fir
This commit is contained in:
32
src/fir.rs
32
src/fir.rs
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user