AMS Advanced Air Mobility Sensors UG
Loading...
Searching...
No Matches
CButterworthLowPassFilter2 Class Reference

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.

Detailed Description

2nd order Butterworth low-pass filter implemented in direct form I.

Constructor & Destructor Documentation

◆ CButterworthLowPassFilter2() [1/2]

CButterworthLowPassFilter2::CButterworthLowPassFilter2 ( )
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() [2/2]

CButterworthLowPassFilter2::CButterworthLowPassFilter2 ( float fCutoffFrequencyHz,
float fSamplingFrequencyHz )

Construct and configure the filter.

Function design

Normal case

The function SHALL compute the normalized IIR coefficients for a 2nd order Butterworth low-pass filter. For the formulae see the helper function documentation.

Argument checks

  1. The function SHALL assert that the provided cutoff frequency is finite and positive.
  2. The function SHALL assert that the provided sampling frequency is finite and positive.
  3. The function SHALL assert that the provided cutoff frequency is less than half the sampling frequency (Nyquist frequency).
Parameters
fCutoffFrequencyHzCutoff frequency in [Hz]
fSamplingFrequencyHzSampling frequency in [Hz]

Member Function Documentation

◆ Add()

void CButterworthLowPassFilter2::Add ( float fNewValue)

Feed one new sample into the filter.

Parameters
fNewValueNew input sample.

Function design

Case 1: Filter is not initialized

  1. IF the filter is not initialized, THEN the function SHALL initialize the filter.
  2. After initialization, the function SHALL update the pre-computed filtered output.
  3. After updating the pre-computed filtered output, the function SHALL update the filter's state.

For the filter initialization procedure see the helper function documentation.

Case 2: Filter is initialized

  1. WHEN the filter is initialized, THEN the function SHALL update the pre-computed filtered output.
  2. After updating the pre-computed filtered output, the function SHALL update the filter's state.

Computation of the filtered output

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.

◆ computeCoefficients()

SCoefficients CButterworthLowPassFilter2::computeCoefficients ( float fCutoffFrequencyHz,
float fSamplingFrequencyHz )
staticprivate

Compute normalized IIR coefficients for the configured Butterworth filter.

Function design

Normal case

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\).

Argument checks

  1. The function SHALL NOT perform argument checks.
Parameters
fCutoffFrequencyHzCutoff frequency in [Hz]
fSamplingFrequencyHzSampling frequency in [Hz]
Returns
Coefficients of the direct-form-I recurrence.

◆ Configure()

void CButterworthLowPassFilter2::Configure ( float fCutoffFrequencyHz,
float fSamplingFrequencyHz )

Reconfigure the filter coefficients.

Function design

Normal case

The function SHALL compute the normalized IIR coefficients for a 2nd order Butterworth low-pass filter. For the formulae see the helper function documentation.

Argument checks

  1. The function SHALL assert that the provided cutoff frequency is finite and positive.
  2. The function SHALL assert that the provided sampling frequency is finite and positive.
  3. The function SHALL assert that the provided cutoff frequency is less than half the sampling frequency (Nyquist frequency).
Parameters
fCutoffFrequencyHzCutoff frequency in [Hz]
fSamplingFrequencyHzSampling frequency in [Hz]

◆ Get()

float CButterworthLowPassFilter2::Get ( ) const

Get the latest filtered value.

Returns
Latest filter output. Returns 0.0F while the filter is uninitialized, for example right after default construction or Reset().

◆ initializeStateWithoutTransient()

SFilterState CButterworthLowPassFilter2::initializeStateWithoutTransient ( float fInputValue,
const SCoefficients & korCoefficients )
staticprivate

Initialize the direct-form-I state to the steady state for a constant input.

Function design

  1. The function SHALL set the states SFilterState::fInput1_ and SFilterState::fInput2_ to the provided input value.
  2. The function SHALL set the states SFilterState::fOutput1_ and SFilterState::fOutput2_ to the corresponding steady-state output value.

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.

Parameters
fInputValueConstant input value to initialize the filter from.
korCoefficientsFilter coefficients.

◆ Reset()

void CButterworthLowPassFilter2::Reset ( )

Reset the filter state.

Function design

  1. The function SHALL transition the filter to an uninitialized state.
  2. The function SHALL NOT modify the filter coefficients.
  3. The function SHALL set the pre-computed filter output to zero.

Member Data Documentation

◆ bIsInitialized_

bool CButterworthLowPassFilter2::bIsInitialized_ { false }
private

True once the internal state has been initialized from an input sample.

◆ fFilteredSignal_

float CButterworthLowPassFilter2::fFilteredSignal_ { 0.0F }
private

Latest filter output.

◆ oCoefficients_

SCoefficients CButterworthLowPassFilter2::oCoefficients_ {}
private

Filter coefficients.

◆ oState_

SFilterState CButterworthLowPassFilter2::oState_ {}
private

State of the direct-form-I recurrence.


The documentation for this class was generated from the following file: