Red Bird Racing VCU v2
 
Loading...
Searching...
No Matches
ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO > Class Template Reference

Filter with exponential moving average algorithm. More...

#include <SignalProcessing.hpp>

Inheritance diagram for ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >:
Collaboration diagram for ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >:

Public Member Functions

 ExponentialFilter ()
 Constructor for ExponentialFilter. Initializes the last output value to zero.
 
void addSample (TypeInput sample) override
 Adds a new sample to the ExponentialFilter. Updates the filtered value using the exponential moving average formula.
 
TypeInput getFiltered () const override
 Retrieves the filtered value from the ExponentialFilter.
 
virtual void addSample (TypeInput sample)=0
 
virtual TypeInput getFiltered () const =0
 

Private Attributes

TypeInput last_out = 0
 

Detailed Description

template<typename TypeInput, typename TypeMid, uint8_t OLD_RATIO = 31, uint8_t NEW_RATIO = 1>
class ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >

Filter with exponential moving average algorithm.

Old samples "decay" naturally. The formula used is: f(t) = (f(t-1) * OLD_RATIO + sample * NEW_RATIO + (OLD_RATIO + NEW_RATIO) / 2) / (OLD_RATIO + NEW_RATIO) Due to round down, the results won't ever reach maximum, especially if OLD_RATIO >> NEW_RATIO, so the use of curve is important.

Template Parameters
TypeInputType of the input samples.
TypeMidType used for intermediate calculations.
OLD_RATIOWeighting ratio for the old value.
NEW_RATIOWeighting ratio for the new sample.

Definition at line 59 of file SignalProcessing.hpp.

Constructor & Destructor Documentation

◆ ExponentialFilter()

template<typename TypeInput , typename TypeMid , uint8_t OLD_RATIO, uint8_t NEW_RATIO>
ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >::ExponentialFilter ( )
default

Constructor for ExponentialFilter. Initializes the last output value to zero.

Template Parameters
TypeInputType of the input samples.
TypeMidType used for intermediate calculations.
OLD_RATIOWeighting ratio for the old value.
NEW_RATIOWeighting ratio for the new sample.

Member Function Documentation

◆ addSample()

template<typename TypeInput , typename TypeMid , uint8_t OLD_RATIO, uint8_t NEW_RATIO>
void ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >::addSample ( TypeInput  sample)
overridevirtual

Adds a new sample to the ExponentialFilter. Updates the filtered value using the exponential moving average formula.

Template Parameters
TypeInputType of the input samples.
TypeMidType used for intermediate calculations.
OLD_RATIOWeighting ratio for the old value.
NEW_RATIOWeighting ratio for the new sample.
Parameters
sampleNew input sample to add.

Implements Filter< TypeInput, TypeMid >.

Definition at line 81 of file SignalProcessing.tpp.

Referenced by Pedal::update().

Here is the caller graph for this function:

◆ getFiltered()

template<typename TypeInput , typename TypeMid , uint8_t OLD_RATIO, uint8_t NEW_RATIO>
TypeInput ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >::getFiltered
overridevirtual

Retrieves the filtered value from the ExponentialFilter.

Template Parameters
TypeInputType of the input samples.
TypeMidType used for intermediate calculations.
OLD_RATIOWeighting ratio for the old value.
NEW_RATIOWeighting ratio for the new sample.
Returns
Filtered value.

Implements Filter< TypeInput, TypeMid >.

Definition at line 95 of file SignalProcessing.tpp.

Referenced by Pedal::sendFrame().

Here is the caller graph for this function:

Member Data Documentation

◆ last_out

template<typename TypeInput , typename TypeMid , uint8_t OLD_RATIO = 31, uint8_t NEW_RATIO = 1>
TypeInput ExponentialFilter< TypeInput, TypeMid, OLD_RATIO, NEW_RATIO >::last_out = 0
private

Last output value for exponential filter, input for next calculation

Definition at line 67 of file SignalProcessing.hpp.


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