Mozzi  version 2015-05-11-20:23
sound synthesis library for Arduino
 All Classes Functions Typedefs Groups
RollingStat< T, WINDOW_LENGTH > Class Template Reference

Calculates an approximation of the variance and standard deviation for a window of recent inputs. 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 >

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 25 of file RollingStat.h.

Member Function Documentation

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 58 of file RollingStat.h.

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 75 of file RollingStat.h.

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 68 of file RollingStat.h.

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 38 of file RollingStat.h.

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 48 of file RollingStat.h.