Skip to content

Commit 4c66fb1

Browse files
committed
test prewarp in c2d and sample_system
1 parent cfb6e86 commit 4c66fb1

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

control/dtime.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Routines in this module:
66
77
sample_system()
8+
c2d()
89
"""
910

1011
"""Copyright (c) 2012 by California Institute of Technology
@@ -58,16 +59,19 @@ def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):
5859
5960
Parameters
6061
----------
61-
sysc : LTI (StateSpace or TransferFunction)
62+
sysc : LTI (:class:`StateSpace` or :class:`TransferFunction`)
6263
Continuous time system to be converted
63-
Ts : real > 0
64+
Ts : float > 0
6465
Sampling period
6566
method : string
6667
Method to use for conversion, e.g. 'bilinear', 'zoh' (default)
67-
68-
prewarp_frequency : real within [0, infinity)
68+
alpha : float within [0, 1]
69+
The generalized bilinear transformation weighting parameter, which
70+
should only be specified with method="gbt", and is ignored
71+
otherwise. See :func:`scipy.signal.cont2discrete`.
72+
prewarp_frequency : float within [0, infinity)
6973
The frequency [rad/s] at which to match with the input continuous-
70-
time system's magnitude and phase
74+
time system's magnitude and phase (only valid for method='bilinear')
7175
7276
Returns
7377
-------
@@ -76,7 +80,7 @@ def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):
7680
7781
Notes
7882
-----
79-
See :meth:`StateSpace.sample` or :meth:`TransferFunction.sample`` for
83+
See :meth:`StateSpace.sample` or :meth:`TransferFunction.sample` for
8084
further details.
8185
8286
Examples
@@ -99,20 +103,19 @@ def c2d(sysc, Ts, method='zoh', prewarp_frequency=None):
99103
100104
Parameters
101105
----------
102-
sysc : LTI (StateSpace or TransferFunction)
106+
sysc : LTI (:class:`StateSpace` or :class:`TransferFunction`)
103107
Continuous time system to be converted
104-
Ts : real > 0
108+
Ts : float > 0
105109
Sampling period
106110
method : string
107111
Method to use for conversion, e.g. 'bilinear', 'zoh' (default)
108-
109112
prewarp_frequency : real within [0, infinity)
110113
The frequency [rad/s] at which to match with the input continuous-
111-
time system's magnitude and phase
114+
time system's magnitude and phase (only valid for method='bilinear')
112115
113116
Returns
114117
-------
115-
sysd : linsys
118+
sysd : LTI of the same class
116119
Discrete time system, with sampling rate Ts
117120
118121
Notes

control/tests/discrete_test.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import pytest
88

99
from control import (StateSpace, TransferFunction, bode, common_timebase,
10-
evalfr, feedback, forced_response, impulse_response,
11-
isctime, isdtime, rss, sample_system, step_response,
10+
feedback, forced_response, impulse_response,
11+
isctime, isdtime, rss, c2d, sample_system, step_response,
1212
timebase)
1313

1414

@@ -382,10 +382,20 @@ def test_sample_system_prewarp(self, tsys, plantname):
382382
Ts = 0.025
383383
# test state space version
384384
plant = getattr(tsys, plantname)
385+
plant_fr = plant(wwarp * 1j)
386+
385387
plant_d_warped = plant.sample(Ts, 'bilinear', prewarp_frequency=wwarp)
386-
plant_fr = evalfr(plant, wwarp * 1j)
387388
dt = plant_d_warped.dt
388-
plant_d_fr = evalfr(plant_d_warped, np.exp(wwarp * 1.j * dt))
389+
plant_d_fr = plant_d_warped(np.exp(wwarp * 1.j * dt))
390+
np.testing.assert_array_almost_equal(plant_fr, plant_d_fr)
391+
392+
plant_d_warped = sample_system(plant, Ts, 'bilinear',
393+
prewarp_frequency=wwarp)
394+
plant_d_fr = plant_d_warped(np.exp(wwarp * 1.j * dt))
395+
np.testing.assert_array_almost_equal(plant_fr, plant_d_fr)
396+
397+
plant_d_warped = c2d(plant, Ts, 'bilinear', prewarp_frequency=wwarp)
398+
plant_d_fr = plant_d_warped(np.exp(wwarp * 1.j * dt))
389399
np.testing.assert_array_almost_equal(plant_fr, plant_d_fr)
390400

391401
def test_sample_system_errors(self, tsys):

control/xferfcn.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,12 +1086,10 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
10861086
* euler: Euler (or forward difference) method ("gbt" with alpha=0)
10871087
* backward_diff: Backwards difference ("gbt" with alpha=1.0)
10881088
* zoh: zero-order hold (default)
1089-
10901089
alpha : float within [0, 1]
10911090
The generalized bilinear transformation weighting parameter, which
10921091
should only be specified with method="gbt", and is ignored
1093-
otherwise.
1094-
1092+
otherwise. See :func:`scipy.signal.cont2discrete`.
10951093
prewarp_frequency : float within [0, infinity)
10961094
The frequency [rad/s] at which to match with the input continuous-
10971095
time system's magnitude and phase (the gain=1 crossover frequency,
@@ -1101,7 +1099,7 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
11011099
Returns
11021100
-------
11031101
sysd : TransferFunction system
1104-
Discrete time system, with sampling rate Ts
1102+
Discrete time system, with sample period Ts
11051103
11061104
Notes
11071105
-----

0 commit comments

Comments
 (0)