![]() |
AMS Advanced Air Mobility Sensors UG
|
2nd order Butterworth low-pass filter implemented in direct form I. More...
Classes | |
| struct | SCoefficients |
| struct | SFilterState |
Public Member Functions | |
| CButterworthLowPassFilter2 ()=default | |
| Construct a pass-through placeholder filter. | |
| CButterworthLowPassFilter2 (float fCutoffFrequencyHz, float fSamplingFrequencyHz) | |
| Construct and configure the filter. | |
| float | Get () const |
| Get the latest filtered value. | |
| void | Add (float fNewValue) |
| Feed one new sample into the filter. | |
| void | Reset () |
| Reset the filter state. | |
| void | Configure (float fCutoffFrequencyHz, float fSamplingFrequencyHz) |
| Reconfigure the filter coefficients. | |
Static Private Member Functions | |
| static SCoefficients | computeCoefficients (float fCutoffFrequencyHz, float fSamplingFrequencyHz) |
| Compute normalized IIR coefficients for the configured Butterworth filter. | |
| static SFilterState | initializeStateWithoutTransient (float fInputValue, const SCoefficients &korCoefficients) |
| Initialize the direct-form-I state to the steady state for a constant input. | |
Private Attributes | |
| SCoefficients | oCoefficients_ {} |
| Filter coefficients. | |
| SFilterState | oState_ {} |
| State of the direct-form-I recurrence. | |
| float | fFilteredSignal_ { 0.0F } |
| Latest filter output. | |
| bool | bIsInitialized_ { false } |
| True once the internal state has been initialized from an input sample. | |
2nd order Butterworth low-pass filter implemented in direct form I.
|
default |
Construct a pass-through placeholder filter.
The default-constructed filter uses unity gain with no filtering until Configure() is called or the configured constructor is used.
| CButterworthLowPassFilter2::CButterworthLowPassFilter2 | ( | float | fCutoffFrequencyHz, |
| float | fSamplingFrequencyHz ) |
Construct and configure the filter.
The function SHALL compute the normalized IIR coefficients for a 2nd order Butterworth low-pass filter. For the formulae see the helper function documentation.
| fCutoffFrequencyHz | Cutoff frequency in [Hz] |
| fSamplingFrequencyHz | Sampling frequency in [Hz] |
| void CButterworthLowPassFilter2::Add | ( | float | fNewValue | ) |
Feed one new sample into the filter.
| fNewValue | New input sample. |
For the filter initialization procedure see the helper function documentation.
The latest filtered output is given by the direct-form-I recurrence
\[y[k] = b_0 x[k] + b_1 x[k - 1] + b_2 x[k - 2] - a_1 y[k - 1] - a_2 y[k - 2] \]
where \( x[k] = \) fNewValue, and the coefficients are given by the current filter configuration.
|
staticprivate |
Compute normalized IIR coefficients for the configured Butterworth filter.
The function SHALL compute coefficients for the direct-form-I recurrence
\[y[k] = b_0 x[k] + b_1 x[k - 1] + b_2 x[k - 2] - a_1 y[k - 1] - a_2 y[k - 2] \]
where \( f_c = \) fCutoffFrequencyHz, \( f_s = \) fSamplingFrequencyHz.
The function SHALL return the normalized Butterworth coefficients
\[b_0 = \Omega^2 / c, \; b_1 = 2 b_0, \; b_2 = b_0, \]
\[a_1 = 2 (\Omega^2 - 1) / c, \; a_2 = (1 - \sqrt{2} \Omega + \Omega^2) / c. \]
Herein \(\Omega = \tan\left(\frac{\pi f_c}{f_s}\right)\), and \(c = 1 + \sqrt{2} \Omega + \Omega^2\).
| fCutoffFrequencyHz | Cutoff frequency in [Hz] |
| fSamplingFrequencyHz | Sampling frequency in [Hz] |
| void CButterworthLowPassFilter2::Configure | ( | float | fCutoffFrequencyHz, |
| float | fSamplingFrequencyHz ) |
Reconfigure the filter coefficients.
The function SHALL compute the normalized IIR coefficients for a 2nd order Butterworth low-pass filter. For the formulae see the helper function documentation.
| fCutoffFrequencyHz | Cutoff frequency in [Hz] |
| fSamplingFrequencyHz | Sampling frequency in [Hz] |
| float CButterworthLowPassFilter2::Get | ( | ) | const |
Get the latest filtered value.
|
staticprivate |
Initialize the direct-form-I state to the steady state for a constant input.
The steady-state output value is given by
\[y_\infty = \frac{b_0 + b_1 + b_2}{1 + a_1 + a_2} x_\infty \]
where \( x_\infty = \) fInputValue.
| fInputValue | Constant input value to initialize the filter from. |
| korCoefficients | Filter coefficients. |
| void CButterworthLowPassFilter2::Reset | ( | ) |
|
private |
True once the internal state has been initialized from an input sample.
|
private |
Latest filter output.
|
private |
Filter coefficients.
|
private |
State of the direct-form-I recurrence.