altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / ao-tools / lib / cc-period.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "cc.h"
20 #include <stdlib.h>
21 #include <math.h>
22
23 struct cc_perioddata *
24 cc_period_make(struct cc_timedata *td, double start_time, double stop_time)
25 {
26         int                     len = stop_time - start_time + 1;
27         struct cc_perioddata    *pd;
28         int                     i, j;
29         double                  t;
30
31         pd = calloc(1, sizeof (struct cc_perioddata));
32         pd->start = start_time;
33         pd->step = 1;
34         pd->num = len;
35         pd->data = calloc(len, sizeof(double));
36         j = 0;
37         for (i = 0; i < pd->num; i++) {
38                 t = start_time + i * pd->step;
39                 while (j < td->num - 1 && fabs(t - td->data[j].time) >= fabs(t - td->data[j+1].time))
40                         j++;
41                 pd->data[i] = td->data[j].value;
42         }
43         return pd;
44 }
45
46 struct cc_perioddata *
47 cc_period_low_pass(struct cc_perioddata *raw, double omega_pass, double omega_stop, double error)
48 {
49         struct cc_perioddata *filtered;
50
51         filtered = calloc (1, sizeof (struct cc_perioddata));
52         filtered->start = raw->start;
53         filtered->step = raw->step;
54         filtered->num = raw->num;
55         filtered->data = cc_low_pass(raw->data, raw->num, omega_pass, omega_stop, error);
56         return filtered;
57 }