There are controllable and observable forms of canonical state-space from a transfer function.
However, when I try ss2tf
from Matlab, I receive a different result. What sort of algorithm does Matlab use? Is there any documentation or open source implementation of it too?
>> a = [1 0.4 1];
>> b = [1 2 1];
>> [A,B,C,D] = tf2ss(b,a)
A =
-0.4000 -1.0000
1.0000 0
B =
1
0
C =
1.6000 0
D =
1
First to keep in mind is that state representations are not unique. Different state representations can lead to the same transfer representation (they actually form an equivalence class up to pole/zero cancellations).
Here the difference is just that and nothing more. Check the following systems: they all have the same transfer function but has different C matrices (G,H different than J) but H,J are in canonical form
G = ss(tf(b,a))
H = ss2ss(G,rot90(eye(2)))
J = canon(H,'companion')
and canon
using negative of off-diagonals the A matrix probably after balancing. Can also be a bug.
As WG~ mentioned (shameless plug I'm the author of harold
), in general there are much more involved algorithms for the conversion because MIMO systems require more care. I implemented a variant of Section 4.4 of W.A. Wolowich, Linear Multivariable Systems (1974). I think matlab does a similar thing but also balances (kind-of) the realization which I have yet to add.
In general, these controllable and observable forms are not well-conditioned numerically because of the companion structure. So extra care is needed if something with considerable size and seriousness.
In practice, don't use them for assessing controllability or observability other than some textbook exercises. Instead use minreal
and work with minimal systems.
The reason why companion matrix pops up is because the roots of the real polynomial and the eigenvalues of the companion matrix formed by the coefficients of this polynomial coincide. For some historical remarks , check out this Cleve Moler's blog post about roots.
For a classical example why this is an ill-conditioned problem here is the example from the master himself.