Skip to content

Commit df4ee82

Browse files
authored
Merge pull request #175 from rabraker/fix_damp
Add support for discrete time systems to lti/damp
2 parents 33bebc1 + ac9a134 commit df4ee82

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

control/lti.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ def issiso(self):
8686

8787
def damp(self):
8888
poles = self.pole()
89-
wn = absolute(poles)
90-
Z = -real(poles)/wn
89+
90+
if isdtime(self, strict=True):
91+
splane_poles = np.log(poles)/self.dt
92+
else:
93+
splane_poles = poles
94+
wn = absolute(splane_poles)
95+
Z = -real(splane_poles)/wn
9196
return wn, Z, poles
9297

9398
def dcgain(self):
@@ -280,6 +285,20 @@ def damp(sys, doprint=True):
280285
poles: array
281286
Pole locations
282287
288+
289+
Algorithm
290+
--------
291+
If the system is continuous,
292+
wn = abs(poles)
293+
Z = -real(poles)/poles.
294+
295+
If the system is discrete, the discrete poles are mapped to their
296+
equivalent location in the s-plane via
297+
s = log10(poles)/dt
298+
and
299+
wn = abs(s)
300+
Z = -real(s)/wn.
301+
283302
See Also
284303
--------
285304
pole

control/tests/lti_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from control.lti import *
66
from control.xferfcn import tf
7+
from control import c2d
78
import numpy as np
89

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

2021
def test_damp(self):
22+
# Test the continuous time case.
2123
zeta = 0.1
2224
wn = 42
2325
p = -wn * zeta + 1j * wn * np.sqrt(1 - zeta**2)
@@ -26,6 +28,15 @@ def test_damp(self):
2628
np.testing.assert_equal(sys.damp(), expected)
2729
np.testing.assert_equal(damp(sys), expected)
2830

31+
# Also test the discrete time case.
32+
dt = 0.001
33+
sys_dt = c2d(sys, dt, method='matched')
34+
p_zplane = np.exp(p*dt)
35+
expected_dt = ([wn, wn], [zeta, zeta],
36+
[p_zplane, p_zplane.conjugate()])
37+
np.testing.assert_almost_equal(sys_dt.damp(), expected_dt)
38+
np.testing.assert_almost_equal(damp(sys_dt), expected_dt)
39+
2940
def test_dcgain(self):
3041
sys = tf(84, [1, 2])
3142
np.testing.assert_equal(sys.dcgain(), 42)

0 commit comments

Comments
 (0)