# Minimal realization of a state space model?

Minimal realization of a transfer function is about cancelling out poles against zeros.

But the minimal realization of a state space model is about cancelling out non-controllable and non-observable states.

My question is how I can do that? Can I use PBH (Popov, Belevich, Hautus)-test to find which each eigenvalue gives non-controllable or observable state?

$$\operatorname{rank} ([(A-\lambda I) B]) = n \forall \lambda$$

$$\operatorname{rank} ([(A-\lambda I); C]) = n \forall \lambda$$

After I have found the states who are uncontrollable or unobservable. Can I then create a new state space model without those states?

## 1 Answer

The easiest way of finding the minimal state space model I think would be using the Kalman decomposition. This allows you to find a similarity transformation that makes it easy to split the state space model into a minimal (controllable and observable) and non-minimal (not controllable or not observable) form.

When calculating this decomposition you could use the Hautus test, but you could also use the controllability and observability matrix. I made a quick implementation of both in MATLAB, whose code can be seen below.

Hautus test:

function [M, Ak, Bk, Ck, N] = kalman_decomp_hautus(A, B, C)

[V,D] = eig(A);
n = length(A);

M1 = []; M2 = []; M3 = []; M4 = [];
N = zeros(1, 4);
for k = 1 : n
tempC = rank([A - D(k,k) * eye(n) B]) - n;
tempO = rank([A - D(k,k) * eye(n); C]) - n;
if tempC == 0
if tempO == 0
M2 = [M2 V(:,k)];
N(2) = N(2) + 1;
else
M1 = [M1 V(:,k)];
N(1) = N(1) + 1;
end
else
if tempO == 0
M4 = [M4 V(:,k)];
N(4) = N(4) + 1;
else
M3 = [M3 V(:,k)];
N(3) = N(3) + 1;
end
end
end
M = [M1 M2 M3 M4];

Ak = M \ A * M;
Bk = M \ B;
Ck = C * M;


Using this implementation does have the downside that the decomposed state space model matrices can have complex numbers, because if the original $A$ matrix (assuming it is real valued) has complex conjugate eigenvalues then its eigenvectors will be complex conjugate as well, and therefore the similarity transformation also. You could of course try to detect this, but I just wanted a working example.

Controllability and observability matrix:

function [M, Ak, Bk, Ck, N] = kalman_decomp_matrix(A, B, C, tol)

cc = ctrb(A, B);
oo = obsv(A, C);

Sc = rref(cc')'; Sc = Sc(:,1:rank(cc));
Nc = null(cc');
So = rref(oo)'; So = So(:,1:rank(oo));
No = null(oo);

M1 = rref(round(Sc * (Sc \ No),tol)')';
N(1) = rank(M1);
M1 = M1(:,1:N(1));
M2 = rref(round(Sc * (Sc \ So),tol)')';
N(2) = rank(M2);
M2 = M2(:,1:N(2));
M3 = rref(round(Nc * (Nc \ No),tol)')';
N(3) = rank(M3);
M3 = M3(:,1:N(3));
M4 = rref(round(Nc * (Nc \ So),tol)')';
N(4) = rank(M4);
M4 = M4(:,1:N(4));
M = [M1 M2 M3 M4];

Ak = M \ A * M;
Bk = M \ B;
Ck = C * M;


I have not done many tests, but with one test I noticed that finding the intersect of two spans of vectors could give wrong results due to limited numerical accuracy, so I added rounding (using tol=13 seems to omit errors in my case).

Once you have your Kalman decomposition then the minimal realisation of the state space model can be constructed using:

list = N(1) + 1:N(1) + N(2);
Am = Ak(list,list);
Bm = Bk(list,:);
Cm = Ck(:,list);
Dm = D;


If you just want to minimal realisation then you might be able to calculate it faster. But you do need to ensure that the total $M$ matrix is square and full rank.

• So with this...I can find which states who are not controllable and observable and remove them ? – Daniel Mårtensson Oct 17 '17 at 18:42
• Or can I not take SVD of controllbility gramian to check what state is controllable or not ? – Daniel Mårtensson Oct 17 '17 at 18:43
• Can I use eigensystem realization algorithm(ERA) or Ho Kalman IR algorithm ? – Daniel Mårtensson Oct 17 '17 at 18:57
• @DanielMårtensson I never really liked Gramians so I prefer the controllability and observability matrices. However the PBH-test does not use either, it just enabled you to find which mode with a certain eigenvalue is not controllable or observable. The corresponding eigenvectors can therefore be used as well to identify the similarity transformation that brings the system into the Kalman decomposition. I am not familiar with eigensystem realization algorithm or Ho Kalman IR algorithm. – Kwin van der Veen Oct 17 '17 at 19:39
• @DanielMårtensson Your initial question is about finding the minimal state space realisation. What your are asking now would be another question by itself. But MATLAB states the following on its page about the minreal function: "Pole-zero cancellation is a straightforward search through the poles and zeros looking for matches that are within tolerance. Transfer functions are first converted to zero-pole-gain form.". Earlier on it also mentions a Kalman decomposition, so I am not sure what MATLAB actually uses. And I also have had problems with minreal not giving the result I expected. – Kwin van der Veen Oct 18 '17 at 0:49