34 lines
492 B
Python
34 lines
492 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import scipy as sp
|
|
|
|
f_s = 8E3
|
|
|
|
T_s = 1/f_s
|
|
t = np.arange(-5,5,T_s)
|
|
|
|
f = np.linspace(0,f_s,len(t))
|
|
omega = 2*np.pi*f
|
|
|
|
def u(t):
|
|
return np.heaviside(t, 1)
|
|
|
|
w = u(t) - u(t-0.6) + u(t-0.7) - u(t-1)
|
|
|
|
W_c = 1j*(np.exp(-1j*omega*0.6) + np.exp(-1j*omega) - np.exp(-1j*omega*0.7) - 1)/omega
|
|
W_d = sp.fft.fft(w)
|
|
|
|
print(W_c[:10])
|
|
print(W_d[:10])
|
|
|
|
|
|
plt.plot(t,w)
|
|
plt.show()
|
|
|
|
|
|
plt.subplot(211)
|
|
plt.plot(W_c)
|
|
plt.subplot(212)
|
|
plt.plot(W_d)
|
|
plt.show()
|