scientific-cal 0.2.4

scientific cal
Documentation
use std::{f32::consts::PI, time::Instant};
use scientific_cal::{filters::{filter_factory, BesselCriterion, FilterBand, FilterType}, ScientificError};

#[test]
fn bessel_filter_test() -> Result<(), ScientificError> {
    // 参数输入
    let order = 4;
    let fs: f64 = 20000.0;
    let cutoff = 10.0;

    // 仿真数据
    let dt = 1.0 / fs as f64;
    let mut raw_data: Vec<f64> = (0..fs as i32)
        .map(|i| {
            let t = i as f64 * dt;
            20.0 * ((2.0 * PI as f64 * 2.0 * t).sin()) + 30.0 * ((2.0 * PI as f64 * 20.0 * t).sin()) + 100.0
        })
        .collect();
    // let mut raw_data = vec![0.0; fs as usize];
    
    // 定义低通滤波器
    let mut start = Instant::now();
    
    let ftype = FilterType::Bessel{  
        order: order,
        cutoff: vec![1.0, cutoff],
        band: FilterBand::BandPass,
        analog: false,
        criterion: BesselCriterion::Delay,
        fs: Some(fs),
    };

    let filter = filter_factory::<f64>().create(ftype)?;
    println!("滤波初始化参数耗时: {:?}", start.elapsed());
    start = Instant::now();
    // 开始计算
    println!("滤波前:{:?}", &raw_data[0..10]);
    let _ = filter.apply_inplase(&mut raw_data)?;
    println!("滤波运行耗时: {:?}", start.elapsed());
    println!("滤波后:{:?}", &raw_data[0..10]);
    Ok(())
}