gpt4 book ai didi

math - numpy离散连续傅里叶变换

转载 作者:行者123 更新时间:2023-12-03 21:38:17 24 4
gpt4 key购买 nike

考虑一个函数f(t),如何计算连续的Fouriertransform g(w)并将其绘制(使用numpy和matplotlib)?



如果不存在傅立叶积分的解析解,则会发生此问题或逆问题(给定g(w),f(t)的图)。

最佳答案

您可以为此使用numpy FFT module,但必须做一些额外的工作。首先,让我们看一下傅立叶积分并将其离散化:

在此,k,m是整数,N是f(t)的数据点数。使用这种离散化,我们得到


最后一个表达式中的和正好是numpy使用的离散傅立叶变换(DFT)(请参见numpy FFT module的“实现详细信息”部分)。
有了这些知识,我们可以编写以下python脚本

import numpy as np
import matplotlib.pyplot as pl

#Consider function f(t)=1/(t^2+1)
#We want to compute the Fourier transform g(w)

#Discretize time t
t0=-100.
dt=0.001
t=np.arange(t0,-t0,dt)
#Define function
f=1./(t**2+1.)

#Compute Fourier transform by numpy's FFT function
g=np.fft.fft(f)
#frequency normalization factor is 2*np.pi/dt
w = np.fft.fftfreq(f.size)*2*np.pi/dt


#In order to get a discretisation of the continuous Fourier transform
#we need to multiply g by a phase factor
g*=dt*np.exp(-complex(0,1)*w*t0)/(np.sqrt(2*np.pi))

#Plot Result
pl.scatter(w,g,color="r")
#For comparison we plot the analytical solution
pl.plot(w,np.exp(-np.abs(w))*np.sqrt(np.pi/2),color="g")

pl.gca().set_xlim(-10,10)
pl.show()
pl.close()


结果图表明该脚本有效

关于math - numpy离散连续傅里叶变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24077913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com