comparison 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
comparison
equal deleted inserted replaced
138:02044ad2749a 139:e04123ab79ef
1 #include <ansi_c.h>
1 #include "stat.h" 2 #include "stat.h"
2 3
3 void stat_zero(struct stat *s) 4 void stat_zero(struct stat *s)
4 { 5 {
5 s->samples = 0; 6 s->samples = 0;
20 21
21 s->previous = value; 22 s->previous = value;
22 } 23 }
23 24
24 25
25 void rollmean_zero(struct rollmean *s, int wlen) 26 void rollmean_zero(struct rollmean *s)
26 { 27 {
27 s->wlen = wlen;
28 s->nobs = 0; 28 s->nobs = 0;
29 s->mean = 0.0; 29 s->mean = 0.0;
30 s->acc = 0.0; 30 s->acc = 0.0;
31 s->prev = 0.0; 31 memset(s->prev, 0, sizeof(s->prev));
32 } 32 }
33 33
34 34
35 void rollmean_accumulate(struct rollmean *s, double value) 35 void rollmean_accumulate(struct rollmean *s, double value)
36 { 36 {
37 s->acc = s->acc - s->prev + value; 37 s->acc = s->acc + value - s->prev[s->nobs % _ROLLMEAN_WLEN];
38 if (s->nobs < s->wlen) 38 s->prev[s->nobs % _ROLLMEAN_WLEN] = value;
39 s->nobs++; 39 s->nobs++;
40 if (s->nobs < _ROLLMEAN_WLEN)
41 s->mean = s->acc / s->nobs;
40 else 42 else
41 s->prev = s->acc; 43 s->mean = s->acc / _ROLLMEAN_WLEN;
42 s->mean = s->acc / s->nobs;
43 } 44 }