Exponential smoothing filter

Implemented is a simple exponential smoothing filter, which has a infinite impulse response. The implementation is equivalent to the IIR-Filter (see IIR filter). The IIR-Filter calculates the smoothing factor with a cutoff frequency and a RC-element. The exponential smoothing filter uses a fixed smoothing factor, the basic implementation is given by the formula[[1]]:

\[\begin{split}y_0 &= x_0 \\ y[i] &= \alpha \cdot y[i] + (1-\alpha) \cdot y[i-1]\end{split}\]

Example

Listing 101 Example to init and sample the filter
1#include "uz_signals.h"
2int main(void) {
3   float alpha = 0.3f; //smoothing factor defined by user
4   uz_exp_smooth_t* test_instance = uz_exp_smooth_init(alpha);
5   float unfiltered_signal = 20.0f;
6   float filtered_signal = 10.0f;
7   filtered_signal = uz_exp_smooth_sample(test_instance, unfiltered_signal);
8}

Note

The implementation of the filter uses the first value from the unfiltered signal as the first output (first sample).

Reference

typedef struct uz_exp_smooth_t uz_exp_smooth_t
uz_exp_smooth_t *uz_exp_smooth_init(float alpha)

Initialization of the simple exponential smoothing filter.

Parameters:
  • alpha – smoothing factor, 0 ≤ α ≤ 1

Returns:

uz_exp_smooth_t* pointer instance

float uz_exp_smooth_sample(uz_exp_smooth_t *self, float input)

Function to filter an input signal with exponential smoothing filter.

Parameters:
  • self – pointer instance of uz_exp_smooth_t*

  • input – signal, which will be filtered

Returns:

float filtered signal

Sources