Repository navigation
Expand file tree
/
Copy pathLab5.py
More file actions
70 lines (57 loc) · 1.42 KB
/
Copy pathLab5.py
File metadata and controls
70 lines (57 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#LAB 5
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig
##################################
steps = 1e-5
t = np.arange(0,1.2e-3+steps,steps) #DEFINE TIME ARRAY
R = 1000
L = 27e-3
C = 100e-9
def toRad(deg):
return ((deg * np.pi)/180)
def h(t):
h = 10331 * np.exp(-5000*t)*np.sin(18584*t+toRad(105))*u(t)
return h
def hstep(t):
h = (1/18584) * np.exp(-5000*t)*np.sin(18584*t)*u(t)
return h
#STEP FUNCTION
def u(t):
y = np.zeros((len(t)))
for i in range(len(t)):
if t[i] < 0:
y[i] = 0
else:
y[i] = 1
return y
numH = [(1/(R*C)),0]
demH = [1,(1/(R*C)),(1/(L*C))]
tout, yout = sig.impulse((numH,demH), T = t)
plt.figure(figsize=(12,8))
plt.subplot(2,1,1)
plt.plot(t,h(t))
plt.title('Impulse Response of RLC Circuit')
plt.ylabel('Hand-Solved Response')
plt.grid(True)
plt.subplot(2,1,2)
plt.plot(tout,yout)
plt.ylabel('Scipy Impulse Response')
plt.grid(True)
plt.xlabel('t')
plt.show()
tstep,ystep = sig.step((numH,demH), T = t)
plt.figure(figsize = (12,8))
plt.plot(tstep,ystep)
plt.title('Step Response of RLC Circuit')
plt.ylabel('sig.step Response')
plt.grid(True)
plt.xlabel('t')
plt.show()
plt.figure(figsize = (12,8))
plt.plot(t,hstep(t))
plt.title('Impulse Response of RLC Circuit')
plt.ylabel('Hand-Solved Response')
plt.grid(True)
plt.xlabel('t')
plt.show()