Calculates a running average over a specified number of the most recent readings. More...
#include <RollingAverage.h>
Public Member Functions | |
RollingAverage () | |
Constructor. More... | |
T | next (T input) |
Give the average of the last WINDOW_LENGTH. More... | |
Protected Member Functions | |
T | add (T input) |
Calculates a running average over a specified number of the most recent readings.
Like Smooth(), this is good for smoothing analog inputs in updateControl().
WINDOW_LENGTH | the number of readings to include in the rolling average. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input. |
Definition at line 37 of file RollingAverage.h.
|
inline |
Constructor.
T | the type of numbers to average, eg. int, unsigned int, float etc. It will be relatively slow with floating point numbers, as it will use a divide operation for the averaging. Nevertheless, there might be a time when it's useful. |
WINDOW_LENGTH | the number of readings to keep track of. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input. |
Definition at line 51 of file RollingAverage.h.
|
inline |
Give the average of the last WINDOW_LENGTH.
input | a control signal such as an analog input which needs smoothing. |
Definition at line 64 of file RollingAverage.h.