简体   繁体   中英

IFFT of a Gaussian power spectrum - Python

I want to calculate the Inverse Fourier Transform of a Gaussian power spectrum, thus obtaining a Gaussian again. I want to use this fact to check that the IFFT of my Gaussian power spectrum is sensible, in the sense that it produces an array of data effectively distributed in Gaussian way. Now, it turns out that the IFFT must be multiplied by a factor 2*pi*N, where N is the dimension of the array, in order to recover the analytic correlation function (which is the Inverse Fourier Transform of the power spectrum). Can someone explain why?

Here is the piece of code that first fills an array with the Gaussian power spectrum and then does the IFFT of the power spectrum.

power_spectrum_k = np.zeros(n, float)
for k in range(1, int(n/2+1)):
    power_spectrum_k[k] = math.exp(-(2*math.pi*k*sigma/n)*(2*math.pi*k*sigma/n))

for k in range(int(n/2+1), n):
    power_spectrum_k[k] = power_spectrum_k[int(k - n/2)]

inverse_transform2 = np.zeros(n, float)
inverse_transform2 = np.fft.ifft(power_spectrum_k)

where the symmetry of the power spectrum comes from the need to get a real correlation function, at the same time following the rules for the use of numpy.ifft (quoting from the documentation:

"The input should be ordered in the same way as is returned by fft, ie, a[0] should contain the zero frequency term, a[1:n/2+1] should contain the positive-frequency terms, and a[n/2+1:] should contain the negative-frequency terms, in order of decreasingly negative frequency".)

The reason is the Plancherel theorem , which states that the Fourier transform conserves the signal's energy, ie, the integral over |x(t)|² equals the integral over |X(f)|² . If you have more samples (eg, caused by higher sampling rate or a longer interval), you have more energy. For that reason your IFFT result is scaled by a factor of N . Your factor depends on hand on the convention of Fourier Integral used, as @pv already noted. On the other hand, on the length of your interval, since integral over the power of the sampled and the continuous interval need to be the same.

I'd recommend using an existing library for an fft. Not as its particularly difficult but there are some well optimised solutions. Try scipy http://docs.scipy.org/doc/scipy/reference/fftpack.html or my favourite fftw https://hgomersall.github.io/pyFFTW/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM