From 40d1234bf4965a6cb4ee9ef77c5f8e16ae708c21 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 1 Dec 2010 10:32:43 -0300 Subject: [PATCH] usrp: try to bring back sanity to pre- and post-processing of FFT data The pre- and post-processing of FFT data was tweaked based on results obtained from a mis-configured measurement setup, in an only partially successful attempt to right the wrong data. - usrp/fft.c (fft_complex): square the magnitude on output but don't square the scaling - usrp/fft.c (fft_real): square the magnitude on input (does this make sense ?) - usrp/fft.c (fft_real): scale the output with the square root of the FFT size (dubious) --- usrp/fft.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/usrp/fft.c b/usrp/fft.c index d0cdd34..79e9a35 100644 --- a/usrp/fft.c +++ b/usrp/fft.c @@ -31,8 +31,8 @@ static void fft_complex(int n, const float *re, const float *im, double *res) fftw_execute(plan); for (i = 0; i != n; i++) { - a = hypot(out[i][0], out[i][1])/n; -// a = a*a; + a = hypot(out[i][0], out[i][1]); // /n; + a = a*a/n; res[i] = a; } } @@ -46,16 +46,18 @@ static void fft_real(int n, const float *re, const float *im, double *res) double a ; in = fftw_malloc(sizeof(double)*n); - (void) a; - for (i = 0; i != n; i++) - in[i] = hypot(re[i], im[i]); + for (i = 0; i != n; i++) { + a = hypot(re[i], im[i]); + in[i] = a*a; + } plan = fftw_plan_r2r_1d(n, in, res, FFTW_REDFT10, FFTW_ESTIMATE); fftw_execute(plan); + /* @@@ not sure at all about the scaling */ for (i = 0; i != n; i++) - res[i] /= n; + res[i] = res[i]/sqrt(n); }