Code covered by the BSD License  

Highlights from
Rsyso

image thumbnail

Rsyso

by

 

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

seriesform(Gt)
function [A,B,C,D] = seriesform(Gt)
% SERIESFORM Finds the Tandem or Serie Realization of a LTI SISO SYS model.
%
% Syntax:  [A,B,C,D] = seriesform(Gt)
%
% Inputs:
%    SYS - LTI SISO system, in Transfer Function -TF
%    representation with only simple poles. 
%
% Outputs:
%    A - 
%    B - 
%    C - 
%    D - space-state representation
%
% Example: 
%   G1=tf([1 0],conv(conv([1 1],[1 1]),conv([1 2],[1 2])));
%
%   [A,B,C,D]=seriesform(Gt)
%
% Other m-files required: 
% Subfunctions:          none
% 
%
% Author: Franklin Pineda
% email: franklin.pineda@fuac.edu.co
% Created: March 2011; 
% Last revision: 11-March-2011;

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

%------------- BEGIN CODE --------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[G D]=serialdtf(Gt);
lg=length(G);
pg=length(pole(G));
if pg<lg
    pg=lg;
end
C=zeros(1,pg);
C(end)=1;
i=1;ig=1;
j=0;M=zeros(pg,pg+1);% [A input]
while i<=pg,
    [z p k]=zpkdata(G(ig));
    z=cell2mat(z);
    p=cell2mat(p);
    if isreal(z) || isreal(p)
        if length(p)==1
            M(i,i)=p;
            i1=0;
        else
            pol=poly(p);
            pol(1)=[];
            pol=-fliplr(pol);
            M(i,i:i+1)=pol;
            M(i+1,i)=1; 
            i1=1;
        end        
        if i~=1
            if length(z)==1
                M(i,i-1)=-z;
                M(i,:)=M(i-1,:)+M(i,:);
            elseif length(z)==2
                M(i,i-1)=-z;
                M(i,:)=M(i-2,:)+M(i-1,:)+M(i,:);
            else
                M(i,i-1)=k;
            end            
        else
            M(i,end)=k;
        end
    else
        [A B C D]=ssdata(Gt);
        j=1;
        break;       
    end
    if i1==1
        i=i+2;
    else
        i=i+1;
    end
    ig=ig+1;
end
if j~=1
    B=M(:,end);
    M(:,end)=[];
    A=M;
end

Contact us