25#ifndef MOVINGAVERAGE_H_
26#define MOVINGAVERAGE_H_
64 float alpha(
float sampleRate)
const;
70 virtual float update(
float v,
float sampleRate=1,
bool forceAlpha=
false);
73 float get() {
return _value; }
74 float constGet()
const {
return _value; }
77 unsigned int nSamples()
const {
return _nSamples; }
80 void amendUpdate(
float previousValue,
float newValue,
float sampleRate=1,
bool forceAlpha=
false);
108 unsigned int _nSamples;
An exponential moving average class.
Definition MovingAverage.h:35
float alpha(float sampleRate) const
Returns the alpha value computed from given sample rate.
Definition MovingAverage.cpp:68
MovingAverage()
Default constructor (infinite time window).
Definition MovingAverage.cpp:34
bool timeWindowIsInfinite() const
Returns true if time window is infinite.
Definition MovingAverage.cpp:64
float get()
Returns the value of the moving average. This is undefined if isValid() == false.
Definition MovingAverage.h:73
virtual float update(float v, float sampleRate=1, bool forceAlpha=false)
Updates the moving average with new value #v# (also returns the current value).
Definition MovingAverage.cpp:76
float timeWindow() const
Returns the smoothing window (expressed in seconds).
Definition MovingAverage.h:52
static void applyAmendUpdate(float &runningValue, float previousValue, float newValue, float alpha)
Performs an amendment of latest update (needs to be called with same alpha# parameter).
Definition MovingAverage.cpp:92
static void applyUpdate(float &runningValue, float newValue, float alpha)
Applies a single update on #runningValue# with new sample #newValue# and mixing factor alpha#.
Definition MovingAverage.cpp:96
void amendUpdate(float previousValue, float newValue, float sampleRate=1, bool forceAlpha=false)
Performs an amendment of latest update (needs to be called with same sampleRate# and #forceAlpha# par...
Definition MovingAverage.cpp:88
void reset()
Resets the moving average.
Definition MovingAverage.cpp:72
static float computeUpdate(float runningValue, float newValue, float alpha)
Computes a single update on #runningValue# with new sample #newValue# and mixing factor alpha#.
Definition MovingAverage.cpp:100
unsigned int nSamples() const
Returns the number of samples processed since reset().
Definition MovingAverage.h:77
void infiniteTimeWindow()
Sets to "infinite" smoothing window.
Definition MovingAverage.cpp:44
float cutoff() const
Returns the smoothing window cutoff frequency (expressed in Hz).
Definition MovingAverage.cpp:60