10000 Merge pull request #143 from murrayrm/timeresp-discrete-retval-fix · python-control/python-control@e3c0f79 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3c0f79

Browse files
authored
Merge pull request #143 from murrayrm/timeresp-discrete-retval-fix
Make output response matrices consistent between continuous and discrete time
2 parents 6ada795 + 1adfaf0 commit e3c0f79

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

control/tests/timeresp_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from control.timeresp import *
1515
from control.statesp import *
1616
from control.xferfcn import TransferFunction, _convertToTransferFunction
17-
17+
from control.dtime import c2d
1818

1919
class TestTimeresp(unittest.TestCase):
2020
def setUp(self):
@@ -77,6 +77,15 @@ def test_step_response(self):
7777
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
7878
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)
7979

80+
# Make sure continuous and discrete time use same return conventions
81+
sysc = self.mimo_ss1
82+
sysd = c2d(sysc, 1) # discrete time system
83+
Tvec = np.linspace(0, 10, 11) # make sure to use integer times 0..10
84+
Tc, youtc = step_response(sysc, Tvec, input=0)
85+
Td, youtd = step_response(sysd, Tvec, input=0)
86+
np.testing.assert_array_equal(Tc.shape, Td.shape)
87+
np.testing.assert_array_equal(youtc.shape, youtd.shape)
88+
8089
def test_impulse_response(self):
8190
# Test SISO system
8291
sys = self.siso_ss1

control/timeresp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False):
324324
dsys = (A, B, C, D, sys.dt)
325325
tout, yout, xout = sp.signal.dlsim(dsys, U, T, X0)
326326

327+
# Transpose the output and state vectors to match local convention
328+
xout = sp.transpose(xout)
329+
yout = sp.transpose(yout)
330+
327331
# See if we need to transpose the data back into MATLAB form
328332
if (transpose):
329333
T = np.transpose(T)

0 commit comments

Comments
 (0)
0