Skip to content

Commit 860acb7

Browse files
committed
Add unit tests, change okid output for siso
1 parent 23c0a44 commit 860acb7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

control/modelsimp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,5 +764,9 @@ def okid(*args, m=None, transpose=False, dt=True, truncate=False):
764764
H[:,:,1:] = Y[:,:,:]
765765
H = H/dt # scaling
766766

767+
# for siso return a 1D array instead of a 3D array
768+
if q == 1 and p == 1:
769+
H = np.squeeze(H)
770+
767771
# Return the first m Markov parameters
768772
return H if not transpose else np.transpose(H)

control/tests/modelsimp_test.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import pytest
88

99

10-
from control import StateSpace, forced_response, tf, rss, c2d
10+
from control import StateSpace, impulse_response, forced_response, tf, rss, c2d
1111
from control.exception import ControlMIMONotImplemented
1212
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
1414

1515

1616
class TestModelsimp:
@@ -111,6 +111,35 @@ def testMarkovResults(self, k, m, n):
111111
# for k=5, m=n=10: 0.015 %
112112
np.testing.assert_allclose(Mtrue, Mcomp, rtol=1e-6, atol=1e-8)
113113

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+
114143
def testModredMatchDC(self):
115144
#balanced realization computed in matlab for the transfer function:
116145
# num = [1 11 45 32], den = [1 15 60 200 60]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy