Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::control::input::Ewma Class Reference

Integer EWMA filter, alpha = 1 / 2^shift. More...

Detailed Description

Integer EWMA filter, alpha = 1 / 2^shift.

Context
update() may run in an ISR while value() is read from the main loop, or the reverse, provided only one context calls update() on an instance: the 32-bit aligned state is read and written in one access on Cortex-M.

Definition at line 38 of file ewma.hpp.

#include <ewma.hpp>

Public Member Functions

 Ewma (uint8_t shift=3)
 Construct EWMA filter.
 
uint16_t update (uint16_t raw)
 Feed a new sample and return the smoothed value.
 
uint16_t value () const
 Return current smoothed value without updating.
 
void set_shift (uint8_t shift)
 Change smoothing exponent without resetting filter state.
 
void reset ()
 Reset filter state (next update will re-seed)
 

Constructor & Destructor Documentation

◆ Ewma()

sbl::control::input::Ewma::Ewma ( uint8_t  shift = 3)
inlineexplicit

Construct EWMA filter.

Parameters
shiftSmoothing exponent (alpha = 1/2^shift), 0 to 15; 0 passes the input through unfiltered.

Definition at line 45 of file ewma.hpp.

Member Function Documentation

◆ update()

uint16_t sbl::control::input::Ewma::update ( uint16_t  raw)
inline

Feed a new sample and return the smoothed value.

First call seeds the filter (no smoothing on first sample). Internal state uses Q16 fixed-point for sub-LSB precision.

Parameters
rawRaw input value (16-bit)
Returns
Smoothed output (16-bit)

Definition at line 56 of file ewma.hpp.

Referenced by sbl::control::input::CvInput::update(), and sbl::control::input::Pot::update().

◆ value()

uint16_t sbl::control::input::Ewma::value ( ) const
inline

Return current smoothed value without updating.

Definition at line 73 of file ewma.hpp.

Referenced by sbl::control::input::Pot::smoothed(), and sbl::control::input::CvInput::value().

◆ set_shift()

void sbl::control::input::Ewma::set_shift ( uint8_t  shift)
inline

Change smoothing exponent without resetting filter state.

Definition at line 76 of file ewma.hpp.

Referenced by sbl::control::input::CvInput::set_smoothing().

◆ reset()

void sbl::control::input::Ewma::reset ( )
inline

Reset filter state (next update will re-seed)

Definition at line 79 of file ewma.hpp.

Referenced by sbl::control::input::CvInput::reset(), and sbl::control::input::Pot::reset().


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