脉冲的傅立叶变换

时间:2019-09-09 11:23:26

标签: python

我正在尝试使用Python绘制脉冲的傅立叶变换:

import numpy as np
import matplotlib.pyplot as plt

def pulse(time, L=1, A=1, C=0):
    return [A * int(C-L/2 <= t <= C+L/2) for t in time]

# data
time = np.arange(-5, 5, 0.01)
freq = np.arange(-5, 5, 0.01)
signal = pulse(time)
fourier = [np.mean(signal * np.exp(-2j * np.pi * f * time)) for f in freq]

# figure
fig, axs = plt.subplots(nrows=3, figsize=(6, 6))

# original signal
axs[0].grid(True)
axs[0].set_ylabel('f(t)')
axs[0].plot(time, signal)

# real part fourier transform
axs[1].grid(True)
axs[1].set_ylabel('Re(F{f})')
axs[1].plot(freq, np.real(fourier))

# Fourier{pulse(width)} = width * sinc(PI * f * width)
axs[2].grid(True)
axs[2].set_ylabel('sinc(f)')
axs[2].plot(freq, np.sinc(np.pi*freq))

# show
fig.canvas.set_window_title('Fourier Transform')
plt.show()

哪个生产:

enter image description here

我不确定为什么最后两个图不完全相同。有什么想法吗?

我想错误在于那几行:

freq = np.arange(-5, 5, 0.01)
fourier = [np.mean(signal * np.exp(-2j * np.pi * f * time)) for f in freq]

0 个答案:

没有答案