簡體   English   中英

Python中高斯函數的傅立葉變換

[英]Fourier transform of a Gaussian function in Python

我想計算一些高斯函數的傅立葉變換。 考慮簡單的高斯g(t)= e ^ {-t ^ 2}。 g(t)的傅立葉變換具有一個簡單的解析表達式 ,使得第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

很簡單。 現在根據文檔 h[0]應該包含零頻率項,從解析表達式中我們可以知道它是根pi。 但是相反它給出了746.444

為什么解析解決方案與計算解決方案之間存在差異?

不知道為什么您認為應該得到分析表達。 NUmPy中的DFFT顯然是不對稱的,如果您在此處查看A k的公式,則可以清楚地看到,對於A 0,您應該獲得輸入和。 同樣,從[-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

它打印

(-4.0, 0.0, 4.0)
886.2269119018041
(886.226911901804+0j)

您可以進行逆變換並將其繪制

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()

並得到

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM