1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! # Butterworth Filter - Simple filters for noisy data
//! This crate implements digital Butterworth filters for time series data. Filters of arbitrary
//! order can be created and applied to data. Lowpass, highpass, bandpass, and bandstop filters are
//! supported.
//!
//! Transfer function creation is primarily based on `scipy.signal.butter`. The `bidirectional`
//! filter function is designed to match the behavior of MATLAB's `filtfilt` function. If the
//! default signal padding behavior of used by SciPy's `filtfilt` is desired, the
//! `bidirectional_with_padding` function can be used with a padding length of
//! `3 * (filter.order() + 1)`.
//!
//! # Examples
//! ```
//! 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();
//! ```
pub use crate;
pub use crateFilterError;