numpy FFT虚部与解析表达式不匹配

时间:2019-06-12 12:42:08

标签: python numpy fft

我想将numpy FFT(DFT)用作连续傅立叶变换(CFT)的离散化。

由于this post

,当预期的CFT为实数时,一切都会顺利进行(例如,高斯定为零)

所以我尝试了一个偏移的高斯,它期望CFT同时具有实部和虚部: gaussian ft

我在以下链接https://www.wolframalpha.com/input/?i=Fourier+transform+calculator&assumption=%7B%22F%22,+%22FourierTransformCalculator%22,+%22transformfunction%22%7D+-%3E%22e%5E(-(x-5.0)%5E2)%22&assumption=%7B%22F%22,+%22FourierTransformCalculator%22,+%22variable1%22%7D+-%3E%22x%22&assumption=%7B%22F%22,+%22FourierTransformCalculator%22,+%22variable2%22%7D+-%3E%22k%22中检查了

以下结果显示虚部以某种方式翻转 fft result

这是我的代码:

import matplotlib.pyplot as plt
import numpy as np

x0= 5.0 
steps = 0.01
xLeft=0.0

x = np.arange(xLeft, 205.0,steps)

g = np.exp( -(x-x0)**2 )

leng = len(g)

gft = np.fft.fft(g) #compute FFT

k = np.fft.fftfreq(leng)*2*np.pi/steps #generate independent variable  set in for FFT 

gft*=steps*np.exp(-complex(0,1)*k*(xLeft))/(np.sqrt(2*np.pi)) #scale FFT and multiply by phase factor (form previous answer) 

igft = np.imag(gft)
rgft = np.real(gft)

true_fft = np.exp(-0.25*k**2+5.0j*k)/np.sqrt(2) #analytic expression for FFT
itrue_fft = np.imag(true_fft)
rtrue_fft = np.real(true_fft)

plt.plot(k, rgft, linewidth=3, label="real part")
plt.plot(k, igft, linewidth=3, label="imag part")
plt.plot(k, rtrue_fft, 'o', ms=2, label="analytic real")
plt.plot(k, itrue_fft, 'o', ms=2, label="analytic imag")
plt.legend()
plt.show()

0 个答案:

没有答案