Control Surface  1.1.1
MIDI Control Surface library for Arduino
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
EMA< K, uint_t > Class Template Reference

A class for single-pole infinite impulse response filters or exponential moving average filters. More...

#include <AH/Filters/EMA.hpp>

Collaboration diagram for EMA< K, uint_t >:

Public Member Functions

uint_t filter (uint_t input)
 Filter the input: Given \( x[n] \), calculate \( y[n] \). More...
 
uint_t operator() (uint_t value)
 Filter the input: Given \( x[n] \), calculate \( y[n] \). More...
 

Private Attributes

uint_t filtered = 0
 

Static Private Attributes

constexpr static uint_t fixedPointAHalf = 1 << (K - 1)
 

Detailed Description

template<uint8_t K, class uint_t>
class EMA< K, uint_t >

A class for single-pole infinite impulse response filters or exponential moving average filters.

Optimized implementation of the difference equation with a slight optimization by using a factor of two as the pole location (this means that no division or floating point operations are required).

Difference equation: \( y[n] = \alpha·x[n]+(1-\alpha)·y[n-1] \) where \( \alpha = \left(\frac{1}{2}\right)^{K} \), \( x \) is the input sequence, and \( y \) is the output sequence.

An in-depth explanation of the EMA filter

Template Parameters
KThe amount of bits to shift by. This determines the location of the pole in the EMA transfer function, and therefore the cut-off frequency.
The higher this number, the more filtering takes place.
The pole location is \( 1 - 2^{-K} \).
uint_tThe (signed) integer type to use for the input, intermediate values and the output. Should be at least \( M+K \) bits wide, where \( M \) is the maximum number of bits of the input. In case of the Arduino's built-in ADC, \( M = 10 = \log_2(1024) \).

Definition at line 42 of file EMA.hpp.

Member Function Documentation

◆ filter()

uint_t filter ( uint_t  input)
inline

Filter the input: Given \( x[n] \), calculate \( y[n] \).

Parameters
inputThe new raw input value.
Returns
The new filtered output value.

Definition at line 51 of file EMA.hpp.

◆ operator()()

uint_t operator() ( uint_t  value)
inline

Filter the input: Given \( x[n] \), calculate \( y[n] \).

Parameters
valueThe new raw input value.
Returns
The new filtered output value.

Definition at line 65 of file EMA.hpp.

Member Data Documentation

◆ filtered

uint_t filtered = 0
private

Definition at line 73 of file EMA.hpp.

◆ fixedPointAHalf

constexpr static uint_t fixedPointAHalf = 1 << (K - 1)
staticconstexprprivate

Definition at line 74 of file EMA.hpp.


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