Skip to content

Commit b6769f6

Browse files
committed
Solve #862: bode_plot phase wrapping incorrect for multiple systems
1 parent c4d1764 commit b6769f6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

control/freqplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,18 @@ def bode_plot(syslist, omega=None,
276276
if initial_phase is None:
277277
# Start phase in the range 0 to -360 w/ initial phase = -180
278278
# If wrap_phase is true, use 0 instead (phase \in (-pi, pi])
279-
initial_phase = -math.pi if wrap_phase is not True else 0
279+
initial_phase_value = -math.pi if wrap_phase is not True else 0
280280
elif isinstance(initial_phase, (int, float)):
281281
# Allow the user to override the default calculation
282282
if deg:
283-
initial_phase = initial_phase/180. * math.pi
283+
initial_phase_value = initial_phase/180. * math.pi
284284
else:
285285
raise ValueError("initial_phase must be a number.")
286286

287287
# Shift the phase if needed
288-
if abs(phase[0] - initial_phase) > math.pi:
288+
if abs(phase[0] - initial_phase_value) > math.pi:
289289
phase -= 2*math.pi * \
290-
round((phase[0] - initial_phase) / (2*math.pi))
290+
round((phase[0] - initial_phase_value) / (2*math.pi))
291291

292292
# Phase wrapping
293293
if wrap_phase is False:

control/tests/freqresp_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ def test_phase_wrap(TF, wrap_phase, min_phase, max_phase):
375375
assert(max(phase) <= max_phase)
376376

377377

378+
def test_phase_wrap_multiple_systems():
379+
G = ctrl.zpk([],[1,1], gain=1)
380+
381+
mag, phase, omega = ctrl.bode(G)
382+
assert(np.min(phase) >= -2*np.pi)
383+
assert(np.max(phase) <= -1*np.pi)
384+
385+
mag, phase, omega = ctrl.bode((G,G))
386+
assert(np.min(phase) >= -2*np.pi)
387+
assert(np.max(phase) <= -1*np.pi)
388+
389+
378390
def test_freqresp_warn_infinite():
379391
"""Test evaluation warnings for transfer functions w/ pole at the origin"""
380392
sys_finite = ctrl.tf([1], [1, 0.01])

0 commit comments

Comments
 (0)