forked from Future-Power-Networks/Simplus-Grid-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSsMinReal.m
41 lines (33 loc) · 768 Bytes
/
SsMinReal.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% Get the minimum realization of a state space model by Kalman
% decomposition.
% Author(s): Yitong Li
function GminKalman = SsMinReal(G)
if (SimplusGT.is_dss(G))
error('Error: The input system cannot be a descriptor state space model.')
end
A = G.A;
B = G.B;
C = G.C;
D = G.D;
[~,U] = minreal(G);
A_ = U*A*(U');
B_ = (U)*B;
C_ = C*(U');
D_ = D;
Tor = 1e-9;
A_ = TorCheck(A_,Tor);
B_ = TorCheck(B_,Tor);
C_ = TorCheck(C_,Tor);
D_ = TorCheck(D_,Tor);
GminKalman = ss(A_,B_,C_,D_);
end
function A = TorCheck(A,tor)
[m,n] = size(A);
for i = 1:m
for j = 1:n
if (A(i,j) <= tor)
A(i,j) = 0;
end
end
end
end