Skip to content

Commit 33bebc1

Browse files
authored
Merge pull request #140 from rssalessio/master
Fix minreal not returning a discrete TF
2 parents f890a88 + 585c028 commit 33bebc1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

control/tests/xferfcn_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def testMinreal(self):
461461
hr = (s+1)/(s**2+s+1)
462462
np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0])
463463
np.testing.assert_array_almost_equal(hm.den[0][0], hr.den[0][0])
464+
np.testing.assert_equal(hm.dt, hr.dt)
464465

465466
def testMinreal2(self):
466467
"""This one gave a problem, due to poly([]) giving simply 1
@@ -474,12 +475,24 @@ def testMinreal2(self):
474475
hr = 6205/(s**2+8*s+1241)
475476
np.testing.assert_array_almost_equal(H2b.num[0][0], hr.num[0][0])
476477
np.testing.assert_array_almost_equal(H2b.den[0][0], hr.den[0][0])
478+
np.testing.assert_equal(H2b.dt, hr.dt)
477479

478480
def testMinreal3(self):
479481
"""Regression test for minreal of tf([1,1],[1,1])"""
480482
g = TransferFunction([1,1],[1,1]).minreal()
481483
np.testing.assert_array_almost_equal(1.0, g.num[0][0])
482484
np.testing.assert_array_almost_equal(1.0, g.den[0][0])
485+
np.testing.assert_equal(None, g.dt)
486+
487+
def testMinreal4(self):
488+
"""Check minreal on discrete TFs."""
489+
T = 0.01
490+
z = TransferFunction([1, 0], [1], T)
491+
h = (z-1.00000000001)*(z+1.0000000001)/((z**2-1))
492+
hm = h.minreal()
493+
hr = TransferFunction([1], [1], T)
494+
np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0])
495+
np.testing.assert_equal(hr.dt, hm.dt)
483496

484497
@unittest.skipIf(not slycot_check(), "slycot not installed")
485498
def testMIMO(self):

control/xferfcn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def minreal(self, tol=None):
652652
den[i][j] = np.atleast_1d(real(poly(poles)))
653653

654654
# end result
655-
return TransferFunction(num, den)
655+
return TransferFunction(num, den, self.dt)
656656

657657
def returnScipySignalLTI(self):
658658
"""Return a list of a list of scipy.signal.lti objects.

0 commit comments

Comments
 (0)