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

5 次查看(过去 30 天)
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.

回答(1 个)

Raj
Raj 2019-6-27
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 个评论
Hans
Hans 2019-6-27
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 2019-6-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by