This commit is contained in:
2026-06-12 09:37:21 +02:00
parent b947256af6
commit d3375c0e22
3 changed files with 34 additions and 15 deletions

View File

@ -1,27 +1,41 @@
// Finite Impulse response + Decimation
use crate::utils::ring_buffer::RingBuffer;
use num_complex::Complex32;
use crate::{iq_reader::IqChunk, iq_reader::IqSample, utils::ring_buffer::RingBuffer};
pub struct Fir<const N: usize> {
// Filter coefs
pub taps: [f32; N],
// Ring Buffer of samples
pub history: RingBuffer<Complex32>,
pub history: RingBuffer<IqSample>,
decimation_factor: usize,
// Factor of decimation
pub decimation_factor: usize,
// When to keep a sample
decimator_counter: usize,
// Track decimation
pub decimation_index: usize,
}
impl<const N: usize> Fir<N> {
fn new(taps: [f32; N], decimation_factor: usize) -> Self {
pub fn new(taps: [f32; N], decimation_factor: usize) -> Self {
Self {
taps,
history: RingBuffer::new(N),
history: RingBuffer::<IqSample>::new(N),
decimation_factor,
decimator_counter: 0,
decimation_index: 0,
}
}
pub fn process_chunk(&mut self, chunk: &mut IqChunk) {
for iq in chunk.samples.iter_mut() {
self.history.push(*iq);
let mut y_n = IqSample::default();
for k in 0..N {
if let Some(sample) = self.history.read_at(k) {
y_n += *sample * self.taps[k];
}
}
*iq = y_n
}
// TODO: Decimation
}
}