18 #ifndef MATHS_EXPONENTIAL_MOVING_AVERAGE
19 #define MATHS_EXPONENTIAL_MOVING_AVERAGE
43 template<
typename T =
float>
49 std::atomic<T> average;
71 inline void reset(T observation = 0) { average = observation; }
93 average = average + alpha * (observation - average);
106 #endif // MATHS_EXPONENTIAL_MOVING_AVERAGE
T get_alpha() const
Return the parameter.
Definition: exponential_moving_average.hpp:85
void process(T observation)
Calculate the next average based on observation .
Definition: exponential_moving_average.hpp:92
void reset(T observation=0)
Reset the average to initial state with observation .
Definition: exponential_moving_average.hpp:71
ExponentialMovingAverage(T alpha_, T observation=0)
Initialize an exponential moving average with given and .
Definition: exponential_moving_average.hpp:63
void set_alpha(T alpha_)
Set the parameter to a new value.
Definition: exponential_moving_average.hpp:77
A structure for calculating an exponential moving average.
Definition: exponential_moving_average.hpp:44
Functions for doing maths.
Definition: exponential_moving_average.hpp:25
static constexpr T ALPHA_MAX
the maximal value for alpha to take
Definition: exponential_moving_average.hpp:55
T get_average() const
Return the current value of the exponential moving average .
Definition: exponential_moving_average.hpp:101
static constexpr T ALPHA_MIN
the minimal value for alpha to take
Definition: exponential_moving_average.hpp:53