MATLAB: How to convert idss model of system into transferfunction

idss modelMATLABsimulinktransfer function

Hi,
I am using n4sid technique for identification and at the end I am getting idss model.
now I know that idss data has A B C D matrices but while using them as state space model in my simulink I am not getting the correct answer.
I even tried to use tfsys = tf(sys, 'noise') to get accurate transfer function but even though it was not working.
but when I used 'idmodel' in simulink I got the correct answer.
so my major question is how can i get accurate transfer function or state space matrices from idss model which I can use in simulink?.
Thank you

Best Answer

Hi,
i think i could solve this by using the following code / functions:
sys=n4sid(data,1);
[A,B,C,D,K] = idssdata(sys);
[b,a] = ss2tf(A,B,C,D);
% new code which seems to work:
sys_new = idtf(sys);
[num, den] = tfdata(sys_new);
x = num{1};
y = den{1};
this delivers:
sys_new =
From input "u1" to output "y1":
z^-1
------------------
1 - 0.0002372 z^-1
Sample time: 0.1 seconds
Discrete-time identified transfer function.
Parameterization:
Number of poles: 1 Number of zeros: 1
Number of free coefficients: 2
Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Created by conversion from idss model.
If you then insert a discrete transfer function block into your simulink model with x and y as numerator, denumerator:
and look the results on data inspector you are happy i guess:
Best regards
Stephan