1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) INRIA - 3// 4// Copyright (C) 2012 - 2016 - Scilab Enterprises 5// 6// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// This file was originally licensed under the terms of the CeCILL v2.1, 9// and continues to be available under such terms. 10// For more information, see the COPYING file which you should have received 11// along with this program. 12 13 14function [Stmp,Ws]=colregul(Sl,Alfa,Beta); 15 // [Stmp,Ws]=regul(Sl) computes a polynomial-state-space prefilter 16 // Ws such that Stmp=Sl*Ws is proper and non singular. 17 // Poles at infinity of Sl are moved to Alfa; 18 // Zeros at infinity of Sl are moved to Beta; 19 // Sl is asummed left invertible i.e. ss2tf(Sl) full column rank 20 //! 21 22 [LHS,RHS]=argn(0); 23 if RHS==1 then Alfa=0;Beta=0;end 24 flag=0; 25 Sl1=Sl(1) 26 if Sl1(1)=="r" then 27 flag=1;Sl=tf2ss(Sl); 28 end 29 s=poly(0,"s"); 30 D=Sl(5); 31 n=size(D);n1=n(1);n2=n(2); 32 Ws=syslin([],[],[],[],eye(n2,n2)); 33 Stmp=Sl; 34 m=max(degree(D)); 35 // moving poles @ infinity to poles @ Alfa 36 while m>0 37 Dm=coeff(D,m); 38 [W,r]=colcomp(Dm); 39 if r==0 then Wstmp=W; else 40 dim=n2-r;Wstmp=W*[eye(dim,dim),zeros(dim,r); 41 zeros(r,dim),tf2ss(1/(s-Alfa)*eye(r,r))];end 42 Ws=Ws*Wstmp; 43 Stmp=Stmp*Wstmp; 44 D=clean(Stmp(5)); 45 m=max(degree(D)); 46 end 47 Stmp(5)=coeff(Stmp(5),0); 48 49 [W,r]=colcomp(Stmp(5)); 50 if r==n1 then 51 Ws=Ws*W;Stmp=Stmp*W; 52 if flag==1 then Ws=ss2tf(Ws);Stmp=ss2tf(Stmp);end 53 return; 54 end 55 [nx,nx]=size(Stmp(2)); 56 // moving zeros @ infinity to zeros @ Beta 57 i=0; 58 while r < n2, 59 i=i+1; 60 if r==n2 then Wstmp=W; 61 else 62 dim=n2-r;Wstmp=W*[(s-Beta)*eye(dim,dim),zeros(dim,r); 63 zeros(r,dim),eye(r,r)]; 64 end 65 Wstmp=syslin([],[],[],[],Wstmp); 66 Ws=Ws*Wstmp; 67 Stmp=Stmp*Wstmp; 68 Stmp(5)=coeff(Stmp(5),0); 69 rold=r; 70 [W,r]=colcomp(Stmp(5)); 71 // if r==rold&r<>0 then break;end 72 if i>=nx then break;end 73 end 74 if flag==1 then 75 Ws=ss2tf(Ws);Stmp=ss2tf(Stmp);end 76endfunction 77