From dec1455c38a4d5324c5a0cbb8a4d96aa42fdf105 Mon Sep 17 00:00:00 2001 From: Sawyer Fuller Date: Sun, 9 Aug 2020 23:37:56 -0700 Subject: [PATCH 1/2] code fix and unit test --- control/tests/timeresp_test.py | 8 ++++++++ control/timeresp.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index 5549b2a88..93ac59e25 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -204,6 +204,14 @@ def test_impulse_response(self): np.testing.assert_array_almost_equal( yy, np.vstack((youttrue, np.zeros_like(youttrue))), decimal=4) + # discrete time + self.siso_tf1 + dt = 0.1 + sysdt = self.siso_tf1.sample(dt, 'impulse') + t = np.arange(0, 3, dt) + np.testing.assert_array_almost_equal(control.impulse_response(sys, t)[1], + control.impulse_response(sysdt, t)[1]) + def test_initial_response(self): # Test SISO system sys = self.siso_ss1 diff --git a/control/timeresp.py b/control/timeresp.py index 8670c180d..d6c31a89b 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -815,7 +815,7 @@ def impulse_response(sys, T=None, X0=0., input=0, output=None, T_num=None, new_X0 = B + X0 else: new_X0 = X0 - U[0] = 1. + U[0] = 1./sys.dt # unit area impulse T, yout, _xout = forced_response(sys, T, U, new_X0, transpose=transpose, squeeze=squeeze) From 0b85e3b13538257aab64b910ab4dace7a7146831 Mon Sep 17 00:00:00 2001 From: Sawyer Fuller Date: Mon, 10 Aug 2020 13:41:40 -0700 Subject: [PATCH 2/2] suggested fix to unit test --- control/tests/timeresp_test.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index 93ac59e25..39bc533bf 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -204,14 +204,15 @@ def test_impulse_response(self): np.testing.assert_array_almost_equal( yy, np.vstack((youttrue, np.zeros_like(youttrue))), decimal=4) - # discrete time - self.siso_tf1 + def test_discrete_time_impulse(self): + # discrete time impulse sampled version should match cont time dt = 0.1 - sysdt = self.siso_tf1.sample(dt, 'impulse') t = np.arange(0, 3, dt) - np.testing.assert_array_almost_equal(control.impulse_response(sys, t)[1], - control.impulse_response(sysdt, t)[1]) - + sys = self.siso_tf1 + sysdt = sys.sample(dt, 'impulse') + np.testing.assert_array_almost_equal(impulse_response(sys, t)[1], + impulse_response(sysdt, t)[1]) + def test_initial_response(self): # Test SISO system sys = self.siso_ss1 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy