Skip to content

Commit 4418e55

Browse files
committed
left an error in the _mimo2simo trimming routine, now fixed.
Added tests to test this to timeresp_test.py
1 parent 4de4c0e commit 4418e55

3 files changed

Lines changed: 40 additions & 20 deletions

File tree

src/statesp.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,13 @@ def _mimo2siso(sys, input, output, warn_conversion=False):
818818
def _mimo2simo(sys, input, warn_conversion=False):
819819
#pylint: disable=W0622
820820
"""
821-
Convert a MIMO system to a SISO system. (Convert a system with multiple
822-
inputs and/or outputs, to a system with a single input and output.)
821+
Convert a MIMO system to a SIMO system. (Convert a system with multiple
822+
inputs and/or outputs, to a system with a single input but possibly
823+
multiple outputs.)
823824
824-
The input and output that are used in the SISO system can be selected
825-
with the parameters ``input`` and ``output``. All other inputs are set
826-
to 0, all other outputs are ignored.
825+
The input that is used in the SIMO system can be selected with the
826+
parameter ``input``. All other inputs are set to 0, all other
827+
outputs are ignored.
827828
828829
If ``sys`` is already a SIMO system, it will be returned unaltered.
829830
@@ -832,13 +833,13 @@ def _mimo2simo(sys, input, warn_conversion=False):
832833
sys: StateSpace
833834
Linear (MIMO) system that should be converted.
834835
input: int
835-
Index of the input that will become the SISO system's only input.
836+
Index of the input that will become the SIMO system's only input.
836837
warn_conversion: bool
837838
If True: print a warning message when sys is a MIMO system.
838839
Warn that a conversion will take place.
839840
840841
Returns:
841-
842+
--------
842843
sys: StateSpace
843844
The converted (SIMO) system.
844845
"""
@@ -852,9 +853,9 @@ def _mimo2simo(sys, input, warn_conversion=False):
852853
#Convert sys to SISO if necessary
853854
if sys.inputs > 1:
854855
if warn_conversion:
855-
warnings.warn("Converting MIMO system to SISO system. "
856-
"Only input {i} and output {o} are used."
857-
.format(i=input, o=output))
856+
warnings.warn("Converting MIMO system to SIMO system. "
857+
"Only input {i} is used."
858+
.format(i=input))
858859
# $X = A*X + B*U
859860
# Y = C*X + D*U
860861
new_B = sys.B[:, input]

src/timeresp.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ def f_dot(x, t):
386386

387387
return T, yout, xout
388388

389-
def step_response(sys, T=None, X0=0., input=0, output=None, \
390-
transpose = False, **keywords):
389+
def step_response(sys, T=None, X0=0., input=0, output=None,
390+
transpose = False, **keywords):
391391
#pylint: disable=W0622
392392
"""Step response of a linear system
393393
@@ -468,8 +468,8 @@ def step_response(sys, T=None, X0=0., input=0, output=None, \
468468
return T, yout
469469

470470

471-
def initial_response(sys, T=None, X0=0., input=0, output=0, transpose=False,
472-
**keywords):
471+
def initial_response(sys, T=None, X0=0., input=0, output=None, transpose=False,
472+
**keywords):
473473
#pylint: disable=W0622
474474
"""Initial condition response of a linear system
475475
@@ -498,7 +498,8 @@ def initial_response(sys, T=None, X0=0., input=0, output=0, transpose=False,
498498
Index of the input that will be used in this simulation.
499499
500500
output: int
501-
Index of the output that will be used in this simulation.
501+
Index of the output that will be used in this simulation. Set to None
502+
to not trim outputs
502503
503504
transpose: bool
504505
If True, transpose all input and output arrays (for backward
@@ -529,7 +530,10 @@ def initial_response(sys, T=None, X0=0., input=0, output=0, transpose=False,
529530
>>> T, yout = initial_response(sys, T, X0)
530531
"""
531532
sys = _convertToStateSpace(sys)
532-
sys = _mimo2siso(sys, input, output, warn_conversion=True)
533+
if output == None:
534+
sys = _mimo2simo(sys, input, warn_conversion=False)
535+
else:
536+
sys = _mimo2siso(sys, input, output, warn_conversion=False)
533537

534538
# Create time and input vectors; checking is done in forced_response(...)
535539
# The initial vector X0 is created in forced_response(...) if necessary
@@ -538,11 +542,11 @@ def initial_response(sys, T=None, X0=0., input=0, output=0, transpose=False,
538542
U = np.zeros_like(T)
539543

540544
T, yout, _xout = forced_response(sys, T, U, X0, transpose=transpose,
541-
**keywords)
545+
**keywords)
542546
return T, yout
543547

544548

545-
def impulse_response(sys, T=None, X0=0., input=0, output=0,
549+
def impulse_response(sys, T=None, X0=0., input=0, output=None,
546550
transpose=False, **keywords):
547551
#pylint: disable=W0622
548552
"""Impulse response of a linear system
@@ -572,7 +576,8 @@ def impulse_response(sys, T=None, X0=0., input=0, output=0,
572576
Index of the input that will be used in this simulation.
573577
574578
output: int
575-
Index of the output that will be used in this simulation.
579+
Index of the output that will be used in this simulation. Set to None
580+
to not trim outputs
576581
577582
transpose: bool
578583
If True, transpose all input and output arrays (for backward
@@ -603,7 +608,10 @@ def impulse_response(sys, T=None, X0=0., input=0, output=0,
603608
>>> T, yout = impulse_response(sys, T, X0)
604609
"""
605610
sys = _convertToStateSpace(sys)
606-
sys = _mimo2siso(sys, input, output, warn_conversion=True)
611+
if output == None:
612+
sys = _mimo2simo(sys, input, warn_conversion=True)
613+
else:
614+
sys = _mimo2siso(sys, input, output, warn_conversion=True)
607615

608616
# System has direct feedthrough, can't simulate impulse response numerically
609617
if np.any(sys.D != 0) and isctime(sys):

tests/timeresp_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def test_impulse_response(self):
8989
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
9090
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)
9191

92+
#Test MIMO system, as mimo, and don't trim outputs
93+
sys = self.mimo_ss1
94+
_t, yy = impulse_response(sys, T=t, input=0)
95+
np.testing.assert_array_almost_equal(
96+
yy, np.vstack((youttrue, np.zeros_like(youttrue))), decimal=4)
97+
9298
def test_initial_response(self):
9399
#Test SISO system
94100
sys = self.siso_ss1
@@ -107,6 +113,11 @@ def test_initial_response(self):
107113
_t, y_11 = initial_response(sys, T=t, X0=x0, input=1, output=1)
108114
np.testing.assert_array_almost_equal(y_00, youttrue, decimal=4)
109115
np.testing.assert_array_almost_equal(y_11, youttrue, decimal=4)
116+
117+
# test MIMO system without trimming
118+
_t, yy = initial_response(sys, T=t, X0=x0)
119+
np.testing.assert_array_almost_equal(yy, np.vstack((y_00, y_11)),
120+
decimal=4)
110121

111122
def test_forced_response(self):
112123
t = np.linspace(0, 1, 10)

0 commit comments

Comments
 (0)