2 个不稳定版本
0.1.0 | 2024年5月22日 |
---|---|
0.0.1 | 2024年1月29日 |
在 机器人 中排名 #198
28KB
438 行
butterworth - 噪声数据的简单滤波器
此工具包实现了时间序列数据的数字巴特沃斯滤波器。可以创建任意阶数的滤波器并应用于数据。支持低通、高通、带通和带阻滤波器。
传递函数的创建主要基于 scipy.signal.butter
。双向滤波器函数被设计为与 MATLAB 的 filtfilt
函数的行为相匹配。如果希望使用 SciPy 的 filtfilt
默认信号填充行为,则可以使用 bidirectional_with_padding
函数,填充长度为 3 * (filter.order() + 1)
。
lib.rs
:
巴特沃斯滤波器 - 噪声数据的简单滤波器
此工具包实现了时间序列数据的数字巴特沃斯滤波器。可以创建任意阶数的滤波器并应用于数据。支持低通、高通、带通和带阻滤波器。
传递函数的创建主要基于 scipy.signal.butter
。双向滤波器函数被设计为与 MATLAB 的 filtfilt
函数的行为相匹配。如果希望使用 SciPy 的 filtfilt
默认信号填充行为,则可以使用 bidirectional_with_padding
函数,填充长度为 3 * (filter.order() + 1)
。
示例
use butterworth::{Filter, Cutoff};
// Create a mix of low and high frequency sine functions
let data = (0..=100).map(|x| x as f64).map(|x| (x * 0.1).sin() + (x * 0.75).sin()).collect();
// Assuming the sample rate is 100 Hz, design a 4th order lowpass filter with an 8 Hz cutoff
let filter = Filter::new(4, 100., Cutoff::LowPass(8.)).unwrap();
// Apply a bidirectional filter to the data
let filtered_data = filter.bidirectional(&data).unwrap();
// Create expected lower frequency component output
let expected = (0..=100).map(|x| x as f64).map(|x| (x * 0.1).sin()).collect::<Vec<f64>>();
// The filtered data should roughly match the lower frequency component, particularly in middle
for i in 8..filtered_data.len() - 8 {
assert!((filtered_data[i] - expected[i]).abs() < 5e-2);
}
// Manually specify a padding length if the default behavior of SciPy is desired
let filtered_data = filter.bidirectional_with_padding(&data, 3 * (filter.order() + 1)).unwrap();
依赖项
~270KB