From d8d6b02a267e5e4c658353cacf85f05b29ce0c76 Mon Sep 17 00:00:00 2001 From: rssalessio Date: Sun, 26 Mar 2017 17:59:05 +0200 Subject: [PATCH 1/2] Fix minreal not returning a discrete TF --- control/xferfcn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/xferfcn.py b/control/xferfcn.py index 1559fa047..99c8b91d4 100644 --- a/control/xferfcn.py +++ b/control/xferfcn.py @@ -685,7 +685,7 @@ def minreal(self, tol=None): den[i][j] = np.atleast_1d(real(poly(poles))) # end result - return TransferFunction(num, den) + return TransferFunction(num, den, None if self.dt == None else self.dt) def returnScipySignalLTI(self): """Return a list of a list of scipy.signal.lti objects. From 585c0280a8a30c0eefe87e5e5ada3ca2d3724d25 Mon Sep 17 00:00:00 2001 From: rssalessio Date: Wed, 29 Mar 2017 23:24:57 +0200 Subject: [PATCH 2/2] change if to None. add tests --- control/tests/xferfcn_test.py | 13 +++++++++++++ control/xferfcn.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/control/tests/xferfcn_test.py b/control/tests/xferfcn_test.py index a6c9ae585..cb33a6190 100644 --- a/control/tests/xferfcn_test.py +++ b/control/tests/xferfcn_test.py @@ -461,6 +461,7 @@ def testMinreal(self): hr = (s+1)/(s**2+s+1) np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0]) np.testing.assert_array_almost_equal(hm.den[0][0], hr.den[0][0]) + np.testing.assert_equal(hm.dt, hr.dt) def testMinreal2(self): """This one gave a problem, due to poly([]) giving simply 1 @@ -474,12 +475,24 @@ def testMinreal2(self): hr = 6205/(s**2+8*s+1241) np.testing.assert_array_almost_equal(H2b.num[0][0], hr.num[0][0]) np.testing.assert_array_almost_equal(H2b.den[0][0], hr.den[0][0]) + np.testing.assert_equal(H2b.dt, hr.dt) def testMinreal3(self): """Regression test for minreal of tf([1,1],[1,1])""" g = TransferFunction([1,1],[1,1]).minreal() np.testing.assert_array_almost_equal(1.0, g.num[0][0]) np.testing.assert_array_almost_equal(1.0, g.den[0][0]) + np.testing.assert_equal(None, g.dt) + + def testMinreal4(self): + """Check minreal on discrete TFs.""" + T = 0.01 + z = TransferFunction([1, 0], [1], T) + h = (z-1.00000000001)*(z+1.0000000001)/((z**2-1)) + hm = h.minreal() + hr = TransferFunction([1], [1], T) + np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0]) + np.testing.assert_equal(hr.dt, hm.dt) @unittest.skipIf(not slycot_check(), "slycot not installed") def testMIMO(self): diff --git a/control/xferfcn.py b/control/xferfcn.py index 99c8b91d4..c22c27c4e 100644 --- a/control/xferfcn.py +++ b/control/xferfcn.py @@ -685,7 +685,7 @@ def minreal(self, tol=None): den[i][j] = np.atleast_1d(real(poly(poles))) # end result - return TransferFunction(num, den, None if self.dt == None else self.dt) + return TransferFunction(num, den, self.dt) def returnScipySignalLTI(self): """Return a list of a list of scipy.signal.lti objects.