Skip to content

Commit 58d8cd6

Browse files
committed
round to nearest integer for default omega
1 parent a111b03 commit 58d8cd6

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

control/freqplot.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
13261326
features_ = np.concatenate((np.abs(sys.pole()),
13271327
np.abs(sys.zero())))
13281328
# Get rid of poles and zeros at the origin
1329-
toreplace = features_ == 0.0
1329+
toreplace = np.isclose(features_, 0.0)
13301330
if np.any(toreplace):
13311331
features_ = features_[~toreplace]
13321332
elif sys.isdtime(strict=True):
@@ -1339,7 +1339,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
13391339
# Get rid of poles and zeros on the real axis (imag==0)
13401340
# * origin and real < 0
13411341
# * at 1.: would result in omega=0. (logaritmic plot!)
1342-
toreplace = (features_.imag == 0.0) & (
1342+
toreplace = np.isclose(features_.imag, 0.0) & (
13431343
(features_.real <= 0.) |
13441344
(np.abs(features_.real - 1.0) < 1.e-10))
13451345
if np.any(toreplace):
@@ -1360,15 +1360,13 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
13601360

13611361
if Hz:
13621362
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)
1363+
features = np.log10(features)
1364+
lsp_min = np.rint(np.min(features) - feature_periphery_decades)
1365+
lsp_max = np.rint(np.max(features) + feature_periphery_decades)
1366+
if Hz:
13661367
lsp_min += np.log10(2. * math.pi)
13671368
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)
1369+
13721370
if freq_interesting:
13731371
lsp_min = min(lsp_min, np.log10(min(freq_interesting)))
13741372
lsp_max = max(lsp_max, np.log10(max(freq_interesting)))

control/tests/sisotool_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def test_sisotool(self, tsys):
102102

103103
# Check if the bode_mag line has moved
104104
bode_mag_moved = np.array(
105-
[674.0242, 667.8354, 661.7033, 655.6275, 649.6074, 643.6426,
106-
637.7324, 631.8765, 626.0742, 620.3252])
105+
[69.0065, 68.6749, 68.3448, 68.0161, 67.6889, 67.3631, 67.0388,
106+
66.7159, 66.3944, 66.0743])
107107
assert_array_almost_equal(ax_mag.lines[0].get_data()[1][10:20],
108108
bode_mag_moved, 4)
109109

0 commit comments

Comments
 (0)