@Anony-Mousse's post gave some terms to google, which led to this dsp.SX questionthis dsp.SX question. There are two approaches, one of which is the Knuth from the other answer. The otherThe other
weighs more recent samples stronger than samples from the distant past.
The update algorithm (slightly edited) is given as
% update the estimate of the mean and the mean square: mean = (1-a)*mean + a*x meansq = (1-b)*meansq + b*(x^2) % calculate the estimate of the variance: var = meansq - mean^2; % and, if you want standard deviation: std = sqrt(var);
The choice of a
and b
determines how strongly to weigh the newer values. The dsp.sx questionThe dsp.sx question has answers which partly contain how to determine it.