Skip to content

Commit 03c04e2

Browse files
committed
adjusted prewarping to only apply to 'bilinear' cont-to-discrete approximation, fixed failing tests
1 parent 8d30b44 commit 03c04e2

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

control/statesp.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,9 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
868868
869869
prewarp_frequency : float within [0, infinity)
870870
The frequency [rad/s] at which to match with the input continuous-
871-
time system's magnitude and phase
871+
time system's magnitude and phase (the gain=1 crossover frequency,
872+
for example). Should only be specified with method='bilinear' or
873+
'gbt' with alpha=0.5 and ignored otherwise.
872874
873875
Returns
874876
-------
@@ -889,11 +891,12 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
889891
raise ValueError("System must be continuous time system")
890892

891893
sys = (self.A, self.B, self.C, self.D)
892-
if prewarp_frequency is not None:
894+
if (method=='bilinear' or (method=='gbt' and alpha==0.5)) and \
895+
prewarp_frequency is not None:
893896
Twarp = 2*np.tan(prewarp_frequency*Ts/2)/prewarp_frequency
894-
Ad, Bd, C, D, _ = cont2discrete(sys, Twarp, method, alpha)
895-
else:
896-
Ad, Bd, C, D, _ = cont2discrete(sys, Ts, method, alpha)
897+
else:
898+
Twarp = Ts
899+
Ad, Bd, C, D, _ = cont2discrete(sys, Twarp, method, alpha)
897900
return StateSpace(Ad, Bd, C, D, Ts)
898901

899902
def dcgain(self):

control/tests/statesp_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def test_sample_system_prewarping(self):
624624
wwarp = 50
625625
Ts = 0.025
626626
plant = StateSpace(A,B,C,0)
627-
plant_d_warped = plant.sample(Ts, prewarp_frequency=wwarp)
627+
plant_d_warped = plant.sample(Ts, 'bilinear', prewarp_frequency=wwarp)
628628
np.testing.assert_array_almost_equal(
629629
evalfr(plant, wwarp*1j),
630630
evalfr(plant_d_warped, np.exp(wwarp*1j*Ts)),

control/tests/xferfcn_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def test_sample_system_prewarping(self):
868868
Ts = 0.025
869869
plant = StateSpace(A,B,C,0)
870870
plant = ss2tf(plant)
871-
plant_d_warped = plant.sample(Ts, prewarp_frequency=wwarp)
871+
plant_d_warped = plant.sample(Ts, 'bilinear', prewarp_frequency=wwarp)
872872
np.testing.assert_array_almost_equal(
873873
evalfr(plant, wwarp*1j),
874874
evalfr(plant_d_warped, np.exp(wwarp*1j*Ts)),

control/xferfcn.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,9 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
988988
989989
prewarp_frequency : float within [0, infinity)
990990
The frequency [rad/s] at which to match with the input continuous-
991-
time system's magnitude and phase
991+
time system's magnitude and phase (the gain=1 crossover frequency,
992+
for example). Should only be specified with method='bilinear' or
993+
'gbt' with alpha=0.5 and ignored otherwise.
992994
993995
Returns
994996
-------
@@ -1014,11 +1016,12 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
10141016
if method == "matched":
10151017
return _c2d_matched(self, Ts)
10161018
sys = (self.num[0][0], self.den[0][0])
1017-
if prewarp_frequency is not None:
1019+
if (method=='bilinear' or (method=='gbt' and alpha==0.5)) and \
1020+
prewarp_frequency is not None:
10181021
Twarp = 2*np.tan(prewarp_frequency*Ts/2)/prewarp_frequency
1019-
numd, dend, _ = cont2discrete(sys, Twarp, method, alpha)
1020-
else:
1021-
numd, dend, _ = cont2discrete(sys, Ts, method, alpha)
1022+
else:
1023+
Twarp = Ts
1024+
numd, dend, _ = cont2discrete(sys, Twarp, method, alpha)
10221025
return TransferFunction(numd[0, :], dend, Ts)
10231026

10241027
def dcgain(self):

0 commit comments

Comments
 (0)