Skip to content

Commit

Permalink
Merge pull request #143 from murrayrm/timeresp-discrete-retval-fix
Browse files Browse the repository at this point in the history
Make output response matrices consistent between continuous and discrete time
  • Loading branch information
murrayrm committed Apr 21, 2017
2 parents 6ada795 + 1adfaf0 commit e3c0f79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion control/tests/timeresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from control.timeresp import *
from control.statesp import *
from control.xferfcn import TransferFunction, _convertToTransferFunction

from control.dtime import c2d

class TestTimeresp(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -77,6 +77,15 @@ def test_step_response(self):
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)

# Make sure continuous and discrete time use same return conventions
sysc = self.mimo_ss1
sysd = c2d(sysc, 1) # discrete time system
Tvec = np.linspace(0, 10, 11) # make sure to use integer times 0..10
Tc, youtc = step_response(sysc, Tvec, input=0)
Td, youtd = step_response(sysd, Tvec, input=0)
np.testing.assert_array_equal(Tc.shape, Td.shape)
np.testing.assert_array_equal(youtc.shape, youtd.shape)

def test_impulse_response(self):
# Test SISO system
sys = self.siso_ss1
Expand Down
4 changes: 4 additions & 0 deletions control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False):
dsys = (A, B, C, D, sys.dt)
tout, yout, xout = sp.signal.dlsim(dsys, U, T, X0)

# Transpose the output and state vectors to match local convention
xout = sp.transpose(xout)
yout = sp.transpose(yout)

# See if we need to transpose the data back into MATLAB form
if (transpose):
T = np.transpose(T)
Expand Down

0 comments on commit e3c0f79

Please sign in to comment.