【问题标题】:Fourier Shift theorem python傅里叶位移定理 python
【发布时间】:2021-07-29 10:41:02
【问题描述】:

所以我试图使用移位定理来找到相隔 30 像素的两个方波的傅立叶变换,但是当我将两个波的傅立叶变换与一个波的傅立叶变换相加到第二个进行比较时使用它们不匹配的移位定理挥动,我不知道为什么

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

plt.rcParams['image.cmap'] = 'magma'

import h5py 
import scipy.fftpack

%matplotlib notebook
def magsq(arr):
    return np.abs(arr*np.conj(arr))

fig1,ax1=plt.subplots()
l=512
test=np.zeros(l)
a=int(len(test)/2)
b=10
test[a-b:a+b]=1
test
ax1.plot(test)

test2=np.zeros(l)
test2[a-b:a+b]=1
test2[a+b+30:a+b+30+2*b]=1
ax1.plot(test2,'--')

FT=np.fft.fft(test)

x=np.linspace(0,l,l)
w = np.fft.fftfreq(30)
s=30
shift=FT*np.e**(1j*2*np.pi*x*s/l)

shifted=FT+shift
FT=np.fft.fftshift(FT)
shifted=np.fft.fftshift(shifted)
shiftedi=magsq(shifted)

FT2=np.fft.fft(test2)
FT2=np.fft.fftshift(FT2)
FT2I=magsq(FT2)
fig2,ax2=plt.subplots()
#ax2.plot(FTI)
ax2.plot(shiftedi)
ax2.plot(FT2I,'--')

【问题讨论】:

  • 也许你应该使用x = np.arange(l),使用linspace(0, l, l)0, 1*512/511, 2*512/511, …, 511*512/511

标签: python numpy matplotlib fft


【解决方案1】:

您将信号移动 30 个像素的代码应如下所示。

test2[a-b+30:a+b+30]=1

那么两个变换完全匹配

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多