-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathexample_algebraicchain.py
More file actions
61 lines (48 loc) · 1.42 KB
/
example_algebraicchain.py
File metadata and controls
61 lines (48 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
#########################################################################################
##
## PathSim example of a purely algebraic signal chain
##
#########################################################################################
# IMPORTS ===============================================================================
import numpy as np
import matplotlib.pyplot as plt
from pathsim import Simulation, Connection
from pathsim.blocks import (
Source,
Constant,
Function,
Amplifier,
Adder,
Scope
)
# Algebraic Signal ======================================================================
#blocks that define the system
Src = Source(np.sin)
Cns = Constant(-1/2)
Amp = Amplifier(2)
Fnc = Function(lambda x: x**2)
Add = Adder()
Sc1 = Scope(labels=["sin"])
Sc2 = Scope(labels=["a", "b"])
blocks = [Src, Cns, Amp, Fnc, Add, Sc1, Sc2]
#the connections between the blocks
connections = [
Connection(Src, Fnc, Sc1),
Connection(Fnc, Add[0], Sc2[0]),
Connection(Cns, Add[1]),
Connection(Add, Amp),
Connection(Amp, Sc2[1])
]
#initialize simulation with the blocks, connections
Sim = Simulation(
blocks,
connections,
dt=0.01
)
# Run Example ===========================================================================
if __name__ == "__main__":
#run the simulation for some time
Sim.run(12)
Sc1.plot(lw=2)
Sc2.plot(lw=2)
plt.show()