|
7 | 7 | import pytest
|
8 | 8 |
|
9 | 9 |
|
10 |
| -from control import StateSpace, forced_response, tf, rss, c2d |
| 10 | +from control import StateSpace, impulse_response, forced_response, tf, rss, c2d |
11 | 11 | from control.exception import ControlMIMONotImplemented
|
12 | 12 | from control.tests.conftest import slycotonly
|
13 |
| -from control.modelsimp import balred, hsvd, markov, modred |
| 13 | +from control.modelsimp import balred, hsvd, markov, okid, modred |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class TestModelsimp:
|
@@ -111,6 +111,35 @@ def testMarkovResults(self, k, m, n):
|
111 | 111 | # for k=5, m=n=10: 0.015 %
|
112 | 112 | np.testing.assert_allclose(Mtrue, Mcomp, rtol=1e-6, atol=1e-8)
|
113 | 113 |
|
| 114 | + def testOKIDSignature(self): |
| 115 | + |
| 116 | + # Example 6.1, Applied System Identification |
| 117 | + m1, k1, c1 = 1., 1., 0.01 |
| 118 | + A = np.array([ |
| 119 | + [0., 1.], |
| 120 | + [-k1/m1, -c1/m1], |
| 121 | + ]) |
| 122 | + B = np.array([[0.],[1./m1]]) |
| 123 | + C = np.array([[-k1/m1, -c1/m1]]) |
| 124 | + D = np.array([[1.]]) |
| 125 | + sys = StateSpace(A, B, C, D) |
| 126 | + dt = 0.1 |
| 127 | + sysd = sys.sample(dt, method='zoh') |
| 128 | + |
| 129 | + T = np.arange(0,200,dt) |
| 130 | + U = np.random.randn(sysd.B.shape[-1], len(T)) |
| 131 | + response = forced_response(sysd, U=U) |
| 132 | + Y = response.outputs |
| 133 | + |
| 134 | + m = 5 |
| 135 | + ir_true = impulse_response(sysd, T=T) |
| 136 | + Htrue = ir_true.outputs[:m+1]*dt |
| 137 | + H = okid(Y, U, m, dt=True) |
| 138 | + |
| 139 | + np.testing.assert_allclose(Htrue, H, atol=1e-1) |
| 140 | + |
| 141 | + |
| 142 | + |
114 | 143 | def testModredMatchDC(self):
|
115 | 144 | #balanced realization computed in matlab for the transfer function:
|
116 | 145 | # num = [1 11 45 32], den = [1 15 60 200 60]
|
|
0 commit comments