Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
round to nearest integer for default omega
  • Loading branch information
bnavigator committed Jan 4, 2022
commit 58d8cd6e4fe77fd5a18f91c791532e3e259b1949
16 changes: 7 additions & 9 deletions control/freqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
features_ = np.concatenate((np.abs(sys.pole()),
np.abs(sys.zero())))
# Get rid of poles and zeros at the origin
toreplace = features_ == 0.0
toreplace = np.isclose(features_, 0.0)
if np.any(toreplace):
features_ = features_[~toreplace]
elif sys.isdtime(strict=True):
Expand All @@ -1339,7 +1339,7 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,
# Get rid of poles and zeros on the real axis (imag==0)
# * origin and real < 0
# * at 1.: would result in omega=0. (logaritmic plot!)
toreplace = (features_.imag == 0.0) & (
toreplace = np.isclose(features_.imag, 0.0) & (
(features_.real <= 0.) |
(np.abs(features_.real - 1.0) < 1.e-10))
if np.any(toreplace):
Expand All @@ -1360,15 +1360,13 @@ def _default_frequency_range(syslist, Hz=None, number_of_samples=None,

if Hz:
features /= 2. * math.pi
features = np.log10(features)
lsp_min = np.floor(np.min(features) - feature_periphery_decades)
lsp_max = np.ceil(np.max(features) + feature_periphery_decades)
features = np.log10(features)
lsp_min = np.rint(np.min(features) - feature_periphery_decades)
lsp_max = np.rint(np.max(features) + feature_periphery_decades)
if Hz:
lsp_min += np.log10(2. * math.pi)
lsp_max += np.log10(2. * math.pi)
else:
features = np.log10(features)
lsp_min = np.floor(np.min(features) - feature_periphery_decades)
lsp_max = np.ceil(np.max(features) + feature_periphery_decades)

if freq_interesting:
lsp_min = min(lsp_min, np.log10(min(freq_interesting)))
lsp_max = max(lsp_max, np.log10(max(freq_interesting)))
Expand Down
4 changes: 2 additions & 2 deletions control/tests/sisotool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def test_sisotool(self, tsys):

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

Expand Down