From d2b1ecbb23f6d2f6148ad585992d989c36c7c8e1 Mon Sep 17 00:00:00 2001 From: dwarning Date: Sun, 1 Mar 2026 16:18:24 +0100 Subject: [PATCH] correct fft scaling at Nyquist freq. in fft cmd and vector operation --- src/frontend/com_fft.c | 4 +++- src/maths/cmaths/cmath4.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/frontend/com_fft.c b/src/frontend/com_fft.c index baefb2c51..b06d1e37d 100644 --- a/src/frontend/com_fft.c +++ b/src/frontend/com_fft.c @@ -181,10 +181,12 @@ com_fft(wordlist *wl) scale = (double) fpts - 1.0; fdvec[i][0].cx_real = out[0][0]/scale/2.0; fdvec[i][0].cx_imag = 0.0; - for (j = 1; j < fpts; j++) { + for (j = 1; j < fpts-1; j++) { fdvec[i][j].cx_real = out[j][0]/scale; fdvec[i][j].cx_imag = out[j][1]/scale; } + fdvec[i][fpts-1].cx_real = out[fpts-1][0]/scale/2.0; + fdvec[i][fpts-1].cx_imag = 0.0; } diff --git a/src/maths/cmaths/cmath4.c b/src/maths/cmaths/cmath4.c index c29e53634..92cfe458a 100644 --- a/src/maths/cmaths/cmath4.c +++ b/src/maths/cmaths/cmath4.c @@ -777,10 +777,12 @@ cx_fft(void *data, short int type, int length, int *newlength, short int *newtyp scale = (double) fpts - 1.0; outdata[0].cx_real = out[0][0]/scale/2.0; outdata[0].cx_imag = 0.0; - for (i = 1; i < fpts; i++) { + for (i = 1; i < fpts-1; i++) { outdata[i].cx_real = out[i][0]/scale; outdata[i].cx_imag = out[i][1]/scale; } + outdata[fpts-1].cx_real = out[fpts-1][0]/scale/2.0; + outdata[fpts-1].cx_imag = 0.0; fftw_free(ind);