Skip to content

Commit aa243d2

Browse files
committed
Fix bode plot with Hz and multiple systems
Otherwise each subsequent system as plotted against a difference omega range
1 parent 90133e8 commit aa243d2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

control/freqplot.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,30 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
126126
omega = default_frequency_range(syslist)
127127

128128
# Get the magnitude and phase of the system
129-
mag_tmp, phase_tmp, omega = sys.freqresp(omega)
129+
mag_tmp, phase_tmp, omega_sys = sys.freqresp(omega)
130130
mag = np.atleast_1d(np.squeeze(mag_tmp))
131131
phase = np.atleast_1d(np.squeeze(phase_tmp))
132132
phase = unwrap(phase)
133-
if Hz: omega = omega/(2*sp.pi)
133+
if Hz:
134+
omega_plot = omega_sys/(2*sp.pi)
135+
else:
136+
omega_plot = omega_sys
134137
if dB: mag = 20*sp.log10(mag)
135138
if deg: phase = phase * 180 / sp.pi
136139

137140
mags.append(mag)
138141
phases.append(phase)
139-
omegas.append(omega)
142+
omegas.append(omega_sys)
140143
# Get the dimensions of the current axis, which we will divide up
141144
#! TODO: Not current implemented; just use subplot for now
142145

143146
if (Plot):
144147
# Magnitude plot
145148
plt.subplot(211);
146149
if dB:
147-
plt.semilogx(omega, mag, *args, **kwargs)
150+
plt.semilogx(omega_plot, mag, *args, **kwargs)
148151
else:
149-
plt.loglog(omega, mag, *args, **kwargs)
152+
plt.loglog(omega_plot, mag, *args, **kwargs)
150153
plt.hold(True);
151154

152155
# Add a grid to the plot + labeling
@@ -156,7 +159,7 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
156159

157160
# Phase plot
158161
plt.subplot(212);
159-
plt.semilogx(omega, phase, *args, **kwargs)
162+
plt.semilogx(omega_plot, phase, *args, **kwargs)
160163
plt.hold(True);
161164

162165
# Add a grid to the plot + labeling

0 commit comments

Comments
 (0)