【发布时间】:2022-01-19 01:32:22
【问题描述】:
我正在阅读我的讲座并发现了这个数字: sampled signal in frequency domain
所以,我得到采样后的连续函数,在频域中,应该重复原始连续函数的模式。但是在我的 Python 代码中,我只得到一个应该是 更多的方块重复。我是信号新手(我不是工程师,这是一门附加课程),所以我对我的代码有点困惑。我错过了什么吗?对不起,如果这是愚蠢或概念误解。
def g(t):
if t == 0:
return 1
return np.sin(1.5*np.pi*t) / (1.5*np.pi*t)
if __name__ == '__main__':
n = 40
fs = 100 # 0.01
t = np.arange(-n, n, 1.0/fs)
y = [g(i) for i in t]
plt.plot(t, y)
plt.xlim(-5, 5)
plt.show()
# Impulse train
n = 40
T = 1.0/2.5
tn = np.arange(-n, n, T)
# y2 = [1 for i in range(len(tn))]
nT = tn*T
y2 = [g(i) for i in nT]
# Sampled g
plt.stem(nT, y2, 'r', markerfmt='C3o', use_line_collection=True)
plt.xlim(-0.9, 0.9)
plt.show()
fft_s = fft(y2)
plt.plot(fftshift(fftfreq(len(fft_s ))),
fftshift(np.abs(fft_s )))
plt.show()
【问题讨论】:
标签: python numpy matplotlib signal-processing