Skip to content

Commit 1fd68c7

Browse files
committed
changed named signal handling to occur in sys.sample methods. added unit tests.
1 parent 055ed39 commit 1fd68c7

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

control/dtime.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
4848
"""
4949

50-
from .namedio import isctime, _process_namedio_keywords
51-
from .iosys import ss
50+
from .namedio import isctime
5251
from .statesp import StateSpace
5352

5453
__all__ = ['sample_system', 'c2d']
@@ -93,10 +92,9 @@ def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):
9392
# Make sure we have a continuous time system
9493
if not isctime(sysc):
9594
raise ValueError("First argument must be continuous time system")
96-
name, inputs, outputs, states, _ = _process_namedio_keywords(defaults=sysc)
97-
return ss(sysc.sample(Ts,
98-
method=method, alpha=alpha, prewarp_frequency=prewarp_frequency),
99-
name=name, inputs=inputs, outputs=outputs, states=states)
95+
96+
return sysc.sample(Ts,
97+
method=method, alpha=alpha, prewarp_frequency=prewarp_frequency)
10098

10199

102100
def c2d(sysc, Ts, method='zoh', prewarp_frequency=None):

control/statesp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,14 +1347,17 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
13471347
if not self.isctime():
13481348
raise ValueError("System must be continuous time system")
13491349

1350-
sys = (self.A, self.B, self.C, self.D)
13511350
if (method == 'bilinear' or (method == 'gbt' and alpha == 0.5)) and \
13521351
prewarp_frequency is not None:
13531352
Twarp = 2 * np.tan(prewarp_frequency * Ts/2)/prewarp_frequency
13541353
else:
13551354
Twarp = Ts
1355+
sys = (self.A, self.B, self.C, self.D)
13561356
Ad, Bd, C, D, _ = cont2discrete(sys, Twarp, method, alpha)
1357-
return StateSpace(Ad, Bd, C, D, Ts)
1357+
# get and pass along same signal names
1358+
_, inputs, outputs, states, _ = _process_namedio_keywords(defaults=self)
1359+
return StateSpace(Ad, Bd, C, D, Ts,
1360+
inputs=inputs, outputs=outputs, states=states)
13581361

13591362
def dcgain(self, warn_infinite=False):
13601363
"""Return the zero-frequency gain

control/tests/discrete_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,16 @@ def test_discrete_bode(self, tsys):
446446
np.testing.assert_array_almost_equal(omega, omega_out)
447447
np.testing.assert_array_almost_equal(mag_out, np.absolute(H_z))
448448
np.testing.assert_array_almost_equal(phase_out, np.angle(H_z))
449+
450+
def test_signal_names(self, tsys):
451+
"test that signal names are preserved in conversion to discrete-time"
452+
ssc = StateSpace(tsys.siso_ss1c,
453+
inputs='u', outputs='y', states=['a', 'b', 'c'])
454+
ssd = ssc.sample(0.1)
455+
tfc = TransferFunction(tsys.siso_tf1c, inputs='u', outputs='y')
456+
tfd = tfc.sample(0.1)
457+
assert ssd.input_labels == ['u']
458+
assert ssd.state_labels == ['a', 'b', 'c']
459+
assert ssd.output_labels == ['y']
460+
assert tfd.input_labels == ['u']
461+
assert tfd.output_labels == ['y']

control/xferfcn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,10 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
11491149
else:
11501150
Twarp = Ts
11511151
numd, dend, _ = cont2discrete(sys, Twarp, method, alpha)
1152-
return TransferFunction(numd[0, :], dend, Ts)
1152+
# get and pass along same signal names
1153+
_, inputs, outputs, _, _ = _process_namedio_keywords(defaults=self)
1154+
return TransferFunction(numd[0, :], dend, Ts,
1155+
inputs=inputs, outputs=outputs)
11531156

11541157
def dcgain(self, warn_infinite=False):
11551158
"""Return the zero-frequency (or DC) gain

0 commit comments

Comments
 (0)