annotate stat.c @ 261:a03df7dc98f8

Add xsocket wrappers
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 16 Jun 2015 15:09:23 +0200
parents be87c8e78266
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
139
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
1 #include <ansi_c.h>
133
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include "stat.h"
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 void stat_zero(struct stat *s)
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5 {
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 s->samples = 0;
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 s->mean = 0.0;
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 s->slope = 0.0;
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 s->previous = 0.0;
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
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 void stat_accumulate(struct stat *s, double value)
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 {
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 s->samples += 1;
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 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
19 s->previous = value;
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
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22
139
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
23 void rollmean_zero(struct rollmean *s)
133
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 s->nobs = 0;
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 s->mean = 0.0;
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 s->acc = 0.0;
139
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
28 memset(s->prev, 0, sizeof(s->prev));
133
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 }
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 void rollmean_accumulate(struct rollmean *s, double value)
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33 {
139
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
34 s->acc = s->acc + value - s->prev[s->nobs % _ROLLMEAN_WLEN];
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
35 s->prev[s->nobs % _ROLLMEAN_WLEN] = value;
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
36 s->nobs++;
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
37 if (s->nobs < _ROLLMEAN_WLEN)
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
38 s->mean = s->acc / s->nobs;
133
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 else
139
e04123ab79ef Fix recenter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 133
diff changeset
40 s->mean = s->acc / _ROLLMEAN_WLEN;
133
7540703b8473 Major code cleanup. Implement beatnote recentering.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41 }