@@ -211,12 +211,13 @@ def _bandwidth(self, dbdrop=-3):
211
211
# check if system is SISO and dbdrop is a negative scalar
212
212
if not self .issiso ():
213
213
raise TypeError ("system should be a SISO system" )
214
-
215
- if not ( np .isscalar (dbdrop )) or dbdrop >= 0 :
214
+
215
+ if ( not np .isscalar (dbdrop )) or dbdrop >= 0 :
216
216
raise ValueError ("expecting dbdrop be a negative scalar in dB" )
217
217
218
218
dcgain = self .dcgain ()
219
219
if np .isinf (dcgain ):
220
+ # infinite dcgain, return np.nan
220
221
return np .nan
221
222
222
223
# use frequency range to identify the 0-crossing (dbdrop) bracket
@@ -226,14 +227,16 @@ def _bandwidth(self, dbdrop=-3):
226
227
idx_dropped = np .nonzero (mag - dcgain * 10 ** (dbdrop / 20 ) < 0 )[0 ]
227
228
228
229
if idx_dropped .shape [0 ] == 0 :
229
- # no frequency response is dbdrop below the dc gain.
230
+ # no frequency response is dbdrop below the dc gain, return np.inf
230
231
return np .inf
231
232
else :
232
- # solve for the bandwidth, use scipy.optimize.root_scalar() to solve using bisection
233
+ # solve for the bandwidth, use scipy.optimize.root_scalar() to
234
+ # solve using bisection
233
235
import scipy
234
- result = scipy .optimize .root_scalar (lambda w : np .abs (self (w * 1j )) - np .abs (dcgain )* 10 ** (dbdrop / 20 ),
235
- bracket = [omega [idx_dropped [0 ] - 1 ], omega [idx_dropped [0 ]]],
236
- method = 'bisect' )
236
+ result = scipy .optimize .root_scalar (
237
+ lambda w : np .abs (self (w * 1j )) - np .abs (dcgain )* 10 ** (dbdrop / 20 ),
238
+ bracket = [omega [idx_dropped [0 ] - 1 ], omega [idx_dropped [0 ]]],
239
+ method = 'bisect' )
237
240
238
241
# check solution
239
242
if result .converged :
@@ -552,16 +555,17 @@ def bandwidth(sys, dbdrop=-3):
552
555
Returns
553
556
-------
554
557
bandwidth : ndarray
555
- The first frequency (rad/time-unit) where the gain drops below dbdrop of the dc gain
556
- of the system, or nan if the system has infinite dc gain, inf if the gain does not drop for all frequency
558
+ The first frequency (rad/time-unit) where the gain drops below dbdrop
559
+ of the dc gain of the system, or nan if the system has infinite dc
560
+ gain, inf if the gain does not drop for all frequency
557
561
558
562
Raises
559
563
------
560
564
TypeError
561
565
if 'sys' is not an SISO LTI instance
562
566
ValueError
563
567
if 'dbdrop' is not a negative scalar
564
-
568
+
565
569
Example
566
570
-------
567
571
3793
>>> G = ct.tf([1], [1, 1])
0 commit comments