Class Butterworth¶
Defined in File butterworth.hpp
Class Documentation¶
-
class Butterworth¶
Implementation of Butterworth filter design in the discrete domain.
This header file provides a comprehensive implementation of Butterworth filters, including low-pass, high-pass, band-pass, and band-stop filters. The Butterworth filter is known for its maximally flat frequency response in the passband, making it ideal for applications requiring minimal signal distortion.
The implementation includes:
Conversion of poles and zeros from the Laplace domain to the Z domain using the bilinear transform.
Expansion of polynomial coefficients from a set of poles or zeros.
Evaluation of the frequency response of the filter at a given frequency.
A templated Butterworth filter class for designing filters of arbitrary order and type.
The design process includes pre-warping of frequencies for the bilinear transform, generation of prototype poles, and scaling of coefficients.
The following transforms map a lowpass prototype into other filter types (s-domain):
Lowpass to Lowpass: \( s \rightarrow \frac{s}{\Omega_c} \)
Lowpass to Highpass: \( s \rightarrow \frac{\Omega_c}{s} \)
Lowpass to Bandpass: \( s \rightarrow \frac{s^2 + \Omega_0^2}{B s} \)
Lowpass to Bandstop: \( s \rightarrow \frac{B s}{s^2 + \Omega_0^2} \)
Where: \( \Omega_0 = \sqrt{\Omega_l \cdot \Omega_h}, \quad B = \Omega_h - \Omega_l \)
After analog transformation, apply the bilinear transform:
\[ s = \frac{2}{T} \cdot \frac{z - 1}{z + 1} \]If results are suspicious, verify filter coefficients using external tools such as MATLAB or Python (e.g., SciPy).
Usage¶
To use this implementation, include this header file and instantiate the
Butterworthclass with the desired filter order, type, and parameters. Then, pass those coefficients into aDiscreteFilter.static constexpr Butterworth<1, LOWPASS> filter(wc, Ts); auto naturalCoeffs = filter.getNaturalResponseCoefficients(); auto forcedCoeffs = filter.getForcedResponseCoefficients(); DiscreteFilter<2> Filter(naturalCoeffs, forcedCoeffs);
- Author
Aiden Prevey
- Date
4/29/2025
- Version
2.0
Note
This implementation is designed for C++20
constexpr, enabling compile-time computation of filter configurations.Warning
High-order filters can introduce high phase delays and should be used with caution. For most applications, low-pass and high-pass filters of order 2 or lower are sufficient.