Documentation of ss2th


Global Index (short | long) | Local contents | Local Index (short | long)


Function Synopsis

ths = ss2th(th,psobs,dkx)

Help text

SS2TH  Produces a parameterized state-space model.
       THS = SS2TH(TH,ORDERS,DKX)

       TH:  Original model in THETA format
       THS: Model in THETA format, corresponding to a state
            space representation in a canonical form corresponding
            th 'pseudobservability indexes' ORDERS. 

   Nominal parameter values are taken from the nominal or fixed values in TH.
   DKX: This is a vector defining the structure: DKX =[D,K,X]
           D=1 indicates that a direct term from input to output will be 
               estimated, while D=0 means that a delay from input to output
           is postulated.
       K=1 indicates that the K-matrix is estimated, while K=0 means that 
               K will be fixed to zero. 
           X=1 indicates that the initial state is estimated, X=0 that the
           initial state is set to zero.
           To define an arbitrary input delay structure NK, where NK(ku) is
       the delay from input number ku to any of the outputs, let
       DKX=[D,K,X,NK]. NK is thus a row vector of length=no of input
       channels. When NK is specified, it overrides the value of D.

       If K, D and/or X0 is all zero in TH, this will make these matrices fixed 
       to zero also in THS.
       If ORDERS is omitted, a default choice is made.
   If DKX is omitted, the default is decided from the values of TH,

       See also CANFORM, CANSTART and MS2TH

Cross-Reference Information

This function calls This function is called by

Listing of function ss2th

function ths = ss2th(th,psobs,dkx)

%   L. Ljung 10-10-93
%   Copyright (c) 1986-98 by The MathWorks, Inc.
%   $Revision: 3.5 $  $Date: 1997/12/03 23:16:09 $

if nargin < 1
  disp('Usage: THS = SS2TH(TH)')
  disp('       THS = SS2TH(TH,ORDERS,DKX)')
  return
end
[a,b,c,d,k,x0]=th2ss(th);
Tsamp=gett(th);
[n,dum]=size(a);
[dum,nu]=size(b);[ny,dum]=size(c);
if nargin<2, psobs=[];end
if nargin<3
  dkx=[0,1,0];
end
if length(dkx)>3
   nk=dkx(4:length(dkx));
   if length(nk)~=nu
      disp(str2mat('If you specify a delay structure in DKX,',...
                    'you must give the delay for each input,',...
                    ' i.e. DKX must have length 3+no of inputs.'));
      error(' ')
   end
   if any(nk~=fix(nk))|any(nk<0)
      error(['The delays must be non-negative integers.'])
   end
   if any(nk==0),dkx(1)=1;else dkx(1)=0;end
   dkxn4=[dkx(1:3),1-(nk==0)];
elseif dkx(1), nk=zeros(1,nu);
else nk=ones(1,nu);
end
if isempty(psobs)
   if ny>n
     psobs(1:n)=ones(1,n);psobs(n+1:ny)=zeros(1,ny-n);
   else  
     ind1=floor(n/ny);
     for kc=1:ny-1
       psobs(kc)=ind1;
     end
     if ny>1
      psobs(ny)=n-sum(psobs);
     else
      psobs=n;
     end
  end   
end
np=sum(psobs);
if any(psobs<0)
   error('The order indices must be non-negative.')
end
if length(psobs)~=ny,
   error('The number of order indices must be equal to the number of outputs.')
end
if np~=n,
   error('The sum of the order indices must equal the model order.')
end

psz=find(psobs==0);
r=cumsum(psobs);
o1=zeros(n,n);
rown=[];kc=1;
for ky=1:ny
  for koi=0:psobs(ky)-1
     rown=[rown,koi*ny+ky];
     if ky==1,rr=0;else rr=r(ky-1);end
     o1(kc,rr+1+koi)=1;
     kc=kc+1;
  end
end
o2=zeros(n*ny,n);
for jk = 1:ny
    xx = ltitr(a',zeros(n,1),zeros(n,1),c(jk,:)');
    o2(jk:ny:ny*(n-1)+jk,:) = xx;
end
o2=o2(rown,:);
T=inv(o2)*o1;
Ti=inv(o1)*o2;
ac=Ti*a*T;bc=Ti*b;kc=Ti*k;cc=c*T;x0=Ti*x0;
ms=canform(psobs,nu,dkx);
inpdel=find(nk>1);normdel=find(nk<=1);
if ~isempty(inpdel),ac=[ac,bc(:,inpdel)];bc=bc(:,normdel);end
d=d(:,find(nk==0));
par=[];
for kl=1:n
  if any(kl==r)
    par=[par,ac(kl,:)];
  elseif ~isempty(inpdel)
    par=[par,ac(kl,n+1:n+length(inpdel))];
  end
end
if nu>0
if ~isempty(bc)
for kl=1:n
   par=[par,bc(kl,:)];
end
end
end
for kl=psz
   par=[par,cc(kl,:)];
end
if nu>0
if ~isempty(d)
for kl=1:ny
   par=[par,d(kl,:)];
end
end
end
if dkx(2)
for kl=1:n
   par=[par,kc(kl,:)];
end
end
if dkx(3)
for kl=1:n
   par=[par,x0(kl)];
end
end

ths=ms2th(ms,'d',par);
ths=sett(ths,Tsamp);
if norm(k)==0
   ths=fixpar(ths,'k');
end
if norm(d)==0
   ths=fixpar(ths,'d');
end
if norm(x0)==0
   ths=fixpar(ths,'x0');
end