-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmargin_test.py
More file actions
47 lines (38 loc) · 1.73 KB
/
Copy pathmargin_test.py
File metadata and controls
47 lines (38 loc) · 1.73 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
#!/usr/bin/env python
#
# margin_test.py - test suit for stability margin commands
# RMM, 15 Jul 2011
import unittest
import numpy as np
from control.xferfcn import TransferFunction
from control.statesp import StateSpace
from control.margins import *
class TestMargin(unittest.TestCase):
"""These are tests for the margin commands in margin.py."""
def setUp(self):
self.sys1 = TransferFunction([1, 2], [1, 2, 3])
self.sys2 = TransferFunction([1], [1, 2, 3, 4])
self.sys3 = StateSpace([[1., 4.], [3., 2.]], [[1.], [-4.]],
[[1., 0.]], [[0.]])
def test_stability_margins(self):
gm, pm, sm, wg, wp, ws = stability_margins(self.sys1);
gm, pm, sm, wg, wp, ws = stability_margins(self.sys2);
gm, pm, sm, wg, wp, ws = stability_margins(self.sys3);
def test_phase_crossover_frequencies(self):
omega, gain = phase_crossover_frequencies(self.sys2)
np.testing.assert_array_almost_equal(omega, [1.73205, 0.])
np.testing.assert_array_almost_equal(gain, [-0.5, 0.25])
tf = TransferFunction([1],[1,1])
omega, gain = phase_crossover_frequencies(tf)
np.testing.assert_array_almost_equal(omega, [0.])
np.testing.assert_array_almost_equal(gain, [1.])
# testing MIMO, only (0,0) element is considered
tf = TransferFunction([[[1],[2]],[[3],[4]]],
[[[1, 2, 3, 4],[1,1]],[[1,1],[1,1]]])
omega, gain = phase_crossover_frequencies(tf)
np.testing.assert_array_almost_equal(omega, [1.73205081, 0.])
np.testing.assert_array_almost_equal(gain, [-0.5, 0.25])
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestMargin)
if __name__ == "__main__":
unittest.main()