libpower/filter/mod.rs
1//! # Digital Signal Processing Filters
2//!
3//! This module provides a collection of high-performance digital filters commonly used
4//! in power electronics and embedded control systems. All filters are implemented as
5//! second-order sections (SOS) for numerical stability and modularity.
6//!
7//! ## Available Filter Types
8//!
9//! ### Butterworth Filters
10//! - [`butterworth_lpf`] - Butterworth low-pass filter (maximally flat passband)
11//! - [`butterworth_hpf`] - Butterworth high-pass filter (maximally flat passband)
12//!
13//! ### Chebyshev Type I Filters
14//! - [`chebyshev_lpf`] - Chebyshev low-pass filter (equiripple passband)
15//! - [`chebyshev_hpf`] - Chebyshev high-pass filter (equiripple passband)
16//!
17//! ## Filter Characteristics
18//!
19//! ### Butterworth Filters
20//! - **Advantages**: Maximally flat passband, no ripple, good phase response
21//! - **Applications**: Anti-aliasing, general-purpose filtering, measurement systems
22//! - **Roll-off**: 20n dB/decade (where n is the filter order)
23//!
24//! ### Chebyshev Type I Filters
25//! - **Advantages**: Steeper roll-off than Butterworth, compact implementation
26//! - **Disadvantages**: Passband ripple, more phase distortion
27//! - **Applications**: Anti-aliasing with tight transition bands, EMI filtering
28//! - **Roll-off**: Steeper than Butterworth for same order
29//!
30//! ## Implementation Details
31//!
32//! ### Second-Order Sections (SOS)
33//! All filters are implemented using cascaded second-order sections:
34//! - **Numerical Stability**: Reduced coefficient sensitivity
35//! - **Modularity**: Easy to implement different orders
36//! - **Efficiency**: Optimized for real-time applications
37//!
38//! ### Supported Orders
39//! - **Range**: 2nd to 8th order (even orders only)
40//! - **Automatic Adjustment**: Invalid orders are bounded and rounded
41//! - **Sections**: Each filter uses order/2 second-order sections
42//!
43//! ## Usage Guidelines
44//!
45//! ### Sampling Frequency Considerations
46//! - Ensure fs > 2 * fc (Nyquist criterion)
47//! - Typical ratio: fs/fc > 10 for good performance
48//! - Account for transition band requirements
49//!
50//! ### Filter Selection
51//! - **Butterworth**: Choose for phase-critical applications
52//! - **Chebyshev**: Choose when sharp cutoff is required
53//! - **Order Selection**: Higher order = sharper cutoff, more delay
54//!
55//! ## Example Usage
56//!
57//! ```rust
58//! use libpower::filter::butterworth_lpf::ButterworthLPF;
59//!
60//! // Create and initialize a 4th-order Butterworth low-pass filter
61//! let mut filter = ButterworthLPF::<4>::new_uninit();
62//! filter.init(4, 1000.0, 44100.0); // 4th order, 1kHz cutoff, 44.1kHz sampling
63//!
64//! // Process signal samples
65//! let input_signal = [1.0, 0.5, -0.5, -1.0, 0.0];
66//! let mut filtered_signal = Vec::new();
67//! for sample in input_signal.iter() {
68//! let filtered = filter.process(*sample);
69//! filtered_signal.push(filtered);
70//! }
71//! ```
72
73pub mod butterworth_hpf;
74pub mod butterworth_lpf;
75pub mod chebyshev_hpf;
76pub mod chebyshev_lpf;