diff options
| author | Keith Packard <keithp@keithp.com> | 2009-09-06 12:51:48 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2009-09-06 12:51:48 -0700 | 
| commit | 7a19aac5e881e635962a64fff73027ca2143b96f (patch) | |
| tree | bb2fec6660529832e9c2defd67c5ed7ef07bbeea /ao-tools/lib/cc-analyse.c | |
| parent | 6d018ab933832e2d80bb1564c339d9fb18b57be2 (diff) | |
Add DSP code to filter data, allowing for integration/differentiation
This adds the computation of speed from both accelerometer and
barometer measurements and then presents a periodic flight profile
using filtered data as a detailed flight record.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/lib/cc-analyse.c')
| -rw-r--r-- | ao-tools/lib/cc-analyse.c | 57 | 
1 files changed, 57 insertions, 0 deletions
diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index fc8a8417..0e020115 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -16,6 +16,7 @@   */  #include "cc.h" +#include <math.h>  int  cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) @@ -56,3 +57,59 @@ cc_timedata_max(struct cc_timedata *d, double min_time, double max_time)  			}  	return max_i;  } + +int +cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time) +{ +	int	start, stop; +	int	i; +	double	min; +	int	min_i; + +	if (d->num == 0) +		return -1; +	start = (int) ceil((min_time - d->start) / d->step); +	if (start < 0) +		start = 0; +	stop = (int) floor((max_time - d->start) / d->step); +	if (stop >= d->num) +		stop = d->num - 1; +	if (stop < start) +		return -1; +	min = d->data[start]; +	min_i = start; +	for (i = start + 1; i <= stop; i++) +		if (d->data[i] < min) { +			min = d->data[i]; +			min_i = i; +		} +	return min_i; +} + +int +cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time) +{ +	int	start, stop; +	int	i; +	double	max; +	int	max_i; + +	if (d->num == 0) +		return -1; +	start = (int) ceil((min_time - d->start) / d->step); +	if (start < 0) +		start = 0; +	stop = (int) floor((max_time - d->start) / d->step); +	if (stop >= d->num) +		stop = d->num - 1; +	if (stop < start) +		return -1; +	max = d->data[start]; +	max_i = start; +	for (i = start + 1; i <= stop; i++) +		if (fabs(d->data[i]) > max) { +			max = fabs(d->data[i]); +			max_i = i; +		} +	return max_i; +}  | 
