Mozzi  version v1.1.0
sound synthesis library for Arduino
RollingStat< T, WINDOW_LENGTH > Class Template Reference

WARNING: this class is work in progress, don't use it yet. More...

#include <RollingStat.h>

Public Member Functions

 RollingStat ()
 Constructor.
 
void update (T x)
 Update the mean and variance given a new input value. More...
 
void update (int8_t x)
 Update the mean and variance given a new input value. More...
 
getMean () const
 Return the mean of the last WINDOW_LENGTH number of inputs. More...
 
getVariance () const
 Return the approximate variance of the last WINDOW_LENGTH number of inputs. More...
 
getStandardDeviation () const
 Return the approximate standard deviation of the last WINDOW_LENGTH number of inputs. More...
 

Detailed Description

template<class T, int WINDOW_LENGTH>
class RollingStat< T, WINDOW_LENGTH >

WARNING: this class is work in progress, don't use it yet.

Calculates an approximation of the variance and standard deviation for a window of recent inputs.

Template Parameters
Tthe type of numbers to use. Choose unsigned int, int , uint8_t, int8_t, or float
WINDOW_LENGTHhow many recent input values to include in the calculations.

Definition at line 28 of file RollingStat.h.

Member Function Documentation

◆ getMean()

template<class T , int WINDOW_LENGTH>
T RollingStat< T, WINDOW_LENGTH >::getMean ( ) const
inline

Return the mean of the last WINDOW_LENGTH number of inputs.

Returns
mean

Definition at line 61 of file RollingStat.h.

◆ getStandardDeviation()

template<class T , int WINDOW_LENGTH>
T RollingStat< T, WINDOW_LENGTH >::getStandardDeviation ( ) const
inline

Return the approximate standard deviation of the last WINDOW_LENGTH number of inputs.

Returns
standard deviation.

Definition at line 78 of file RollingStat.h.

◆ getVariance()

template<class T , int WINDOW_LENGTH>
T RollingStat< T, WINDOW_LENGTH >::getVariance ( ) const
inline

Return the approximate variance of the last WINDOW_LENGTH number of inputs.

Returns
variance
Note
This should really be calculated using WINDOW_LENGTH-1, but sacrificing accuracy for speed we use the power of two value of WINDOW_LENGTH.

Definition at line 71 of file RollingStat.h.

◆ update() [1/2]

template<class T , int WINDOW_LENGTH>
void RollingStat< T, WINDOW_LENGTH >::update ( x)
inline

Update the mean and variance given a new input value.

Parameters
xthe next input value
Note
timing for unsigned int 10us, int 22us

Definition at line 41 of file RollingStat.h.

◆ update() [2/2]

template<class T , int WINDOW_LENGTH>
void RollingStat< T, WINDOW_LENGTH >::update ( int8_t  x)
inline

Update the mean and variance given a new input value.

Parameters
xthe next input value

Definition at line 51 of file RollingStat.h.