Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70e912f

Browse files
committed
Implemented and passed nominal test
1 parent86ff95c commit70e912f

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 (notself.issiso())and (dbdrop>=0):
213-
raiseValueError("#TODO ")
212+
ifnotself.issiso():
213+
raiseTypeError("system should be a SISO system")
214+
215+
ifnot(np.isscalar(dbdrop))ordbdrop>=0:
216+
raiseValueError("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
importcontrolasct
88
fromcontrolimportc2d,tf,ss,tf2ss,NonlinearIOSystem
9-
fromcontrol.ltiimportLTI,evalfr,damp,dcgain,zeros,poles
9+
fromcontrol.ltiimportLTI,evalfr,damp,dcgain,zeros,poles,bandwidth
1010
fromcontrolimportcommon_timebase,isctime,isdtime,issiso,timebaseEqual
1111
fromcontrol.tests.conftestimportslycotonly
1212
fromcontrol.exceptionimportslycot_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+
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp