2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 struct cc_perioddata *
22 cc_period_make(struct cc_timedata *td, double start_time, double stop_time)
24 int len = stop_time - start_time + 1;
25 struct cc_perioddata *pd;
31 pd = calloc(1, sizeof (struct cc_perioddata));
32 pd->start = start_time;
35 pd->data = calloc(len, sizeof(double));
36 prev_time = start_time;
37 for (i = 0; i < td->num; i++) {
38 if (start_time <= td->data[i].time && td->data[i].time <= stop_time) {
39 int pos = td->data[i].time - start_time;
41 if (i < td->num - 1 && td->data[i+1].time < stop_time)
42 next_time = (td->data[i].time + td->data[i+1].time) / 2.0;
44 next_time = stop_time;
45 interval = next_time - prev_time;
46 pd->data[pos] = td->data[i].value * interval;
47 prev_time = next_time;
53 struct cc_perioddata *
54 cc_period_low_pass(struct cc_perioddata *raw, double omega_pass, double omega_stop, double error)
56 struct cc_perioddata *filtered;
58 filtered = calloc (1, sizeof (struct cc_perioddata));
59 filtered->start = raw->start;
60 filtered->step = raw->step;
61 filtered->num = raw->num;
62 filtered->data = cc_low_pass(raw->data, raw->num, omega_pass, omega_stop, error);