From 55e12c391bbfb4c6bd7054e78b807dfc97cd3ed5 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 20 Dec 2006 16:47:52 +0000 Subject: Added bin frequencies to second half of xtract_magnitude_spectrum() --- src/scalar.c | 6 +++--- src/vector.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/scalar.c b/src/scalar.c index c7d6edd..612fa3c 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -456,7 +456,7 @@ int xtract_lowest_value(const float *data, const int N, const void *argv, float int n = N; float temp; - *result = data[N]; + *result = data[--n]; while(n--){ if((temp = data[n]) > *(float *)argv) @@ -470,7 +470,7 @@ int xtract_highest_value(const float *data, const int N, const void *argv, float int n = N; - *result = data[N]; + *result = data[--n]; while(n--) *result = MAX(*result, data[n]); @@ -633,7 +633,7 @@ int xtract_failsafe_f0(const float *data, const int N, const void *argv, float * magnitudes = (float *)malloc(N * sizeof(float)); peaks = (float *)malloc(N * sizeof(float)); - xtract_magnitude_spectrum(data, N, NULL, magnitudes); + xtract_magnitude_spectrum(data, N, argv, magnitudes); argf[0] = 10.f; argf[1] = *(float *)argv; xtract_peaks(magnitudes, N, argf, peaks); diff --git a/src/vector.c b/src/vector.c index 3a6e587..739004e 100644 --- a/src/vector.c +++ b/src/vector.c @@ -32,7 +32,7 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, float *result){ - float *temp, *input; + float *temp, *input, q; size_t bytes; int n , M = N >> 1; fftwf_plan plan; @@ -41,17 +41,22 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, input = (float *)malloc(bytes = N * sizeof(float)); input = memcpy(input, data, bytes); + q = 0.f; + + q = *(float *)argv; + q = (q ? (q * .5) / M : 0.f); + plan = fftwf_plan_r2r_1d(N, input, temp, FFTW_R2HC, FFTW_ESTIMATE); fftwf_execute(plan); for(n = 1; n < M; n++){ result[n] = sqrt(SQ(temp[n]) + SQ(temp[N - n])) / N; - result[N-n] = 0.0f; + result[M + n] = n * q; } result[0] = fabs(temp[0]) / N; - result[M] = fabs(temp[M]) / N; + result[M] = q * .5; fftwf_destroy_plan(plan); fftwf_free(temp); -- cgit v1.2.3