Code covered by the BSD License

# Rsyso

### Franklin Pineda (view profile)

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

[An Bn Cn P]=ss2rform(A,B,C,n)
```function [An Bn Cn P]=ss2rform(A,B,C,n)
% SS2RFORM Finds the Controllable and Observable Canonical Forms form of a LTI SISO SYS model.
%        Starting of Space-State Model.
%
% Syntax:  [A,B,C,D] = ss2rform(A,B,C,D,n)
%
% Inputs:
%    A,B,C,D - LTI SISO system, in Space-State -SS
%    representation.
%    n - Form 1 to 4 Controllable Canonical Forms
%             5 to 8 Observable Canonical Forms.
%
% Outputs:
%    A -
%    B -
%    C -
%    D - space-state representation
%    P - Matriz Transformation
%
% Example:
%   A=[-4 1 0;-5 0 1;-2 0 0];B=[1;4;4];C=[1 0 0];D=0;
%
%   [A,B,C,D P]=ss2rform(A,B,C,D,5)
%
% Other m-files required:
% Subfunctions:         [Ag Bg Cg]=rota(A,B,C)
%                       [Ag Bg Cg]=obs(A,B,C,P)
%                       [Ag Bg Cg]=con(A,B,C,P)
%                       [M]=order(A)
%
%
% Author: Franklin Pineda Torres
% email: franklin.pineda@fuac.edu.co
% Created: March 2011;
% Last revision: 17-March-2011;

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

%------------- BEGIN CODE --------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if n>=1 || n<=8
if n<=4
if isctrb(A,B)
U=ctrb(A,B);
switch n
case 1
P=U;
[An Bn Cn]=con(A,B,C,P);
case 2
P=U*order(A);
[An Bn Cn]=con(A,B,C,P);
case 3
[An Bn Cn P]=ss2rform(A,B,C,1);
[An Bn Cn]=rota(An,Bn,Cn);
case 4
[An Bn Cn P]=ss2rform(A,B,C,2);
[An Bn Cn]=rota(An,Bn,Cn);
end

else
errordlg('The System is not Controllable','ERROR!!');
An=0;Bn=0;Cn=0;P=0;
end
else
if isobsv(A,C)
V=obsv(A,C);
switch n
case 5
P=V;
[An Bn Cn]=obs(A,B,C,P);
case 6
P=order(A)*V;
[An Bn Cn]=obs(A,B,C,P);
case 7
[An Bn Cn P]=ss2rform(A,B,C,5);
[An Bn Cn]=rota(An,Bn,Cn);
case 8
[An Bn Cn P]=ss2rform(A,B,C,6);
[An Bn Cn]=rota(An,Bn,Cn);
end

else
errordlg('The System is not Observable','ERROR!!');
An=0;Bn=0;Cn=0;P=0;
end
end
else
errordlg('Number must be form 1 to 8','!! Error !!')
end

function [M]=order(A)
p=poly(A);
p(end)=[];
p=fliplr(p);
M=eye(length(p));
M=rot90(M);
for i=1:length(M),
M(i,1:length(p))=p;
p(1)=[];
end

function [Ag Bg Cg]=con(A,B,C,P)
Ag=inv(P)*A*P;
Bg=inv(P)*B;
Cg=C*P;

function [Ag Bg Cg]=obs(A,B,C,P)
Ag=P*A*inv(P);
Bg=P*B;
Cg=C*inv(P);

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