RIT VEXU Core API
Loading...
Searching...
No Matches
ExponentialMovingAverage Class Reference

#include <moving_average.h>

Inheritance diagram for ExponentialMovingAverage:
Filter

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 ()
 

Detailed Description

ExponentialMovingAverage

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.

Constructor & Destructor Documentation

◆ ExponentialMovingAverage() [1/2]

ExponentialMovingAverage::ExponentialMovingAverage ( int buffer_size)

Create a moving average calculator with 0 as the default value

Parameters
buffer_sizeThe size of the buffer. The number of samples that constitute a valid reading

◆ ExponentialMovingAverage() [2/2]

ExponentialMovingAverage::ExponentialMovingAverage ( int buffer_size,
double starting_value )

Create a moving average calculator with a specified default value

Parameters
buffer_sizeThe size of the buffer. The number of samples that constitute a valid reading
starting_valueThe value that the average will be before any data is added

Member Function Documentation

◆ add_entry()

void ExponentialMovingAverage::add_entry ( double n)
overridevirtual

Add a reading to the buffer Before: [ 1 1 2 2 3 3] => 2 ^ After: [ 2 1 2 2 3 3] => 2.16 ^

Parameters
nthe sample that will be added to the moving average.

Implements Filter.

◆ get_size()

int ExponentialMovingAverage::get_size ( )

How many samples the average is made from

Returns
the number of samples used to calculate this average

◆ get_value()

double ExponentialMovingAverage::get_value ( ) const
overridevirtual

Returns the average based off of all the samples collected so far

Returns
the calculated average. sum(samples)/numsamples

How many samples the average is made from

Returns
the number of samples used to calculate this average

Implements Filter.


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