MATLAB: Conversion from State Space to TF and then back to State Space

control systemControl System Toolboxstate-spacetransfer function

I created a state space model with 2 inputs 4 outputs 4 states
used the
if true
sys_tf = tf(sys);
end
function to convert SS to tf. sys_tf comes out to a 4 X 2 matrix
Once I obtained this TF I added a PID feedback control to sys_tf(1,2) and sys_tf(3,2). Now when I convert this sys_tf to a state space model using
if true
[A,B,C,D] = ssdata(sys_tf);
sys1 = ss(A,B,C,D);
end
This creates s state space model with 2 inputs, 4 outputs and 30states. Why and how is this happening.
Thanks. Shilp

Best Answer

Some points:
Don't do "algebra" with tf variables, use the functions series, parallel and feedback.
sys_mimo1 = ss(sys_mimo) is going to convert the tf model to a ss model, I don't think there is a need for the extra step with ssdata.
This one here
sys_mimo_tf(1,2) = sys_mimo_tf(1,2)*feedback(sys_mimo_tf(1,2),C);
is probably not doing what you want it to, it will give you the transfer function
sys_mimo_tf(1,2)^2 / 1 + sys_mimo_tf(1,2)*C
so that's probably where many extra states come from. You should expect 2 extra states per added PID.
Lastly, look at the Hankel Singular Values or a similar measure to figure out whether there might be a lot of almost unobservable/almost uncontrollable states in your resulting model. That would indicate numerical issues.