Mercurial > hg > fxanalyse
comparison 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 |
comparison
equal
deleted
inserted
replaced
132:fbd72d87b4dc | 133:7540703b8473 |
---|---|
1 #include "stat.h" | |
2 | |
3 void stat_zero(struct stat *s) | |
4 { | |
5 s->samples = 0; | |
6 s->mean = 0.0; | |
7 s->slope = 0.0; | |
8 s->previous = 0.0; | |
9 } | |
10 | |
11 | |
12 void stat_accumulate(struct stat *s, double value) | |
13 { | |
14 s->samples += 1; | |
15 | |
16 if (s->samples > 1) | |
17 s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); | |
18 | |
19 s->mean = ((s->samples - 1) * s->mean + value) / s->samples; | |
20 | |
21 s->previous = value; | |
22 } | |
23 | |
24 | |
25 void rollmean_zero(struct rollmean *s, int wlen) | |
26 { | |
27 s->wlen = wlen; | |
28 s->nobs = 0; | |
29 s->mean = 0.0; | |
30 s->acc = 0.0; | |
31 s->prev = 0.0; | |
32 } | |
33 | |
34 | |
35 void rollmean_accumulate(struct rollmean *s, double value) | |
36 { | |
37 s->acc = s->acc - s->prev + value; | |
38 if (s->nobs < s->wlen) | |
39 s->nobs++; | |
40 else | |
41 s->prev = s->acc; | |
42 s->mean = s->acc / s->nobs; | |
43 } |