Laptop backup week 10? (for safety reasons)
This commit is contained in:
@@ -6,20 +6,32 @@ import matplotlib.pyplot as plt
|
||||
def u(n):
|
||||
return np.heaviside(n, 1)
|
||||
|
||||
|
||||
# Transfer function for an ideal lowpass filter
|
||||
def ideal_lowpass(omega, omega_c):
|
||||
return np.where(np.abs(omega) <= omega_c, 1, 0)
|
||||
|
||||
|
||||
def main():
|
||||
omega_c = 0.4*np.pi
|
||||
omega = np.arange(0, np.pi, 0.05*np.pi)
|
||||
f_c = 0.4 # Cutoff frequency
|
||||
omega_c = np.pi*f_c # Angular cutoff frequency
|
||||
omega = np.arange(0, np.pi, 0.05*np.pi) # Frequency range
|
||||
|
||||
h_lpf = ideal_lowpass(omega, omega_c)
|
||||
n = np.arange(-50, 51) # Sample range (100 samples centered at 0)
|
||||
|
||||
plt.plot(omega, h_lpf)
|
||||
x = f_c*np.sinc(f_c*n) # Impulse resonse of ideal LPF
|
||||
plt.stem(n,x)
|
||||
plt.show()
|
||||
|
||||
h_lpf = ideal_lowpass(omega, omega_c) # Plot X(e^jw)
|
||||
plt.plot(omega, h_lpf)
|
||||
plt.xlabel("Frequency")
|
||||
plt.ylabel("DTFT of Ideal Lowpass Filter")
|
||||
|
||||
|
||||
for k in (10, 20, 30): # K values for truncated DTFT
|
||||
w,h = sp.signal.freqz(x[50-k:50+k], 1, omega) # Calculate truncated DTFT
|
||||
plt.plot(omega, np.abs(h)) # Plot magnitude of truncated DTFT
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
% First 100 samples
|
||||
for n=0:99
|
||||
y1(n+1) = (1 - (0.95)^(n+1))/0.05;
|
||||
y2(n+1) = n + 1;
|
||||
end
|
||||
|
||||
% Plot output of system for input x[n] = 0.95^n u[n]
|
||||
figure(1)
|
||||
n=0:1:99;
|
||||
stem(n,y1)
|
||||
xlabel('n')
|
||||
ylabel('y(n)')
|
||||
|
||||
% Plot output of system for input x[n] = u[n]
|
||||
figure(2)
|
||||
n=0:1:99;
|
||||
stem(n,y2)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import numpy as np
|
||||
import scipy as sp
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def main():
|
||||
n = np.arange(100) # First 100 samples
|
||||
|
||||
y_1 = (1 - 0.95**(n+1))/0.05 # Output of system for input x[n] = 0.95^n u[n]
|
||||
y_2 = n + 1 # Output of system for input x[n] = u[n]
|
||||
|
||||
plt.stem(n, y_1) # Plot y_1[n]
|
||||
plt.xlabel("n")
|
||||
plt.ylabel("y[n]")
|
||||
plt.show()
|
||||
|
||||
plt.stem(n, y_2) # Plot y_2[n]
|
||||
plt.xlabel("n")
|
||||
plt.ylabel("y[n]")
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user