Fixed scaling issue in FFT

This commit is contained in:
Casper Jansen 2021-08-13 11:40:25 +02:00
parent 4c0f399505
commit c98b10b83a

View File

@ -117,16 +117,19 @@ void PowerSpectra_compute(const PowerSpectra* ps,
TRACE(15,"fft done");
/* Scale fft such that power is easily computed */
const c scale_fac = d_sqrt(2/win_pow)/nfft;
/* Scale fft such that power is easily computed
* - Multiply power spectral density by 2 except at f=0 and f=fNq
* - Divide by energy of window function = nfft * window_power
* - .. sqrt(factors) because it is applied to output fft instead of psd */
const c scale_fac = d_sqrt(2/(nfft*win_pow));
cmat_scale(&fft_work,scale_fac);
TRACE(15,"scale done");
for(us i=0;i< nchannels;i++) {
/* Multiply DC term with 1/sqrt(2) */
/* Multiply DC term by 1/sqrt(2) */
*getcmatval(&fft_work,0,i) *= 1/d_sqrt(2.)+0*I;
/* Multiply Nyquist term with 1/sqrt(2) */
/* Multiply Nyquist term by 1/sqrt(2) */
*getcmatval(&fft_work,nfft/2,i) *= 1/d_sqrt(2.)+0*I;
}
check_overflow_xmat(fft_work);