Skip to content

Make output response matrices consistent between continuous and discrete time #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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