-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathamplifier.py
More file actions
77 lines (53 loc) · 1.79 KB
/
amplifier.py
File metadata and controls
77 lines (53 loc) · 1.79 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
71
72
73
74
75
76
77
#########################################################################################
##
## AMPLIFIER BLOCK
## (blocks/amplifier.py)
##
#########################################################################################
# IMPORTS ===============================================================================
import numpy as np
from ._block import Block
from ..optim.operator import Operator
# SISO BLOCKS ===========================================================================
class Amplifier(Block):
"""Amplifies the input signal by multiplication with a constant gain term.
Like this:
.. math::
y(t) = \\mathrm{gain} \\cdot u(t)
Note
----
This block is purely algebraic and its operation (`op_alg`) will be called
multiple times per timestep, each time when `Simulation._update(t)` is
called in the global simulation loop.
Example
-------
The block is initialized like this:
.. code-block:: python
#amplification by factor 5
A = Amplifier(gain=5)
Parameters
----------
gain : float
amplifier gain
Attributes
----------
op_alg : Operator
internal algebraic operator
"""
def __init__(self, gain=1.0):
super().__init__()
self.gain = gain
self.op_alg = Operator(
func=lambda x: x*self.gain,
jac=lambda x: self.gain*np.eye(len(x))
)
def update(self, t):
"""update system equation in fixed point loop
Parameters
----------
t : float
evaluation time
"""
u = self.inputs.to_array()
y = self.op_alg(u)
self.outputs.update_from_array(y)