python – Why function sampled in time frequency is not repeating?
I’m reading my lecture and found this figure:
sampled signal in frequency domain
So, I get the continuous function after sampling, in frequency domain, should repeat the pattern of the original continuous function. But in my Python code I just get one square where it should be a
lot more squares repeating. I’m new to signals (I’m not engineer, it’s an additional course) so I’m a little confused with my code. Am I missing something? Sorry if it is something dumb or concept misunderstanding.
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()
Read more here: Source link