Mercurial > hg > libxtract
diff 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 |
line wrap: on
line diff
--- a/src/helper.c Thu Jun 05 20:31:33 2014 +0100 +++ b/src/helper.c Fri Jun 06 09:55:01 2014 +0100 @@ -75,6 +75,32 @@ } + +/* + * Implements y[n] = k * x[n] + (1-k) * y[n-1] + */ +int xtract_smoothed(const double *data, const int N, const void *argv, double *result) +{ + double gain = *(double *)argv; + double oneminusgain = 1.0 - gain; + int i; + + // reverse filtering first + for (i = N - 2; i >= 0; i--) + { + result[i] = gain * data[i] + oneminusgain * data[i+1]; + } + + // then forward filtering + for (i = 1; i < N; i++) + { + result[i] = gain * result[i] + oneminusgain * result[i-1]; + } + + return XTRACT_SUCCESS; +} + + //inline int xtract_is_denormal(double const d) int xtract_is_denormal(double const d) {