-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathexample_transferfunction.py
More file actions
55 lines (38 loc) · 1.42 KB
/
example_transferfunction.py
File metadata and controls
55 lines (38 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
#########################################################################################
##
## PathSim Example for TransferFunction
##
#########################################################################################
# IMPORTS ===============================================================================
import matplotlib.pyplot as plt
import numpy as np
from pathsim import Simulation, Connection
from pathsim.blocks import Source, Scope, TransferFunctionPRC
from pathsim.solvers import RKCK54, GEAR52A
# STEP RESPONSE OF A TRANSFER FUNCTION ==================================================
#step delay
tau = 5.0
#simulation timestep
dt = 0.05
#transfer function parameters
const = 0.0
poles = [-0.3, -0.05+0.4j, -0.05-0.4j, -0.1+2j, -0.1-2j]
residues = [-0.2, -0.2j, 0.2j, 0.3, 0.3]
#blocks and connections
Sr = Source(lambda t: int(t>=tau))
TF = TransferFunctionPRC(Poles=poles, Residues=residues, Const=const)
Sc = Scope(labels=["step", "response"])
blocks = [Sr, TF, Sc]
connections = [
Connection(Sr, TF, Sc),
Connection(TF, Sc[1])
]
#initialize simulation
Sim = Simulation(blocks, connections, dt=dt, log=True, Solver=RKCK54)
# Run Example ===========================================================================
if __name__ == "__main__":
#run simulation
Sim.run(100)
#plot the results from the scope directly
Sc.plot()
plt.show()