modm API documentation

Moving average filter. More...
#include <modm/math/filter/moving_average.hpp>
Public Member Functions  
MovingAverage (const T &initialValue=0)  
void  update (const T &input) 
Append new value.  
const T  getValue () const 
Get filtered value.  
Moving average filter.
Calculates the average of N newest values, i.a. the sum of the last N values have been passed to update(...), divided by N. If less than N values have been passed to the filter, the division factor is still N, so missing values are assumed to be zero.
For integer types this implementation stores the current sum of all values in the buffer and updates this value with every call of update() by subtracting the overwritten buffer index and adding the new one.
Due to numerical instabillity for floating value types, inside the update function the sum has to be recalculated making it less efficient.
The internal sum is always up to date and the getValue() method consists of only one division.
The sum off the last N input values must not be greater than the maximum value of T, otherwise an overflow will occur.
T  Input type 
N  Number of samples (maximum is 65356 or 2**16) 