comparison src/helper.c @ 244:8c768f32a6a8

Add new helper function xtract_smoothed(), e.g. can be used to extract smoothed spectrum
author Jamie Bullock <jamie@jamiebullock.com>
date Fri, 06 Jun 2014 09:55:01 +0100
parents ef80f7c52c6d
children d383a8c66b5d
comparison
equal deleted inserted replaced
243:d13189c1005c 244:8c768f32a6a8
73 73
74 return rv; 74 return rv;
75 75
76 } 76 }
77 77
78
79 /*
80 * Implements y[n] = k * x[n] + (1-k) * y[n-1]
81 */
82 int xtract_smoothed(const double *data, const int N, const void *argv, double *result)
83 {
84 double gain = *(double *)argv;
85 double oneminusgain = 1.0 - gain;
86 int i;
87
88 // reverse filtering first
89 for (i = N - 2; i >= 0; i--)
90 {
91 result[i] = gain * data[i] + oneminusgain * data[i+1];
92 }
93
94 // then forward filtering
95 for (i = 1; i < N; i++)
96 {
97 result[i] = gain * result[i] + oneminusgain * result[i-1];
98 }
99
100 return XTRACT_SUCCESS;
101 }
102
103
78 //inline int xtract_is_denormal(double const d) 104 //inline int xtract_is_denormal(double const d)
79 int xtract_is_denormal(double const d) 105 int xtract_is_denormal(double const d)
80 { 106 {
81 if(sizeof(d) != 2 * sizeof(int)) 107 if(sizeof(d) != 2 * sizeof(int))
82 fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n"); 108 fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n");