MATLAB: Problem in conversion the state-space of the system to transfer function

balrealss2tfssdatasystemtftransfer function

I want to return the state-space to transfer function, if the system reduced is by balanced real technique.
I have this code
s=tf('s');
G=(s^3+11*s^2+36*s+26)/(s^4+14.6*s^3+74.96*s^2+156.7*s+99.65);
[A,B,C,D]=ssdata(G);
[AA, BB, CC,DD] = balreal(A, B, C);
[b,a] = ss2tf(AA,BB,CC,DD);
if i want to convert state-space representation to transfer function using the function 'ss2tf', i find this error :
Error using ss2tf (line 26)
The C and D matrices must have the same number of rows.
Can any one help me how can i solve this error ?

Best Answer

Hi,
this appears to run:
s=tf('s');
G=(s^3+11*s^2+36*s+26)/(s^4+14.6*s^3+74.96*s^2+156.7*s+99.65);
[sys,g] = balreal(G);
[b,a] = ss2tf(sys.A, sys.B, sys.C, sys.D);
result is:
>> transfun = tf(a,b)
transfun =
s^4 + 14.6 s^3 + 74.96 s^2 + 156.7 s + 99.65
--------------------------------------------
s^3 + 11 s^2 + 36 s + 26
Continuous-time transfer function.
Best regards
Stephan