@@ -210,23 +210,32 @@ def bandwidth(self, dbdrop=-3):
210210 def _bandwidth (self , dbdrop = - 3 ):
211211 # check if system is SISO and dbdrop is a negative scalar
212212 if (not self .issiso ()) and (dbdrop >= 0 ):
213- raise ValueError ("NOT sure what to raise #TODO " )
214-
213+ raise ValueError ("#TODO " )
214+
215
10000
+ # # # this will probabily fail if there is a resonant frequency larger than the bandwidth, the initial guess can be around that peak
216+ # G1 = ct.tf(0.1, [1, 0.1])
217+ # wn2 = 0.9
218+ # zeta2 = 0.001
219+ # G2 = ct.tf(wn2**2, [1, 2*zeta2*wn2, wn2**2])
220+ # ct.bandwidth(G1*G2)
221+ # import scipy
215222 # result = scipy.optimize.root(lambda w: np.abs(self(w*1j)) - np.abs(self.dcgain())*10**(dbdrop/20), x0=1)
216- # # this will probabily fail if there is a resonant frequency larger than the bandwidth, the initial guess can be around that peak
223+
224+ # if result.success:
225+ # return np.abs(result.x)[0]
217226
218227 # use bodeplot to identify the 0-crossing bracket
219228 from control .freqplot import _default_frequency_range
220229 omega = _default_frequency_range (self )
221230 mag , phase , omega = self .frequency_response (omega )
222231
223232 dcgain = self .dcgain ()
224- idx_out = np .nonzero (mag - dcgain * 10 ** (dbdrop / 20 ) < 0 )[0 ][0 ]
233+ idx_dropped = np .nonzero (mag - dcgain * 10 ** (dbdrop / 20 ) < 0 )[0 ][0 ]
225234
226235 # solve for the bandwidth, use scipy.optimize.root_scalar() to solve using bisection
227236 import scipy
228237 result = scipy .optimize .root_scalar (lambda w : np .abs (self (w * 1j )) - np .abs (dcgain )* 10 ** (dbdrop / 20 ),
229- bracket = [omega [idx_out - 1 ], omega [idx_out ]],
238+ bracket = [omega [idx_dropped - 1 ], omega [idx_dropped ]],
230239 method = 'bisect' )
231240
232241 # check solution
@@ -555,6 +564,13 @@ def bandwidth(sys, dbdrop=-3):
555564 >>> ct.bandwidth(G)
556565 0.9976
557566
567+ >>> G1 = ct.tf(0.1, [1, 0.1])
568+ >>> wn2 = 1
569+ >>> zeta2 = 0.001
570+ >>> G2 = ct.tf(wn2**2, [1, 2*zeta2*wn2, wn2**2])
571+ >>> ct.bandwidth(G1*G2)
572+ 0.1018
573+
558574 """
559575 return sys .bandwidth (dbdrop )
560576
0 commit comments