所以我试图用移位定理找到两个方波的傅里叶变换,这两个方波被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,'--')
将信号偏移30像素的代码如下所示
然后两个变换完全匹配
相关问题 更多 >
编程相关推荐