TransferFunction implemented for series biquad

This commit is contained in:
Anne de Jong 2024-07-03 22:06:33 +02:00
parent 7e9cf734d0
commit 81872c62e1

View File

@ -1,20 +1,17 @@
use super::*;
use super::biquad::Biquad;
use anyhow::{bail, Result};
#[derive(Clone, Debug)]
#[cfg_attr(feature = "python-bindings", pyclass)]
/// Series of biquads that filter sequentially on an input signal
///
/// # Examples
///
/// See (tests)
///
///
pub struct SeriesBiquad {
biqs: Vec<Biquad>,
}
@ -109,7 +106,16 @@ impl Filter for SeriesBiquad {
Box::new(self.clone())
}
}
impl<'a, T: AsArray<'a, Flt>> TransferFunction<'a, T> for SeriesBiquad {
fn tf(&self, fs: Flt, freq: T) -> Ccol {
let freq = freq.into();
let mut res = self.biqs.first().unwrap().tf(fs, freq);
for i in self.biqs.iter().skip(1) {
res = &res * i.tf(fs, freq);
}
res
}
}
#[cfg(test)]
mod test {
@ -138,4 +144,4 @@ mod test {
inp[1] = 0.5;
assert_eq!(&inp, &filtered);
}
}
}