8000 Implemented and passed nominal test · python-control/python-control@723ddc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 723ddc8

Browse files
committed
Implemented and passed nominal test
1 parent 409d0c6 commit 723ddc8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

control/lti.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,11 @@ def bandwidth(self, dbdrop=-3):
209209

210210
def _bandwidth(self, dbdrop=-3):
211211
# check if system is SISO and dbdrop is a negative scalar
212-
if (not self.issiso()) and (dbdrop >= 0):
213-
raise ValueError("#TODO ")
212+
if not self.issiso():
213+
raise TypeError("system should be a SISO system")
214+
215+
if not(np.isscalar(dbdrop)) or dbdrop >= 0:
216+
raise ValueError("expecting dbdrop be a negative scalar in dB")
214217

215218
# # # this will probabily fail if there is a resonant frequency larger than the bandwidth, the initial guess can be around that peak
216219
# G1 = ct.tf(0.1, [1, 0.1])
@@ -560,7 +563,7 @@ def bandwidth(sys, dbdrop=-3):
560563
561564
Example
562565
-------
563-
>>> G = ct.tf([1], [1, 2])
566+
>>> G = ct.tf([1], [1, 1])
564567
>>> ct.bandwidth(G)
565568
0.9976
566569

control/tests/lti_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import control as ct
88
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
1010
from control import common_timebase, isctime, isdtime, issiso, timebaseEqual
1111
from control.tests.conftest import slycotonly
1212
from control.exception import slycot_check
@@ -104,6 +104,27 @@ def test_dcgain(self):
104104
np.testing.assert_allclose(sys.dcgain(), 42)
105105
np.testing.assert_allclose(dcgain(sys), 42)
106106

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+
107128
@pytest.mark.parametrize("dt1, dt2, expected",
108129
[(None, None, True),
109130
(None, 0, True),

0 commit comments

Comments
 (0)
0