From b8a9ca9df46e61868eb33d53423a2b78dcfa8ceb Mon Sep 17 00:00:00 2001 From: dwarning Date: Wed, 16 Aug 2017 21:35:41 +0200 Subject: [PATCH] correct the fft scaling for real input and complex output vector --- src/frontend/com_fft.c | 4 ++-- src/maths/cmaths/cmath4.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/com_fft.c b/src/frontend/com_fft.c index 4ef273efe..c61c89a6f 100644 --- a/src/frontend/com_fft.c +++ b/src/frontend/com_fft.c @@ -172,7 +172,7 @@ com_fft(wordlist *wl) fftw_execute(plan_forward); - scale = (double) length; + scale = (double) fpts - 1.0; for (j = 0; j < fpts; j++) { fdvec[i][j].cx_real = out[j][0]/scale; fdvec[i][j].cx_imag = out[j][1]/scale; @@ -200,7 +200,7 @@ com_fft(wordlist *wl) rffts(in, M, 1); fftFree(); - scale = (double) N; + scale = (double) fpts - 1.0; /* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ fdvec[i][0].cx_real = in[0]/scale; fdvec[i][0].cx_imag = 0.0; diff --git a/src/maths/cmaths/cmath4.c b/src/maths/cmaths/cmath4.c index e21a0f564..5111314ff 100644 --- a/src/maths/cmaths/cmath4.c +++ b/src/maths/cmaths/cmath4.c @@ -716,7 +716,7 @@ cx_fft(void *data, short int type, int length, int *newlength, short int *newtyp fftw_execute(plan_forward); - scale = (double) length; + scale = (double) fpts - 1.0; for (i = 0; i < fpts; i++) { outdata[i].cx_real = out[i][0]/scale; outdata[i].cx_imag = out[i][1]/scale; @@ -740,7 +740,7 @@ cx_fft(void *data, short int type, int length, int *newlength, short int *newtyp rffts(datax, M, 1); fftFree(); - scale = (double) N; + scale = (double) fpts - 1.0; /* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ outdata[0].cx_real = datax[0]/scale; outdata[0].cx_imag = 0.0;