Mercurial > hg > fxanalyse
diff stat.c @ 139:e04123ab79ef
Fix recenter
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:22 +0100 |
parents | 7540703b8473 |
children | be87c8e78266 |
line wrap: on
line diff
--- a/stat.c Wed Jan 22 14:45:07 2014 +0100 +++ b/stat.c Wed Jan 22 14:45:22 2014 +0100 @@ -1,3 +1,4 @@ +#include <ansi_c.h> #include "stat.h" void stat_zero(struct stat *s) @@ -22,22 +23,22 @@ } -void rollmean_zero(struct rollmean *s, int wlen) +void rollmean_zero(struct rollmean *s) { - s->wlen = wlen; s->nobs = 0; s->mean = 0.0; s->acc = 0.0; - s->prev = 0.0; + memset(s->prev, 0, sizeof(s->prev)); } void rollmean_accumulate(struct rollmean *s, double value) { - s->acc = s->acc - s->prev + value; - if (s->nobs < s->wlen) - s->nobs++; + s->acc = s->acc + value - s->prev[s->nobs % _ROLLMEAN_WLEN]; + s->prev[s->nobs % _ROLLMEAN_WLEN] = value; + s->nobs++; + if (s->nobs < _ROLLMEAN_WLEN) + s->mean = s->acc / s->nobs; else - s->prev = s->acc; - s->mean = s->acc / s->nobs; + s->mean = s->acc / _ROLLMEAN_WLEN; }