@@ -209,7 +209,7 @@ def bode_plot(syslist, omega=None,
209209 syslist = (syslist ,)
210210
211211 omega , omega_range_given = _determine_omega_vector (
212- syslist , omega , omega_limits , omega_num )
212+ syslist , omega , omega_limits , omega_num , Hz = Hz )
213213
214214 if plot :
215215 # Set up the axes with labels so that multiple calls to
@@ -965,7 +965,7 @@ def gangof4_plot(P, C, omega=None, **kwargs):
965965 # Select a default range if none is provided
966966 # TODO: This needs to be made more intelligent
967967 if omega is None :
968- omega = _default_frequency_range ((P , C , S ))
968+ omega = _default_frequency_range ((P , C , S ), Hz = Hz )
969969
970970 # Set up the axes with labels so that multiple calls to
971971 # gangof4_plot will superimpose the data. See details in bode_plot.
@@ -1115,7 +1115,7 @@ def singular_values_plot(syslist, omega=None,
11151115 syslist = (syslist ,)
11161116
11171117 omega , omega_range_given = _determine_omega_vector (
1118- syslist , omega , omega_limits , omega_num )
1118+ syslist , omega , omega_limits , omega_num , Hz = Hz )
11191119
11201120 omega = np .atleast_1d (omega )
11211121
@@ -1210,7 +1210,8 @@ def singular_values_plot(syslist, omega=None,
12101210
12111211
12121212# 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 ):
12141215 """Determine the frequency range for a frequency-domain plot
12151216 according to a standard logic.
12161217
@@ -1236,6 +1237,10 @@ def _determine_omega_vector(syslist, omega_in, omega_limits, omega_num):
12361237 omega_num : int
12371238 Number of points to be used for the frequency
12381239 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.
12391244
12401245 Returns
12411246 -------
@@ -1253,7 +1258,8 @@ def _determine_omega_vector(syslist, omega_in, omega_limits, omega_num):
12531258 omega_range_given = False
12541259 # Select a default range if none is provided
12551260 omega_out = _default_frequency_range (syslist ,
1256- number_of_samples = omega_num )
1261+ number_of_samples = omega_num ,
1262+ Hz = Hz )
12571263 else :
12581264 omega_limits = np .asarray (omega_limits )
12591265 if len (omega_limits ) != 2 :
@@ -1280,7 +1286,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
12801286 ----------
12811287 syslist : list of LTI
12821288 List of linear input/output systems (single system is OK)
1283- Hz : bool
1289+ Hz : bool, optional
12841290 If True, the limits (first and last value) of the frequencies
12851291 are set to full decades in Hz so it fits plotting with logarithmic
12861292 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,
13261332 features_ = np .concatenate ((np .abs (sys .pole ()),
13271333 np .abs (sys .zero ())))
13281334 # Get rid of poles and zeros at the origin
1329- toreplace = features_ == 0.0
1335+ toreplace = np . isclose ( features_ , 0.0 )
13301336 if np .any (toreplace ):
13311337 features_ = features_ [~ toreplace ]
13321338 elif sys .isdtime (strict = True ):
@@ -1339,7 +1345,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
13391345 # Get rid of poles and zeros on the real axis (imag==0)
13401346 # * origin and real < 0
13411347 # * at 1.: would result in omega=0. (logaritmic plot!)
1342- toreplace = (features_ .imag == 0.0 ) & (
1348+ toreplace = np . isclose (features_ .imag , 0.0 ) & (
13431349 (features_ .real <= 0. ) |
13441350 (np .abs (features_ .real - 1.0 ) < 1.e-10 ))
13451351 if np .any (toreplace ):
@@ -1360,15 +1366,13 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
13601366
13611367 if Hz :
13621368 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 :
13661373 lsp_min += np .log10 (2. * math .pi )
13671374 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+
13721376 if freq_interesting :
13731377 lsp_min = min (lsp_min , np .log10 (min (freq_interesting )))
13741378 lsp_max = max (lsp_max , np .log10 (max (freq_interesting )))
0 commit comments