Mercurial > hg > fxanalyse
diff stat.c @ 133:7540703b8473
Major code cleanup. Implement beatnote recentering.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 12:10:17 +0100 |
parents | |
children | e04123ab79ef |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stat.c Wed Jan 22 12:10:17 2014 +0100 @@ -0,0 +1,43 @@ +#include "stat.h" + +void stat_zero(struct stat *s) +{ + s->samples = 0; + s->mean = 0.0; + s->slope = 0.0; + s->previous = 0.0; +} + + +void stat_accumulate(struct stat *s, double value) +{ + s->samples += 1; + + if (s->samples > 1) + s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); + + s->mean = ((s->samples - 1) * s->mean + value) / s->samples; + + s->previous = value; +} + + +void rollmean_zero(struct rollmean *s, int wlen) +{ + s->wlen = wlen; + s->nobs = 0; + s->mean = 0.0; + s->acc = 0.0; + s->prev = 0.0; +} + + +void rollmean_accumulate(struct rollmean *s, double value) +{ + s->acc = s->acc - s->prev + value; + if (s->nobs < s->wlen) + s->nobs++; + else + s->prev = s->acc; + s->mean = s->acc / s->nobs; +}