Skip to content

Add support for discrete systems to lti/damp #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 21 additions & 2 deletions control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ def issiso(self):

def damp(self):
poles = self.pole()
wn = absolute(poles)
Z = -real(poles)/wn

if isdtime(self, strict=True):
splane_poles = np.log(poles)/self.dt
else:
splane_poles = poles
wn = absolute(splane_poles)
Z = -real(splane_poles)/wn
return wn, Z, poles

def dcgain(self):
Expand Down Expand Up @@ -280,6 +285,20 @@ def damp(sys, doprint=True):
poles: array
Pole locations


Algorithm
--------
If the system is continuous,
wn = abs(poles)
Z = -real(poles)/poles.

If the system is discrete, the discrete poles are mapped to their
equivalent location in the s-plane via
s = log10(poles)/dt
and
wn = abs(s)
Z = -real(s)/wn.

See Also
--------
pole
Expand Down
11 changes: 11 additions & 0 deletions control/tests/lti_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from control.lti import *
from control.xferfcn import tf
from control import c2d
import numpy as np

class TestUtils(unittest.TestCase):
Expand All @@ -18,6 +19,7 @@ def test_zero(self):
np.testing.assert_equal(zero(sys), 42)

def test_damp(self):
# Test the continuous time case.
zeta = 0.1
wn = 42
p = -wn * zeta + 1j * wn * np.sqrt(1 - zeta**2)
Expand All @@ -26,6 +28,15 @@ def test_damp(self):
np.testing.assert_equal(sys.damp(), expected)
np.testing.assert_equal(damp(sys), expected)

# Also test the discrete time case.
dt = 0.001
sys_dt = c2d(sys, dt, method='matched')
p_zplane = np.exp(p*dt)
expected_dt = ([wn, wn], [zeta, zeta],
[p_zplane, p_zplane.conjugate()])
np.testing.assert_almost_equal(sys_dt.damp(), expected_dt)
np.testing.assert_almost_equal(damp(sys_dt), expected_dt)

def test_dcgain(self):
sys = tf(84, [1, 2])
np.testing.assert_equal(sys.dcgain(), 42)
Expand Down