diff --git a/src/agc.rs b/src/agc.rs index 55ce4c7..362469f 100644 --- a/src/agc.rs +++ b/src/agc.rs @@ -3,21 +3,21 @@ use num_complex::Complex; use crate::iq_reader::IqChunk; // Automatic Gain Control -struct Agc { +pub struct Agc { // Previous power estimate - power_estimate: f32, + pub power_estimate: f32, // Previous gain - current_gain: f32, - target_power: f32, - alpha_attack: f32, - alpha_release: f32, - beta: f32, - min_gain: f32, - max_gain: f32, + pub current_gain: f32, + pub target_power: f32, + pub alpha_attack: f32, + pub alpha_release: f32, + pub beta: f32, + pub min_gain: f32, + pub max_gain: f32, } impl Agc { - fn new(sample_rate: f32, target_power: f32, min_gain: f32, max_gain: f32) -> Self { + pub fn new(sample_rate: f32, target_power: f32, min_gain: f32, max_gain: f32) -> Self { // Target attack time 5 ms let tau_attack = 0.005; @@ -44,7 +44,7 @@ impl Agc { } } - fn process_chunk(&mut self, chunk: &mut IqChunk) { + pub fn process_chunk(&mut self, chunk: &mut IqChunk) { for z in chunk.samples.iter_mut() { let i = z.re; let q = z.im; diff --git a/src/main.rs b/src/main.rs index bb0654d..5ceb870 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ +use crate::agc::Agc; use crate::iq_reader::FileSource; use std::error::Error; mod agc; mod iq_reader; -mod plot; fn main() -> Result<(), Box> { let source = FileSource::new("test.iq", 32769)?; @@ -12,5 +12,14 @@ fn main() -> Result<(), Box> { // println!("{chunk :?}"); // } + // 20 MSps + let mut agc = Agc::new(20_000_000.0, 0.1, 0.001, 100.0); + + // Apply Auto Gain Control + for chunk_r in source { + let mut chunk = chunk_r?; + agc.process_chunk(&mut chunk); + } + Ok(()) }