In MATLAB we use tf2ss, similarly how can we Implement this in simulink

2 Ansichten (letzte 30 Tage)
Hans
Hans am 25 Jun. 2019
Kommentiert: Raj am 27 Jun. 2019
I alredy made an euler algorithm for a system in Matlab and now I need to make the same in Simulink. In Matlab I took the help of tf2ss command to get the data of matrices A, B, C and D. Now inordeer to obtain the same result in Simulink How should I proceed.
% For Example
Fun = tf([1 2],[3 4 5]);
% Now Simply I use tf2ss to get A, B, C and D matrices
[A B C D] = tf2ss(Fun);
Please guide me, how to implement the same in simulink.

Antworten (1)

Raj
Raj am 27 Jun. 2019
Why not use the transfer function block directly instead of converting it to state space model? Anyways, you can use 'Matlab function block' & 'tf2ss' function to implement the same thing that you have done in Matlab. Something like this:
function [A,B,C,D] = Myfcn
A=zeros(2,2);
B=zeros(2,1);
C=B;
D=0;
coder.extrinsic('tf2ss') % Code generation not supported for tf2ss
[A B C D] = tf2ss([1 2],[3 4 5]);
end
  2 Kommentare
Hans
Hans am 27 Jun. 2019
I am showing you my example in detail please look into this.
My overall tf is
G_PHI_SET_DELTA_ACTU =
1640 s^5 + 4090 s^4 + 1722 s^3 + 204.6 s^2 + s
------------------------------------------------------------
8 s^6 + 138 s^5 + 674 s^4 + 960 s^3 + 1020 s^2 + 200.1 s + 1
% In matlab coding I simply wrote these commands
G_BACK_DELTA = series(G_PHI_T,G_MES_T);
G_PHI_SET_DELTA_ACTU = feedback(G_FRWD_DELTA,G_BACK_DELTA);
[G_PHI_SET_DELTA_ACTU_NUM,G_PHI_SET_DELTA_ACTU_DEN] = tfdata(G_PHI_SET_DELTA_ACTU);
[A,B,C,D] = tf2ss(G_PHI_SET_DELTA_ACTU_NUM{1},G_PHI_SET_DELTA_ACTU_DEN{1});
% Now here I use Euler Algorithm using a While loop
while condtn>=5
X1(j+1) = X1(j) + delta_t * (A(1,1)*X1(j)+A(1,2)*X2(j)+A(1,3)*X3(j)+A(1,4)*X4(j)+A(1,5)*X5(j)+A(1,6)*X6(j)+B(1)*phi_T_SET(j));
X2(j+1) = X2(j) + delta_t * (A(2,1)*X1(j)+A(2,2)*X2(j)+A(2,3)*X3(j)+A(2,4)*X4(j)+A(2,5)*X5(j)+A(2,6)*X6(j)+B(2)*phi_T_SET(j));
X3(j+1) = X3(j) + delta_t * (A(3,1)*X1(j)+A(3,2)*X2(j)+A(3,3)*X3(j)+A(3,4)*X4(j)+A(3,5)*X5(j)+A(3,6)*X6(j)+B(3)*phi_T_SET(j));
X4(j+1) = X4(j) + delta_t * (A(4,1)*X1(j)+A(4,2)*X2(j)+A(4,3)*X3(j)+A(4,4)*X4(j)+A(4,5)*X5(j)+A(4,6)*X6(j)+B(4)*phi_T_SET(j));
X5(j+1) = X5(j) + delta_t * (A(5,1)*X1(j)+A(5,2)*X2(j)+A(5,3)*X3(j)+A(5,4)*X4(j)+A(5,5)*X5(j)+A(5,6)*X6(j)+B(5)*phi_T_SET(j));
X6(j+1) = X6(j) + delta_t * (A(6,1)*X1(j)+A(6,2)*X2(j)+A(6,3)*X3(j)+A(6,4)*X4(j)+A(6,5)*X5(j)+A(6,6)*X6(j)+B(6)*phi_T_SET(j));
phi_T_ACTU(j) = C(1,1)*X1(j)+C(1,2)*X2(j)+C(1,3)*X3(j)+C(1,4)*X4(j)+C(1,5)*X5(j)+C(1,6)*X6(j)+D*phi_T_SET(j);
j =j+1
end
% This was my task in matlab and its done, now I have to do the same thing in Simulink
With your previous explanation I got a brief idea how to get the A,B,C and D matrices by using the Matlab function block in simulink. If possible could you please help me with overall problem.
Raj
Raj am 27 Jun. 2019
You have not shared your full code without which your 'while' is making no sense to me. What is 'condtn'? Its not defined anywhere. Why is another random variable 'j' getting incremented inside the loop which is not pre defined anywhere? What is delta_t? What is 'phi_T_SET'? Looks like you just want to do a matrix multiplication, (xdot=Ax+Bu & y=Cx+Du) then what is the necessity of this complicated while loop? It's quite simple to implement in Simulink. Just use the 'State Space' block and enter your A,B,C,D matrices.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by