Skip to content
Merged
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
initial commit that performs indents in the z-plane
  • Loading branch information
sawyerbfuller committed Nov 5, 2021
commit aa92e434ca3fcb26ce98793b3bb30621f491e958
38 changes: 22 additions & 16 deletions control/freqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,41 +714,47 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
if np.any(omega_sys * sys.dt > np.pi) and warn_nyquist:
warnings.warn("evaluation above Nyquist frequency")

# Transform frequencies to continuous domain
contour = np.exp(1j * omega * sys.dt)
else:
contour = 1j * omega_sys
# do indentations in s-plane where it is more convenient
splane_contour = 1j * omega_sys

# Bend the contour around any poles on/near the imaginary axis
if isinstance(sys, (StateSpace, TransferFunction)) \
and sys.isctime() and indent_direction != 'none':
poles = sys.pole()
if contour[1].imag > indent_radius \
and 0. in poles and not omega_range_given:
and indent_direction != 'none':
if sys.isctime():
splane_poles = sys.pole()
else:
# map z-plane poles to s-plane
splane_poles = np.log(sys.pole())/sys.dt

if splane_contour[1].imag > indent_radius \
and 0. in splane_poles and not omega_range_given:
# add some points for quarter circle around poles at origin
contour = np.concatenate(
splane_contour = np.concatenate(
(1j * np.linspace(0., indent_radius, 50),
contour[1:]))
for i, s in enumerate(contour):
splane_contour[1:]))
for i, s in enumerate(splane_contour):
# Find the nearest pole
p = poles[(np.abs(poles - s)).argmin()]

p = splane_poles[(np.abs(splane_poles - s)).argmin()]
# See if we need to indent around it
if abs(s - p) < indent_radius:
if p.real < 0 or \
(p.real == 0 and indent_direction == 'right'):
# Indent to the right
contour[i] += \
splane_contour[i] += \
np.sqrt(indent_radius ** 2 - (s-p).imag ** 2)
elif p.real > 0 or \
(p.real == 0 and indent_direction == 'left'):
# Indent to the left
contour[i] -= \
splane_contour[i] -= \
np.sqrt(indent_radius ** 2 - (s-p).imag ** 2)
else:
ValueError("unknown value for indent_direction")

# TODO: add code to indent around discrete poles on unit circle
# change contour to z-plane if necessary
if sys.isctime():
contour = splane_contour
else:
contour = np.exp(splane_contour * sys.dt)

# Compute the primary curve
resp = sys(contour)
Expand Down