This commit is contained in:
2026-06-11 12:31:56 +02:00
parent e44db49bb4
commit f402885ab8
2 changed files with 21 additions and 12 deletions

View File

@ -3,21 +3,21 @@ use num_complex::Complex;
use crate::iq_reader::IqChunk; use crate::iq_reader::IqChunk;
// Automatic Gain Control // Automatic Gain Control
struct Agc { pub struct Agc {
// Previous power estimate // Previous power estimate
power_estimate: f32, pub power_estimate: f32,
// Previous gain // Previous gain
current_gain: f32, pub current_gain: f32,
target_power: f32, pub target_power: f32,
alpha_attack: f32, pub alpha_attack: f32,
alpha_release: f32, pub alpha_release: f32,
beta: f32, pub beta: f32,
min_gain: f32, pub min_gain: f32,
max_gain: f32, pub max_gain: f32,
} }
impl Agc { 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 // Target attack time 5 ms
let tau_attack = 0.005; 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() { for z in chunk.samples.iter_mut() {
let i = z.re; let i = z.re;
let q = z.im; let q = z.im;

View File

@ -1,9 +1,9 @@
use crate::agc::Agc;
use crate::iq_reader::FileSource; use crate::iq_reader::FileSource;
use std::error::Error; use std::error::Error;
mod agc; mod agc;
mod iq_reader; mod iq_reader;
mod plot;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let source = FileSource::new("test.iq", 32769)?; let source = FileSource::new("test.iq", 32769)?;
@ -12,5 +12,14 @@ fn main() -> Result<(), Box<dyn Error>> {
// println!("{chunk :?}"); // 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(()) Ok(())
} }