4 sys
.path
.insert(0, os
.getcwd())
5 prefix
= os
.path
.join(sys
.path
[0], "build")
6 if not os
.path
.exists(prefix
):
11 except Exception as e
:
20 def num_set(self
, num
):
21 self
._num
= np
.array(num
, dtype
=float)
22 self
.input = np
.array(len(num
) * [0.0], dtype
=float)
24 num
= property(num_get
, num_set
, None, None)
29 def den_set(self
, den
):
30 self
._den
= np
.array(den
, dtype
=float)
31 self
.output
= np
.array(len(den
) * [0.0], dtype
=float)
33 den
= property(den_get
, den_set
, None, None)
35 def __init__(self
, num
, den
):
39 def __call__(self
, input: float) -> float:
40 self
.input = np
.roll(self
.input, 1)
41 self
.input[0] = input # type: ignore
42 output
= self
._num
@ self
.input - self
._den
@ self
.output
# type: ignore
43 self
.output
= np
.roll(self
.output
, 1)
44 self
.output
[0] = output
# type: ignore
49 data
= np
.arange(0, 0.2, Ts
)
52 import control
.matlab
as ct
54 sysc
= ct
.tf(133, [1, 25, 0])
55 sysd
= ct
.c2d(sysc
, Ts
)
58 [[num
]], [[den
]] = ct
.tfdata(sysd
)
59 except ModuleNotFoundError
:
60 num
= [6.59492796e-05, 6.54019884e-05]
61 den
= [1.0, -1.97530991, 0.97530991]
62 except Exception as e
:
66 tf
= a
.tf(num
, den
[1:])
67 tf_
= TF(num
, den
[1:])
73 print(tf_
.num
, tf_
.den
, tf_
.input, tf_
.output
)
74 print(tf
.num
, tf
.den
, tf
.input, tf
.output
)