我想将numpy FFT(DFT)用作连续傅立叶变换(CFT)的离散化。
,当预期的CFT为实数时,一切都会顺利进行(例如,高斯定为零)所以我尝试了一个偏移的高斯,它期望CFT同时具有实部和虚部:
以下结果显示虚部以某种方式翻转
这是我的代码:
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()