根据我的好朋友Wolfram的说法,一个高斯在时间/空间域中的傅立叶变换在频率/谱域中得到另一个高斯。当我使用numpy.fft.fft例程对此进行测试时,我并没有得到我所期望的结果。
import numpy as np
import matplotlib.pyplot as plt
N = 1000 # Number of samples
a = 10.0 # Inverse variance
x = np.linspace(-5, 5, N) # Spatial domain
y = np.exp(-a*x**2) # Gaussian in spatial domain
dx = x[1] - x[0] # Sampling rate
k = np.fft.fftfreq(N, dx) # Wave numbers
inds = np.argsort(k) # Sorting order of wave numbers
# Analytical solution for Fourier transform of y
y_hat = np.sqrt(np.pi / a) * np.exp(-np.pi**2 * k**2 / a)
# Numerical solution (FFT of y)
y_hat2 = np.fft.fft(y)
# Plot original function in spatial domain
plt.subplot(211)
plt.plot(x, y)
plt.xlabel("position [m]")
plt.ylabel("y")
# Plot solutions in the spectral domain
plt.subplot(212)
plt.plot(k[inds], np.real(y_hat2[inds]), label="Real FFT(y)")
plt.plot(k[inds], np.imag(y_hat2[inds]), label="Imag FFT(y)")
plt.plot(k[inds], y_hat[inds], "k--", label="Analytical")
plt.xlabel("wave number [1/m]")
plt.ylabel("FFT(y)")
plt.ylim((-1, 1))
plt.xlim((-5, 5))
plt.legend()
plt.tight_layout()
plt.show()结果:

事实证明,y的快速傅立叶变换的虚部是非零的,而实部在0附近疯狂振荡,这两种情况都不是解析解所期望的。有人能给我解释一下为什么会这样吗?
发布于 2019-06-26 23:14:18
对于严格实数的规范FFT结果,输入必须围绕FFT输入数组中的第一个元素(循环)对称。您的输入似乎是围绕输入数组的中间对称的,这将调整FFT结果(时移属性)。
尝试FFTShift操作。
https://stackoverflow.com/questions/56775974
复制相似问题