use ndarray::Array1;
use num_traits::{Float, FromPrimitive, One, Zero};
use crate::filters::{fir::{correlate1d}, iir::{sos_filt}, FilterApply, FilterError};
pub struct IIRFilter {
pub(crate) sections: Vec<[f64; 6]>
}
impl<T> FilterApply<T> for IIRFilter
where
T: Float + FromPrimitive + Zero + Clone + One,
{
fn apply(&self, data: &Vec<T>) -> Result<Vec<T>, FilterError> {
let mut input: Vec<T> = data.clone();
let _ = sos_filt(&mut input, &self.sections).map_err(|_| FilterError::FilterApplyError);
Ok(input)
}
fn apply_inplase(&self, data: &mut Vec<T>) -> Result<(), FilterError> {
sos_filt(data, &self.sections).map_err(|_| FilterError::FilterApplyError)
}
}
pub struct FIRFilter {
pub(crate) sections: Array1<f64>
}
impl<T> FilterApply<T> for FIRFilter
where
T: Float + FromPrimitive + Zero + Clone + One,
{
fn apply(&self, data: &Vec<T>) -> Result<Vec<T>, FilterError> {
let out = correlate1d(data, &self.sections, -1, "reflect", 0.0, 0).map_err(|_| FilterError::FilterApplyError);
out
}
fn apply_inplase(&self, _data: &mut Vec<T>) -> Result<(), FilterError> {
todo!()
}
}