Skip to content

Commit 20ba841

Browse files
Allan McInnesAllan McInnes
authored andcommitted
Bugfix freqplot.default_frequency_range(), which failed to deal properly with single systems. Also add an option to control the number of points. Set default to a larger number of points than the logspace default, so that we're more likely to get a smooth curve on bode, nyquist, and nichols plots.
1 parent 41f8220 commit 20ba841

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/freqplot.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ def nyquist_grid(cl_mags=None, cl_phases=None):
192192
193193
Parameters
194194
----------
195-
cl_mags : array-like (dB)
195+
cl_mags : array-like (dB), optional
196196
Array of closed-loop magnitudes defining a custom set of
197197
M-circle iso-gain lines.
198-
cl_phases : array-like (degrees)
198+
cl_phases : array-like (degrees), optional
199199
Array of closed-loop phases defining a custom set of
200200
N-circle iso-phase lines. Must be in the range -180.0 < cl_phases < 180.0
201201
@@ -273,8 +273,8 @@ def nichols(syslist, omega=None, grid=True):
273273
List of linear input/output systems (single system is OK)
274274
omega : freq_range
275275
Range of frequencies (list or bounds) in rad/sec
276-
grid : boolean
277-
True if the plot should include a Nichols-chart grid
276+
grid : boolean, optional
277+
True if the plot should include a Nichols-chart grid. Default is True.
278278
279279
Return values
280280
-------------
@@ -326,10 +326,10 @@ def nichols_grid(cl_mags=None, cl_phases=None):
326326
327327
Parameters
328328
----------
329-
cl_mags : array-like (dB)
329+
cl_mags : array-like (dB), optional
330330
Array of closed-loop magnitudes defining the iso-gain lines on a
331331
custom Nichols chart.
332-
cl_phases : array-like (degrees)
332+
cl_phases : array-like (degrees), optional
333333
Array of closed-loop phases defining the iso-phase lines on a custom
334334
Nichols chart. Must be in the range -360 < cl_phases < 0
335335
@@ -468,7 +468,7 @@ def gangof4(P, C, omega=None):
468468
#
469469

470470
# Compute reasonable defaults for axes
471-
def default_frequency_range(syslist):
471+
def default_frequency_range(syslist, num=1000):
472472
"""Compute a reasonable default frequency range for frequency
473473
domain plots.
474474
@@ -483,6 +483,8 @@ def default_frequency_range(syslist):
483483
----------
484484
syslist : linsys
485485
List of linear input/output systems (single system is OK)
486+
num : integer, optional
487+
Number of samples to generate. Default is 50.
486488
487489
Return values
488490
-------------
@@ -495,6 +497,10 @@ def default_frequency_range(syslist):
495497
# integer. It excludes poles and zeros at the origin. If no features
496498
# are found, it turns logspace(-1, 1)
497499

500+
# If argument was a singleton, turn it into a list
501+
if (not getattr(syslist, '__iter__', False)):
502+
syslist = (syslist,)
503+
498504
# Find the list of all poles and zeros in the systems
499505
features = np.array(())
500506
for sys in syslist:
@@ -513,7 +519,7 @@ def default_frequency_range(syslist):
513519

514520
# Set the range to be an order of magnitude beyond any features
515521
omega = sp.logspace(np.floor(np.min(features))-1,
516-
np.ceil(np.max(features))+1)
522+
np.ceil(np.max(features))+1, num)
517523

518524
return omega
519525

0 commit comments

Comments
 (0)