use std::f64::consts::PI;

use ndarray::{s, Array1};

use crate::filters::{fir::{gauss::gauss1d::gaussian_kernel1d, FIRFilterDesign}, impls::FIRFilter};

pub struct Gauss1dFilter {
    fs: f64,
    cutoff: f64,
    truncate: f64, 
    radius: Option<usize>
}
impl Gauss1dFilter {
    pub fn new(
        fs: f64,
        cutoff: f64,
        truncate: f64, 
        radius: Option<usize>   
    ) -> Self
    {
        Self { fs, cutoff, truncate, radius}
    }
}
/// 高斯滤波器
///
/// # 参数
///
/// - `fs`：采样频率
/// - `cutoff`: 截止频率
/// - `truncate`：
/// - `radius`：
///
///
/// # 返回值
///
/// 滤波器设计参数 Vec<[f64; 6]。
///
/// # 示例
///
/// ```
/// 无
/// ```
/// 
impl<'a> FIRFilterDesign for Gauss1dFilter{
    fn design(&self) -> FIRFilter
    {
        let sd = 1.0 / (2.0 * PI * self.cutoff) * self.fs;
        let mut lw = (self.truncate * sd + 0.5).floor() as usize;
        if let Some(r) = self.radius {
            lw = r;
        }
        if let Ok(result) = gaussian_kernel1d(sd, 0, lw){
            return FIRFilter{
                sections: result.slice(s![..;-1]).to_owned()
            };
        }else{
            return FIRFilter{
                sections: Array1::from(Vec::<f64>::new())
            };
        };
    }
}