@@ -210,23 +210,32 @@ def bandwidth(self, dbdrop=-3):
210
210
def _bandwidth (self , dbdrop = - 3 ):
211
211
# check if system is SISO and dbdrop is a negative scalar
212
212
if (not self .issiso ()) and (dbdrop >= 0 ):
213
- raise ValueError ("NOT sure what to raise #TODO " )
214
-
213
+ raise ValueError ("#TODO " )
214
+
215
+ # # # 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
215
222
# 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]
217
226
218
227
# use bodeplot to identify the 0-crossing bracket
219
228
from control .freqplot import _default_frequency_range
220
229
omega = _default_frequency_range (self )
221
230
mag , phase , omega = self .frequency_response (omega )
222
231
223
232
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 ]
225
234
226
235
# solve for the bandwidth, use scipy.optimize.root_scalar() to solve using bisection
227
236
import scipy
228
237
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 ]],
230
239
method = 'bisect' )
231
240
232
241
# check solution
@@ -555,6 +564,13 @@ def bandwidth(sys, dbdrop=-3):
555
564
>>> ct.bandwidth(G)
556
565
0.9976
557
566
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
+
558
574
"""
559
575
return sys .bandwidth (dbdrop )
560
576
0 commit comments