diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2007-12-27 17:51:07 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2007-12-27 17:51:07 +0000 |
commit | 24f2b43e28e755423cc0c319aafcf74e7db5b61b (patch) | |
tree | 7bb9ae8a66c9961fded7572bf2aeb650c55a370d /src/vector.c | |
parent | 6abcb447777c3ab48bdbe720fc3d84d3e8841317 (diff) | |
download | LibXtract-24f2b43e28e755423cc0c319aafcf74e7db5b61b.tar.gz LibXtract-24f2b43e28e755423cc0c319aafcf74e7db5b61b.tar.bz2 LibXtract-24f2b43e28e755423cc0c319aafcf74e7db5b61b.zip |
- Added extra argument to xtract_spectrum to give the option of normalising the magnitude/power coeffificients
- Removed duplicate code block (argc assignment) from descriptors.c
- Added some extra documentation to libxtract.h
Diffstat (limited to 'src/vector.c')
-rw-r--r-- | src/vector.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/vector.c b/src/vector.c index 06fc281..d3fdd67 100644 --- a/src/vector.c +++ b/src/vector.c @@ -45,12 +45,17 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *result){ - float *input, *rfft, q, temp; + float *input, *rfft, q, temp, max; size_t bytes; - int n , NxN, M, vector, withDC, argc; - //fftwf_plan plan; + int n, + NxN, + M, + vector, + withDC, + argc, + normalise; - vector = argc = withDC = 0; + vector = argc = withDC = normalise = 0; M = N >> 1; NxN = XTRACT_SQ(N); @@ -62,13 +67,14 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res q = *(float *)argv; vector = (int)*((float *)argv+1); withDC = (int)*((float *)argv+2); + normalise = (int)*((float *)argv+3); + + temp = 0.f; + max = 0.f; XTRACT_CHECK_q; if(fft_plans.spectrum_plan == NULL){ - /* FIX: Not sure this should really be here. Might introduce - * DEBUG_POST macro, or some kind of error handler, or leave it to the - * caller... */ fprintf(stderr, "libxtract: Error: xtract_spectrum() has uninitialised plan\n"); return XTRACT_NO_RESULT; @@ -98,6 +104,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res XTRACT_DB_SCALE_OFFSET; result[M + n - 1] = n * q; } + max = result[n] > max ? result[n] : max; } break; @@ -113,6 +120,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res (XTRACT_SQ(rfft[n]) + XTRACT_SQ(rfft[N - n])) / NxN; result[M + n - 1] = n * q; } + max = result[n] > max ? result[n] : max; } break; @@ -133,6 +141,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res XTRACT_DB_SCALE_OFFSET; result[M + n - 1] = n * q; } + max = result[n] > max ? result[n] : max; } break; @@ -149,6 +158,7 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res XTRACT_SQ(rfft[N - n])) / N; result[M + n - 1] = n * q; } + max = result[n] > max ? result[n] : max; } break; } @@ -157,16 +167,26 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res /* The DC component */ result[0] = XTRACT_SQ(rfft[0]); result[M + 1] = 0.f; + max = result[0] > max ? result[0] : max; /* The Nyquist */ result[M] = XTRACT_SQ(rfft[M]); result[N + 1] = q * M; + max = result[M] > max ? result[M] : max; + M++; /* So we normalise the Nyquist (below) */ } else { /* The Nyquist */ result[M - 1] = (float)XTRACT_SQ(rfft[M]); result[N - 1] = q * M; + max = result[M - 1] > max ? result[M - 1] : max; } + + if(normalise){ + for(n = 0; n < M; n++) + result[n] /= max; + } + fftwf_free(rfft); free(input); |