@@ -209,7 +209,7 @@ def bode_plot(syslist, omega=None,
209
209
syslist = (syslist ,)
210
210
211
211
omega , omega_range_given = _determine_omega_vector (
212
- syslist , omega , omega_limits , omega_num )
212
+ syslist , omega , omega_limits , omega_num , Hz = Hz )
213
213
214
214
if plot :
215
215
# Set up the axes with labels so that multiple calls to
@@ -965,7 +965,7 @@ def gangof4_plot(P, C, omega=None, **kwargs):
965
965
# Select a default range if none is provided
966
966
# TODO: This needs to be made more intelligent
967
967
if omega is None :
968
- omega = _default_frequency_range ((P , C , S ))
968
+ omega = _default_frequency_range ((P , C , S ), Hz = Hz )
969
969
970
970
# Set up the axes with labels so that multiple calls to
971
971
# gangof4_plot will superimpose the data. See details in bode_plot.
@@ -1115,7 +1115,7 @@ def singular_values_plot(syslist, omega=None,
1115
1115
syslist = (syslist ,)
1116
1116
1117
1117
omega , omega_range_given = _determine_omega_vector (
1118
- syslist , omega , omega_limits , omega_num )
1118
+ syslist , omega , omega_limits , omega_num , Hz = Hz )
1119
1119
1120
1120
omega = np .atleast_1d (omega )
1121
1121
@@ -1210,7 +1210,8 @@ def singular_values_plot(syslist, omega=None,
1210
1210
1211
1211
1212
1212
# Determine the frequency range to be used
1213
- def _determine_omega_vector (syslist , omega_in , omega_limits , omega_num ):
1213
+ def _determine_omega_vector (syslist , omega_in , omega_limits , omega_num ,
1214
+ Hz = None ):
1214
1215
"""Determine the frequency range for a frequency-domain plot
1215
1216
according to a standard logic.
1216
1217
@@ -1236,6 +1237,10 @@ def _determine_omega_vector(syslist, omega_in, omega_limits, omega_num):
1236
1237
omega_num : int
1237
1238
Number of points to be used for the frequency
1238
1239
range (if the frequency range is not user-specified)
1240
+ Hz : bool, optional
1241
+ If True, the limits (first and last value) of the frequencies
1242
+ are set to full decades in Hz so it fits plotting with logarithmic
1243
+ scale in Hz otherwise in rad/s. Omega is always returned in rad/sec.
1239
1244
1240
1245
Returns
1241
1246
-------
@@ -1253,7 +1258,8 @@ def _determine_omega_vector(syslist, omega_in, omega_limits, omega_num):
1253
1258
omega_range_given = False
1254
1259
# Select a default range if none is provided
1255
1260
omega_out = _default_frequency_range (syslist ,
1256
- number_of_samples = omega_num )
1261
+ number_of_samples = omega_num ,
1262
+ Hz = Hz )
1257
1263
else :
1258
1264
omega_limits = np .asarray (omega_limits )
1259
1265
if len (omega_limits ) != 2 :
@@ -1280,7 +1286,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
1280
1286
----------
1281
1287
syslist : list of LTI
1282
1288
List of linear input/output systems (single system is OK)
1283
- Hz : bool
1289
+ Hz : bool, optional
1284
1290
If True, the limits (first and last value) of the frequencies
1285
1291
are set to full decades in Hz so it fits plotting with logarithmic
1286
1292
scale in Hz otherwise in rad/s. Omega is always returned in rad/sec.
@@ -1326,7 +1332,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
1326
1332
features_ = np .concatenate ((np .abs (sys .pole ()),
1327
1333
np .abs (sys .zero ())))
1328
1334
# Get rid of poles and zeros at the origin
1329
- toreplace = features_ == 0.0
1335
+ toreplace = np . isclose ( features_ , 0.0 )
1330
1336
if np .any (toreplace ):
1331
1337
features_ = features_ [~ toreplace ]
1332
1338
elif sys .isdtime (strict = True ):
@@ -1339,7 +1345,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
1339
1345
# Get rid of poles and zeros on the real axis (imag==0)
1340
1346
# * origin and real < 0
1341
1347
# * at 1.: would result in omega=0. (logaritmic plot!)
1342
- toreplace = (features_ .imag == 0.0 ) & (
1348
+ toreplace = np . isclose (features_ .imag , 0.0 ) & (
1343
1349
(features_ .real <= 0. ) |
1344
1350
(np .abs (features_ .real - 1.0 ) < 1.e-10 ))
1345
1351
if np .any (toreplace ):
@@ -1360,15 +1366,13 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
1360
1366
1361
1367
if Hz :
1362
1368
features /= 2. * math .pi
1363
- features = np .log10 (features )
1364
- lsp_min = np .floor (np .min (features ) - feature_periphery_decades )
1365
- lsp_max = np .ceil (np .max (features ) + feature_periphery_decades )
1369
+ features = np .log10 (features )
1370
+ lsp_min = np .rint (np .min (features ) - feature_periphery_decades )
1371
+ lsp_max = np .rint (np .max (features ) + feature_periphery_decades )
1372
+ if Hz :
1366
1373
lsp_min += np .log10 (2. * math .pi )
1367
1374
lsp_max += np .log10 (2. * math .pi )
1368
- else :
1369
- features = np .log10 (features )
1370
- lsp_min = np .floor (np .min (features ) - feature_periphery_decades )
1371
- lsp_max = np .ceil (np .max (features ) + feature_periphery_decades )
1375
+
1372
1376
if freq_interesting :
1373
1377
lsp_min = min (lsp_min , np .log10 (min (freq_interesting )))
1374
1378
lsp_max = max (lsp_max , np .log10 (max (freq_interesting )))
0 commit comments