【问题标题】:inverse Fourier unclear Data逆傅立叶不清晰数据
【发布时间】:2020-01-08 17:05:24
【问题描述】:

我目前正在尝试计算已知函数的逆傅立叶。 不幸的是 np.fft.ifft() 函数没有显示我正在寻找的结果。由于我不确定错误发生在哪里,我构建了一个已知问题并遇到了类似的错误。傅里叶函数是 1/(1+x^2),这个函数的逆傅里叶是 a*exp(-|k|)。有一个常数。 从图中可以看出,通过 np.fft.ifft() 函数生成的数据与实际数据相同。但我不知道为什么。

感谢您的宝贵时间

import numpy as np
import matplotlib.pyplot as plt

X=np.arange(-0.6,0.6,0.00001)
original_FT=[]
FT_known_result=[]
for x_val in X:
    original_FT.append(1/(1 + x_val**2))
    FT_known_result.append(np.exp(-abs(x_val)))


FT_test_list=np.fft.ifftshift(original_FT)



plt.figure()
plt.plot(X,FT_test_list,label='FT calc ifft')
plt.plot(X,FT_known_result,label='real FT')
plt.plot(X,original_FT,label="orginal data")
plt.legend()
plt.show()

【问题讨论】:

  • 您没有使用 FFT,您只是在使用与 FFT 相关的移位。只需添加y = np.fft.fft(original_FT)。还应该对要转换为翅膀的函数进行采样(即值变小的地方),否则会有明显的混叠(即,如果你想保持范围,让你的函数变窄)。也不需要数据点的数量来获取图片。最后,您不能将timefrequency 结果绘制在同一个图中。它们的点数相同,但物理意义不同。
  • 感谢您的快速回复。我仍然有一个问题:你的意思是我必须添加 y= np.fft.fft(original FT) 然后再次反转它?因为我不是在寻找 FT,而是在寻找逆 FT。我发现了一个错误,因为向量必须具有一定的结构。但同样,数据确实与真正的 FT 有一定的差异,我觉得这很奇怪。关于时间和频率。是的,你是 100 正确,那些不一样我只是出于可视化原因将它添加到情节中。

标签: python numpy fft inverse-transform


【解决方案1】:

以下所有内容均在 Jupyter 笔记本中完成。我没有重做洛伦兹的分析 FT,所以那里可能有错误。 我假设以下是正确的:

$$ FT  \left(  \frac{1}{\pi \Delta f} \frac{1} {1 + (\frac{f}{\Delta f})^2} \right)  = e^{ 2 \pi \Delta f |t|} $$

import numpy as np
import matplotlib.pyplot as p
%matplotlib inline


start,stop,num=-.5,.5,1000
t=np.linspace(start,stop,num)    # stop-start= 1.0 sec, inverse is frequency resolution , i.e 1 Hz
dt=(stop-start)/num        
print(f'time interval:  {dt} secs')     # will be 1 millisecond, inverse is frequency span i.e -500 Hz to +500 Hz

freq = np.fft.fftfreq(num,dt)
# print(freq)   #  0..499, -500.. -1  # unshifted; that can be useful, you don't need to shift to get the plots right
freq2 =  np.fft.fftshift(freq)
# print(freq2)    #  -500.. 0 .. 499    # we need the shift because you want to compare a spectrum = f (frequency)         
print(f'freq interval :  {freq2[1] - freq2[0]}  Hz')                 
# in numpy , given the time and frequency vectors we just made it is easy to get a function filled w/o a for loop
# let's assume that original_FT is a spectrum as is typical for a Lorentzian

df=5  # width of lorentzian

ori= 1/np.pi /df /(1 + (freq2/(df ))**2)   # a lorentzian of variable width, FT of bisided exponential
print(f'integral over lorentzian {np.sum(ori):.3f}') 
analytical= np.exp(-abs(t*df*2*np.pi ))     # a bisided exponential  (the envelope of a time dependency), 
                                    # the width has to be inversely proportional to the width of the Lorentzian
computed= np.abs(np.fft.fftshift(np.fft.fft(ori))) 


p.figure(figsize=(10,4))
p.subplot(131)
p.plot(freq2,ori,label="orginal spectral data")
p.xlabel('frequencies/Hz')
p.title('freq. domain')
p.legend()

p.subplot(132)
p.plot(t ,analytical ,label='real FT')
p.plot(t ,computed ,label='calc ifft')
p.xlabel('time/secs')
p.title('time domain')
p.legend()

p.subplot(133)
p.plot(t[490:510],analytical[490:510],'.-',label='real FT')
p.plot(t[490:510],computed[490:510],'.-',label='calc ifft')
p.xlabel('time/secs')
p.title('zoomed in')
p.legend();

【讨论】:

  • 感谢您的回答。我缺少的关键行是 np.fft.fftshift(np.fft.fft(ori))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
相关资源
最近更新 更多