RIT VEXU Core API
|
#include <moving_average.h>
Public Member Functions | |
MovingAverage (int buffer_size) | |
MovingAverage (int buffer_size, double starting_value) | |
void | add_entry (double n) override |
double | get_value () const override |
int | get_size () const |
A 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.
The MovingAverage class provides a simple interface to do this smoothing from our noisy sensor values.
WARNING: because we need a lot of samples to get the actual value, the value given by the MovingAverage will 'lag' behind the actual value that the sensor is reading. Using a MovingAverage is thus a tradeoff between accuracy and lag time (more samples) vs. less accuracy and faster updating (less samples).
MovingAverage::MovingAverage | ( | 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 |
MovingAverage::MovingAverage | ( | 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 MovingAverage::get_size | ( | ) | const |
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.