|
6 | 6 |
|
7 | 7 | import control as ct
|
8 | 8 | from control import c2d, tf, ss, tf2ss, NonlinearIOSystem
|
9 |
| -from control.lti import LTI, evalfr, damp, dcgain, zeros, poles |
| 9 | +from control.lti import LTI, evalfr, damp, dcgain, zeros, poles, bandwidth |
10 | 10 | from control import common_timebase, isctime, isdtime, issiso, timebaseEqual
|
11 | 11 | from control.tests.conftest import slycotonly
|
12 | 12 | from control.exception import slycot_check
|
@@ -104,6 +104,27 @@ def test_dcgain(self):
|
104 | 104 | np.testing.assert_allclose(sys.dcgain(), 42)
|
105 | 105 | np.testing.assert_allclose(dcgain(sys), 42)
|
106 | 106 |
|
| 107 | + def test_bandwidth(self): |
| 108 | + # test a first-order system, compared with matlab |
| 109 | + sys1 = tf(0.1, [1, 0.1]) |
| 110 | + np.testing.assert_allclose(sys1.bandwidth(), 0.099762834511098) |
| 111 | + np.testing.assert_allclose(bandwidth(sys1), 0.099762834511098) |
| 112 | + |
| 113 | + # test a second-order system, compared with matlab |
| 114 | + wn2 = 1 |
| 115 | + zeta2 = 0.001 |
| 116 | + sys2 = sys1 * tf(wn2**2, [1, 2*zeta2*wn2, wn2**2]) |
| 117 | + np.testing.assert_allclose(sys2.bandwidth(), 0.101848388240241) |
| 118 | + np.testing.assert_allclose(bandwidth(sys2), 0.101848388240241) |
| 119 | + |
| 120 | + # test if raise exception given other than SISO system |
| 121 | + sysMIMO = tf([[[-1, 41], [1]], [[1, 2], [3, 4]]], |
| 122 | + [[[1, 10], [1, 20]], [[1, 30], [1, 40]]]) |
| 123 | + np.testing.assert_raises(TypeError, bandwidth, sysMIMO) |
| 124 | + |
| 125 | + # test if raise exception if dbdrop is positive scalar |
| 126 | + np.testing.assert_raises(ValueError, bandwidth, sys1, 3) |
| 127 | + |
107 | 128 | @pytest.mark.parametrize("dt1, dt2, expected",
|
108 | 129 | [(None, None, True),
|
109 | 130 | (None, 0, True),
|
|
0 commit comments