简体   繁体   English

高斯功率谱的IFFT-Python

[英]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. 我想利用这一事实来检查我的高斯功率谱的IFFT是否合理,因为它会产生一系列以高斯方式有效分布的数据。 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). 现在,事实证明,IFFT必须乘以因子2 * pi * N,其中N是阵列的维数,以便恢复解析相关函数(它是功率谱的傅立叶逆变换)。 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. 这是一段代码,该代码首先用高斯功率谱填充一个数组,然后对功率谱进行IFFT。

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: 功率谱的对称性来自于需要获得真实的相关函数的同时,还遵循numpy.ifft的使用规则(引用文档:

"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".) “输入的排序方式应与fft返回的方式相同,即a [0]应包含零频项,a [1:n / 2 + 1]应包含正频项,而a [ n / 2 + 1:]应包含负频率项,以负频率递减的顺序进行。”)

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)|² . 原因是Plancherel定理 ,该定理指出傅里叶变换可节省信号能量,即| x(t)|²上的积分等于| 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 . 因此,您的IFFT结果缩放了N倍。 Your factor depends on hand on the convention of Fourier Integral used, as @pv already noted. 您的因素取决于使用的傅里叶积分惯例 ,正如@pv已经指出的那样。 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. 我建议将现有库用于ftf。 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/ 尝试scipy http://docs.scipy.org/doc/scipy/reference/fftpack.html或我最喜欢的fftw https://hgomersall.github.io/pyFFTW/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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