Mercurial > hg > fxanalyse
annotate 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 |
rev | line source |
---|---|
133
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
1 #include "stat.h" |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
2 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
3 void stat_zero(struct stat *s) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
4 { |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
5 s->samples = 0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
6 s->mean = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
7 s->slope = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
8 s->previous = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
9 } |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
10 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
11 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
12 void stat_accumulate(struct stat *s, double value) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
13 { |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
14 s->samples += 1; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
15 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
16 if (s->samples > 1) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
17 s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
18 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
19 s->mean = ((s->samples - 1) * s->mean + value) / s->samples; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
20 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
21 s->previous = value; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
22 } |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
23 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
24 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
25 void rollmean_zero(struct rollmean *s, int wlen) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
26 { |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
27 s->wlen = wlen; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
28 s->nobs = 0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
29 s->mean = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
30 s->acc = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
31 s->prev = 0.0; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
32 } |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
33 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
34 |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
35 void rollmean_accumulate(struct rollmean *s, double value) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
36 { |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
37 s->acc = s->acc - s->prev + value; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
38 if (s->nobs < s->wlen) |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
39 s->nobs++; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
40 else |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
41 s->prev = s->acc; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
42 s->mean = s->acc / s->nobs; |
7540703b8473
Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
43 } |