RIT VEXU Core API
|
#include <moving_average.h>
Public Member Functions | |
ExponentialMovingAverage (int buffer_size) | |
ExponentialMovingAverage (int buffer_size, double starting_value) | |
void | add_entry (double n) override |
double | get_value () const override |
int | get_size () |
An exponential moving average is a way of smoothing out noisy data. For many sensor readings, the noise is roughly symmetric around the actual value. This means that if you collect enough samples those that are too high are cancelled out by the samples that are too low leaving the real value.
A simple mobing average lags significantly with time as it has to counteract old samples. An exponential moving average keeps more up to date by weighting newer readings higher than older readings so it is more up to date while also still smoothed.
The ExponentialMovingAverage class provides an simple interface to do this smoothing from our noisy sensor values.
ExponentialMovingAverage::ExponentialMovingAverage | ( | int | buffer_size | ) |
Create a moving average calculator with 0 as the default value
buffer_size | The size of the buffer. The number of samples that constitute a valid reading |
ExponentialMovingAverage::ExponentialMovingAverage | ( | int | buffer_size, |
double | starting_value ) |
Create a moving average calculator with a specified default value
buffer_size | The size of the buffer. The number of samples that constitute a valid reading |
starting_value | The value that the average will be before any data is added |
|
overridevirtual |
Add a reading to the buffer Before: [ 1 1 2 2 3 3] => 2 ^ After: [ 2 1 2 2 3 3] => 2.16 ^
n | the sample that will be added to the moving average. |
Implements Filter.
int ExponentialMovingAverage::get_size | ( | ) |
How many samples the average is made from
|
overridevirtual |
Returns the average based off of all the samples collected so far
How many samples the average is made from
Implements Filter.