26 template <
class T,
int WINDOW_LENGTH>
41 _mean = rollingMean.next(x);
42 _variance = (((
long)x - _previous_mean)*((
long)x - _mean))>>WINDOW_LENGTH_AS_RSHIFT;
43 _previous_mean = _mean;
51 _mean = rollingMean.next(x);
52 _variance = (((
int)x - _previous_mean)*((
int)x - _mean))>>WINDOW_LENGTH_AS_RSHIFT;
53 _previous_mean = _mean;
78 return isqrt16(_variance);
84 T _previous_mean, _mean, _variance;
86 const uint8_t WINDOW_LENGTH_AS_RSHIFT;
93 template <
int WINDOW_LENGTH>
99 RollingStat() : _previous_mean(0), _mean(0), _variance(0), WINDOW_LENGTH_AS_RSHIFT(trailingZerosConst(WINDOW_LENGTH))
107 void update(
float x) {
108 _mean = rollingMean.next(x);
109 _variance = ((x - _previous_mean)*(x - _mean))/(WINDOW_LENGTH-1);
110 _previous_mean = _mean;
117 float getMean()
const {
125 float getVariance()
const {
133 float getStandardDeviation()
const {
134 return sqrt(_variance);
140 float _previous_mean, _mean, _variance;
142 const uint8_t WINDOW_LENGTH_AS_RSHIFT;