1 #ifndef __MovingAverage_h__
2 #define __MovingAverage_h__
15 void set(
float value){
36 lambda = smoothing / (observations + 1);
53 lambda = cfc - 1 + sqrtf(cfc*cfc - 4*cfc + 3);
60 y = y*lambda + x*(1.0f - lambda);
71 for(
size_t i=0; i<input.
getSize(); i++)
89 size_t writeIndex = 0;
98 void set(
float value){
100 sum = value * buffer.
getSize();
103 sum = sum - buffer[writeIndex] + value;
104 buffer[writeIndex] = value;
107 if(++writeIndex == buffer.
getSize())
124 for(
size_t i=0; i<input.
getSize(); i++)
Exponential Moving Average EMA.
void setSmoothing(size_t observations, float smoothing=2)
Set lambda (time coefficient) as amount of smoothing over number of observations.
void setModifiedMovingAverage(size_t N)
Set lambda (time coefficient) as 1/N.
float getNextAverage(float x)
RMS detection with smoothing coefficient (Moving RMS) as per: R.
static ExponentialMovingAverage * create(float lambda)
void setLambda(float value)
Set the exponential decay time coefficient.
ExponentialMovingAverage(float lambda=0.995, float y=0)
static void destroy(ExponentialMovingAverage *obj)
void setCutoff(float fc)
Set lambda (time coefficient) as the -3dB cutoff frequency, in radians.
void process(FloatArray input)
This class contains useful methods for manipulating arrays of floats.
void clear()
Clear the array.
static void destroy(FloatArray array)
Destroys a FloatArray created with the create() method.
static FloatArray create(int size)
Creates a new FloatArray.
void setAll(float value)
Set all the values in the array.
Base class for signal processors such as Filters.
virtual float process(float input)
Simple Moving Average SMA.
float getNextSum(float value)
static void destroy(SimpleMovingAverage *buf)
float getNextAverage(float push)
SimpleMovingAverage(FloatArray buf)
static SimpleMovingAverage * create(int samples)
void process(FloatArray input)