decimation
This commit is contained in:
32
src/fir.rs
32
src/fir.rs
@ -27,18 +27,27 @@ impl<I, const N: usize> Fir<I, N> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_chunk(&mut self, chunk: &mut IqChunk) {
|
||||
for iq in chunk.samples.iter_mut() {
|
||||
pub fn process_chunk(&mut self, chunk: &IqChunk) -> IqChunk {
|
||||
let mut chunk_out = IqChunk::new();
|
||||
|
||||
for iq in chunk.samples.iter() {
|
||||
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];
|
||||
|
||||
// Decimation
|
||||
if self.decimation_index.is_multiple_of(self.decimation_factor) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
chunk_out.samples.push(y_n);
|
||||
}
|
||||
*iq = y_n
|
||||
|
||||
self.decimation_index += 1;
|
||||
}
|
||||
// TODO: Decimation
|
||||
chunk_out
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,9 +59,10 @@ where
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.inner.next()? {
|
||||
Ok(mut chunk) => {
|
||||
self.process_chunk(&mut chunk);
|
||||
Some(Ok(chunk))
|
||||
Ok(chunk) => {
|
||||
// self.process_chunk(&mut chunk);
|
||||
// Some(Ok(chunk))
|
||||
Some(Ok(self.process_chunk(&chunk)))
|
||||
}
|
||||
Err(e) => Some(Err(e)),
|
||||
}
|
||||
|
||||
@ -11,6 +11,14 @@ pub struct IqChunk {
|
||||
pub samples: Vec<IqSample>,
|
||||
}
|
||||
|
||||
impl IqChunk {
|
||||
pub fn new() -> Self {
|
||||
IqChunk {
|
||||
samples: Vec::<IqSample>::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FileSource {
|
||||
// Buffer
|
||||
pub reader: BufReader<File>,
|
||||
|
||||
@ -12,14 +12,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let source = FileSource::new("test.iq", 32769)?;
|
||||
|
||||
// Fir coefs
|
||||
let taps = [1.0; 64];
|
||||
let taps = [0.5; 64];
|
||||
|
||||
let pipeline = source
|
||||
.agc(20_000_000.0, 1.0, 0.001, 100.0)
|
||||
.fir::<64>(taps, 4);
|
||||
|
||||
for chunk_r in pipeline {
|
||||
let _chunk = chunk_r?;
|
||||
let chunk = chunk_r?;
|
||||
println!("size : {}", chunk.samples.len());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user