Lowpass Filter

The LowpassFilter class provides an implementation of a digial lowpass infinite impulse response (IIR) filter, which leverages the hardware acceleration provided by esp-dsp and which leverages the vector instructions on the espressif processors.

API Reference

Header File

Classes

class LowpassFilter

Lowpass infinite impulse response (IIR) filter.

Public Functions

LowpassFilter() = default

Default constructor.

explicit LowpassFilter(const Config &config)

Initialize the lowpass filter coefficients based on the config.

Parameters

config – Configuration struct.

void configure(const Config &config)

Set the filter coefficients based on the config.

Parameters

config – Configuration struct.

void update(const float *input, float *output, size_t length)

Filter the input samples, updating internal state, and writing the filtered values to the data pointed to by output.

Note

On ESP32, the input and output arrays must have attribute((aligned(16))) to ensure proper alignment for the ESP32 DSP functions.

Parameters
  • input – Pointer to (floating point) array of new samples of the input data

  • output – Pointer to (floating point) array which will be filled with the filtered input.

  • length – Number of samples, should be >= length of input & output memory.

float update(const float input)

Filter the signal sampled by input, updating internal state, and returning the filtered output.

Parameters

input – New sample of the input data.

Returns

Filtered output based on input and history.

float operator()(float input)

Filter the signal sampled by input, updating internal state, and returning the filtered output.

Parameters

input – New sample of the input data.

Returns

Filtered output based on input and history.

void reset()

Reset the filter state to zero.

struct Config

Configuration for the lowpass filter.

Public Members

float normalized_cutoff_frequency

Filter cutoff frequency in the range 0.0, 0.5.

float q_factor

Quality (Q) factor of the filter. The higher the Q the better the filter.