Code covered by the BSD License  

Highlights from
Rsyso

image thumbnail

Rsyso

by

 

Finds realizations of SISO linear systems. Autonoma of Colombia University.

tf2rform(G,n)
function [A,B,C,D] = tf2rform(G,n)
% TF2RFORM Finds the Controllable and Observable Canonical Forms form of a LTI SISO SYS model.
%        Starting of Transfer Function Model.
%
% Syntax:  [A,B,C,D] = tf2rform(G,n)
%
% Inputs:
%    A,B,C,D - LTI SISO system, in Space-State -SS
%    representation.  
%    n - Form 1 to 4 Observable Canonical Forms
%             5 to 8 Controllable Canonical Forms.
%
% Outputs:
%    A - 
%    B - 
%    C - 
%    D - space-state representation
%
%
% Example: 
%        den=conv(conv(conv([1 1],[1 1]),[1 1]),[1 2]);
%        G1=tf(conv(conv([1 2],[1 2]),[1 2]),den);        
%
%   [A,B,C,D]=tf2rform(A,B,C,D,5)
%
% Other m-files required: 
% Subfunctions:        
%                      [Ag Bg Cg]=rota(A,B,C)
%                       B=betas(A,b)
%                       
%
% Author: Franklin Pineda Torres
% email: franklin.pineda@fuac.edu.co
% Created: March 2011; 
% Last revision: 19-March-2011;

% May be distributed freely for non-commercial use, 
% but please leave the above info unchanged, for
% credit and feedback purposes

%------------- BEGIN CODE --------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch n
    case 1
        [Ag,Bg,Cg,D] = tf2rform(G,3);
        [A B C]=rota(Ag,Bg,Cg);       
    case 2 
         [Ag,Bg,Cg,D] = tf2rform(G,4);
         [A B C]=rota(Ag,Bg,Cg);
    case 3
        [A,Bg,Cg,D] = tf2rform(G,8);
        C=fliplr(Bg');
        B=betas(A,Cg');
    case 4
         [Ag,Bg,Cg,D] = tf2rform(G,8);
         B=Cg';C=Bg';A=flipud(rot90(Ag));         
    case 5
         [Ag,Bg,Cg,D] = tf2rform(G,1);
         C=Bg';B=Cg';A=Ag';     
    case 6
        [Ag,Bg,Cg,D] = tf2rform(G,8);
        [A B C]=rota(Ag,Bg,Cg);
    case 7
        [Ag,Bg,Cg,D] = tf2rform(G,3);
        C=Bg';B=Cg';A=Ag';        
    case 8
        [nun den]=tfdata(G);
        [A,B,C,D]=tf2ss(nun{:},den{:});
end


function B=betas(A,b)
p=poly(A);
p(end)=[];
p=fliplr(p);
M=eye(length(p));
for i=length(M):-1:1,
    M(i,1:length(p))=p; 
    p(1)=[];
end
B=inv(M)*b;
B=flipud(B);


function [Ag Bg Cg]=rota(A,B,C)
Bg=flipud(B);
Cg=fliplr(C);
Ag=rot90(A,90);

Contact us