Python中高斯函数的Fourier变换

2024-05-29 01:35:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想计算一些高斯函数的傅里叶变换。考虑简单高斯g(t)=e^{-t^2}。g(t)的Fourier变换有一个simple analytical expression ,因此第0个频率就是根pi。在

如果我尝试在Python中执行相同的操作:

N = 1000
t = np.linspace(-1,1,N)
g = np.exp(-t**2)

h = np.fft.fft(g) #This is the Fourier transform of expression g

很简单。现在as per the docsh[0]应该包含零频率项,我们从解析表达式中知道它是根pi。但它却给出746.444?!在

为什么解析解与计算解有出入?在


Tags: ofthe函数fftisnppitransform
1条回答
网友
1楼 · 发布于 2024-05-29 01:35:53

不知道为什么你认为你应该得到分析表达式。NUmPy中的DFFT显然是不对称的,如果你看看Akhere的公式,你可以清楚地看到对于A0你应该得到输入的和。同样,从[-sigma…sigma]区间得到高斯分布是不对的。在

这是一个修改过的例子

import numpy as np
import matplotlib.pyplot as plt

N = 4001
t = np.linspace(-4.0, 4.0, N)
print((t[0], t[2000], t[4000]))
g = np.exp(-t*t)
print(np.sum(g)) # sum of input

h = np.fft.fft(g, norm=None)
print(h[0]) # should be the same as sum of input

它会印出来

^{pr2}$

你可以做反变换,然后画出来

q = np.fft.ifft(h, norm=None)

plt.plot(t, g, label = "Gauss")
plt.show()
plt.plot(t, np.abs(q), label = "dFFT Gauss")
plt.show()
f = np.fft.fftfreq(N)
plt.plot(f, np.angle(h), f, np.abs(h))
plt.show()

然后得到

enter image description here

相关问题 更多 >

    热门问题