numpy离散连续傅里叶变换 [英] Discretized continuous Fourier transform with numpy

查看:193
本文介绍了numpy离散连续傅里叶变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Consider a function f(t), how do I compute the continuous Fouriertransform g(w) and plot it (using numpy and matplotlib)?

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

This or the inverse problem (g(w) given, plot of f(t) unknown) occurs if there exists no analytical solution to the Fourier Integral.

推荐答案

您可以使用

You can use the numpy FFT module for that, but have to do some extra work. First let's look at the Fourier integral and discretize it: Here k,m are integers and N the number of data points for f(t). Using this discretization we get

最后一个表达式中的和正好是numpy使用的离散傅立叶变换(DFT)(请参见

The sum in the last expression is exactly the Discrete Fourier Transformation (DFT) numpy uses (see section "Implementation details" of the numpy FFT module). With this knowledge we can write the following python script

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

生成的图表明该脚本有效

The resulting plot shows that the script works

这篇关于numpy离散连续傅里叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆