我试图在
Python
中展示时域中两个信号相乘与频域中它们的卷积的等价性。
fftshift
函数来显示这种等价性,但示例是在Matlab
中完成的。我期望在Python
中得到完全相同的结果,但它不一样,代码如下:
f = 2e6
t = np.linspace(0,1,64)
x = np.sin(2*np.pi*f*t)
y = np.sin(2*np.pi*0.5*f*t)
# multiplication in time domain
signal_xy = x*y
# Fourier of multiplied signals and individual signal
FFT_xy = np.fft.fft(signal_xy)
FFT_x = np.fft.fft(x)
FFT_y = np.fft.fft(y)
# plot the result
plt.plot(abs(FFT_xy))
plt.plot(np.fft.fftshift(abs(np.convolve(np.fft.fftshift(FFT_x),np.fft.fftshift(FFT_y), 'same')))/len(FFT_x), linestyle='--')
我也尝试使用
fftshift
模块中的 convolve
和 scipy
,但结果完全一样。
fftshift
和 convolve
功能在 Python
中是否可以正常工作?