Python 应如何重新调整fft点的比例,以获得与解析解相同的结果?

Python 应如何重新调整fft点的比例,以获得与解析解相同的结果?,python,numpy,fft,Python,Numpy,Fft,我想使用numpy fft包使用快速傅里叶变换,然后我尝试比较解析解和快速傅里叶变换之间的结果,虽然我可以从我所做的图中看出曲线是相似的,但很明显,比例是不同的 我尝试过几种不同版本的频率(角频率、频率和波数),但我所有的尝试都不起作用,在numpy文档中,不清楚快速傅里叶变换是如何精确定义的。例如,我想将指数函数在时间上的傅里叶变换转换到角频率域,f(t)=Exp(-a | t |),f(w)=a/pi*(a²+w²)(根据我们考虑的频率空间,这个解析解有多种版本) 我已经尝试了上述代码的多种

我想使用numpy fft包使用快速傅里叶变换,然后我尝试比较解析解和快速傅里叶变换之间的结果,虽然我可以从我所做的图中看出曲线是相似的,但很明显,比例是不同的

我尝试过几种不同版本的频率(角频率、频率和波数),但我所有的尝试都不起作用,在numpy文档中,不清楚快速傅里叶变换是如何精确定义的。例如,我想将指数函数在时间上的傅里叶变换转换到角频率域,f(t)=Exp(-a | t |),f(w)=a/pi*(a²+w²)(根据我们考虑的频率空间,这个解析解有多种版本)

我已经尝试了上述代码的多种不同变体,特别是频率,但我仍然没有达到fft和解析解相似的程度。有人能帮我一下吗?

可以应用于可积函数,如
np.exp(-0.5*abs(t))
。但是,计算周期信号的傅里叶变换。见和

因此,长度为T的帧的DFT对应于周期帧的傅里叶变换。由于帧从0开始,因此计算周期性右侧指数衰减的傅里叶变换: 如您所见,函数的一半
np.exp(-0.5*abs(t))
不显示。
让我们更正它并添加双边指数衰减的周期性递增部分。 我使用频率作为参数:

import matplotlib.pyplot as plt
import numpy as np

def e(t):
    return np.exp(-0.5*abs(t))
def F(w):
    return 0.5/(np.pi)*(1/(((0.5)**2)+((w)**2)))

def Fc(xi):
    #ok , that's sourced from https://en.wikipedia.org/wiki/Fourier_transform ... Square-integrable functions, one-dimensional, line 207
    return 2*0.5/(((0.5)**2)+(4*(np.pi*xi)**2))


framelength=100.
nbsample=1000
def ep(t):
    #the periodized negative part is added at the end of the frame.
    return np.maximum(np.exp(-0.5*abs(t)),np.exp(-0.5*abs(t-framelength)))

t=np.linspace(0,framelength,nbsample, endpoint=False)

#plotting the periodized signal, to see what's happening
ein=ep(t)
tp=np.linspace(0,10*framelength,10*nbsample, endpoint=False)
periodized=np.zeros(10*nbsample)
for i in range(10):
    for j in range(nbsample):
       periodized[i*nbsample+j]=ein[j]

plt.plot(tp,periodized,'k-',label='periodized frame')
plt.legend()
plt.show()

fourier=np.fft.fft(ep(t))/np.size(ep(t))*framelength

#comparing the mean is useful to check the overall scaling
print np.mean(ep(t))*framelength
print fourier[0]
print Fc(0)

#the frenquencies of the DFT of a frame of length T are 1/T, 2/T ... and negative for the second part of the array.
xi=np.fft.fftfreq(len(t), framelength/len(t))

# comparison between analytical Fourier transform and dft.
plt.plot(xi,Fc(xi),'o',label='F(xi)')
plt.plot(xi,np.real(fourier),'k-', lw=3, color='red', label='DTF')
plt.legend()
plt.show()
结果如下:

对于实验性非周期信号,当帧周期化时,会出现人为的不连续性。它诱导并用于衰减不连续性及其影响。其中一个潜在的窗口,称为泊松窗口,是一个双边指数衰减

import matplotlib.pyplot as plt
import numpy as np

def e(t):
    return np.exp(-0.5*abs(t))
def F(w):
    return 0.5/(np.pi)*(1/(((0.5)**2)+((w)**2)))

def Fc(xi):
    #ok , that's sourced from https://en.wikipedia.org/wiki/Fourier_transform ... Square-integrable functions, one-dimensional, line 207
    return 2*0.5/(((0.5)**2)+(4*(np.pi*xi)**2))


framelength=100.
nbsample=1000
def ep(t):
    #the periodized negative part is added at the end of the frame.
    return np.maximum(np.exp(-0.5*abs(t)),np.exp(-0.5*abs(t-framelength)))

t=np.linspace(0,framelength,nbsample, endpoint=False)

#plotting the periodized signal, to see what's happening
ein=ep(t)
tp=np.linspace(0,10*framelength,10*nbsample, endpoint=False)
periodized=np.zeros(10*nbsample)
for i in range(10):
    for j in range(nbsample):
       periodized[i*nbsample+j]=ein[j]

plt.plot(tp,periodized,'k-',label='periodized frame')
plt.legend()
plt.show()

fourier=np.fft.fft(ep(t))/np.size(ep(t))*framelength

#comparing the mean is useful to check the overall scaling
print np.mean(ep(t))*framelength
print fourier[0]
print Fc(0)

#the frenquencies of the DFT of a frame of length T are 1/T, 2/T ... and negative for the second part of the array.
xi=np.fft.fftfreq(len(t), framelength/len(t))

# comparison between analytical Fourier transform and dft.
plt.plot(xi,Fc(xi),'o',label='F(xi)')
plt.plot(xi,np.real(fourier),'k-', lw=3, color='red', label='DTF')
plt.legend()
plt.show()