www.pudn.com > Closid30.rar > Clmodcop.M, change:1998-09-17,size:7633b


function clmodcop(option) 
% function clmodcop(option) 
% 
% Callback m-file for the conversion of estimated objects into 
% plant and noise models to be copied to the model board.  
%  
% OPTION indicates the identification method being used as 
% 1   Two-stage: 
% 2   Indirect: 
% 3   Tailor-made: 
% 4   IV 
% 5   Coprime factors: 
% 6   Dual-Youla: 
% 7   Non-parametric: 
 
% Functions called: cllight,sitb2cl,clobjget,clobjins,poly2th, 
%                   th2ss,clr2p,clstack,cltpc,minreal,clsplit,cldn2sys, 
%                   th2tf 
 
% 07-06-1997 
% (c) Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 19-05-1998 
%              24-08-1998: Addition correct sample time for Tailm-models 
%              16-09-1998: Correction reading nonpar-estimate. 
global CLIDmods	CLIDmnum 
 
% Import model 
if option==1 | option==2 | option==6 | ... 
    (option==5 & get(findobj('tag','CLIDENT'),'value')==3), 
  err=1; 
  [err,th]=sitb2cl; 
  if err, return, end 
%  tsamp=th(1,2); 
else 
  if option==3 
    th=get(findobj('tag','TAILORORDER'),'userdata'); 
%%%%%%% Correction 24/08/98:%% 
	tsamp=th(1,2); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	 
  elseif option==4 
    th=get(findobj('tag','IVORDER'),'userdata'); 
  elseif option==5 
    th=get(findobj('tag','CLIDENT'),'userdata'); 
  elseif option==7 
    th=get(findobj('tag','WINDOWLENGTH'),'userdata'); 
  end 
end 
tsamp=th(1,2); 
 
% Get userdata of current figure to read the name  
% of the model to be stored 
figus=get(gcf,'Userdata'); 
title=cldebl(get(figus(4,1),'String')); 
 
if option==1 | option==2 | option==3 | option==6 | ... 
   (option==5 &	get(findobj('tag','CLIDENT'),'value')==3) 
%if ((option~=4 & option~=7) | ... 
%    (option==5 & get(findobj('tag','CLIDENT'),'value')~=2)) 
% Rewrite th in system format 
%  [a,b,c,d,k]=th2ss(th); 
  [numg,deng]=th2tf(th,1);[ag,bg,cg,dg]=tf2ss(numg,deng); 
  [numh,denh]=th2tf(th,-1);[ah,bh,ch,dh]=tf2ss(numh,denh); 
  [ag,bg,cg,dg]=minreal(ag,bg,cg,dg); 
  if isempty(ag), ag=0;bg=0;cg=0; end 
  [ah,bh,ch,dh]=minreal(ah,bh,ch,dh); 
  if isempty(ah), ah=0;bh=0;ch=0; end 
  sgest=[ag bg;cg dg]; nsgest=length(ag); 
  shest=[ah bh;ch 1]; nshest=length(ah); 
end 
 
%**************************************************************** 
% 
%              Two-stage method	/ Tailor-made parametrization 
% 
%**************************************************************** 
if option==1 | option==3 
  sg=sgest; 
% Check whether a controller is present 
% (This will always be the case for the tailor-made method) 
  cm=[1:CLIDmods(1,4)]; 
  if ~isempty(find(CLIDmods(17,cm)==1)) 
%   H = [1 + GC] H_est     
	sc=clobjget('C'); 
	st=clstack(sc,length(sc)-1,sgest,length(sgest)-1,'series'); 
	[a,b,c,d]=clsplit(st); 
	[a,b,c,d]=minreal(a,b,c,d); 
	st=[a b;c d+1]; 
	sh=clstack(shest,length(shest)-1,st,length(st)-1,'series'); 
  elseif get(findobj('tag','CLINPUTSIGNAL'),'userdata')~=2 
%   if a sensitivity has been constructed in the first step: 
%   H = inv(S_est) H_est     
	ss=clobjget('X'); 
	[a,b,c,d]=clsplit(ss); 
	dinv=inv(d); 
	ss=[a+b*dinv*c b*dinv; dinv*c dinv]; 
	sh=clstack(shest,length(shest)-1,ss,length(ss)-1,'series'); 
  else 
%   if a controller times sensitivity has been constructed in the 
%   first step: 
%   H = inv[I+ G G_x] H_est  with G_x the constructed CS. 
    ss=clobjget('X'); 
    [st,nst]=cltpc(ss,sg,length(ss)-1,length(sg)-1); 
	[a,b,c,d]=clsplit(st,nst); 
	[a,b,c,d]=minreal(a,b(:,2),c(2,:),d(2,2)); 
	st=[a b;c d]; 
	sh=clstack(shest,length(shest)-1,st,length(st)-1,'series'); 
  end 
% 
%**************************************************************** 
% 
%              Indirect method 
% 
%**************************************************************** 
elseif option==2 
  sc=clobjget('C'); 
  [ac,bc,cc,dc]=clsplit(sc); 
  smc=[ac bc;-cc -dc]; 
% Check the input signal that is used:   
  if get(findobj('tag','CLINPUTSIGNAL'),'userdata')~=2 
%   G = G_est [I - C G_est] 
    [st,nst]=cltpc(sgest,smc,length(sgest)-1,length(smc)-1); 
	[a,b,c,d]=clsplit(st,nst); 
	sg=[a b(:,2);c(1,:) d(1,2)]; 
  else 
%	G = G_est inv(I - G_est) inv(C) 
    smc=[0 1;0 -1]; 
    [st,nst]=cltpc(sgest,smc,length(sgest)-1,length(smc)-1); 
	[a,b,c,d]=clsplit(st,nst); 
	sgt=[a b(:,2);c(1,:) d(1,2)]; 
	dcinv=inv(dc); 
	scinv=[ac + bc*dcinv*cc bc*dcinv; dcinv*cc dcinv]; 
	sg=clstack(scinv,length(scinv)-1,sgt,length(sgt)-1,'series'); 
  end 
% H = [1 + GC] H_est     
  st=clstack(sc,length(sc)-1,sg,length(sg)-1,'series'); 
  [a,b,c,d]=clsplit(st); 
  [a,b,c,d]=minreal(a,b,c,d); 
  st=[a b;c d+1]; 
  sh=clstack(shest,length(shest)-1,st,length(st)-1,'series'); 
% 
%**************************************************************** 
% 
%              IV 
% 
%**************************************************************** 
elseif option==4 
  clobjins(th,'P',title); 
% 
%**************************************************************** 
% 
%              Coprime factor method 
% 
%**************************************************************** 
elseif option==5 & get(findobj('tag','CLIDENT'),'value')==2 
% Local oe identification 
  clobjins(th,'P',title); 
% 
elseif option==5 
  sc=clobjget('C'); 
  [sg,nsg]=cldn2sys(sgest,nsgest,'r'); 
  [a,b,c,d]=clsplit(shest,nshest); 
  [ah,bh,ch,dh]=minreal(a,b,c(2,:),d(2,:)); 
  shest=[ah bh;ch dh];nshest=length(ah); 
% H = [1 + GC] H_est     
  st=clstack(sc,length(sc)-1,sg,length(sg)-1,'series'); 
  [a,b,c,d]=clsplit(st); 
  [a,b,c,d]=minreal(a,b,c,d); 
  st=[a b;c d+1]; 
  sh=clstack(shest,length(shest)-1,st,length(st)-1,'series'); 
% 
%**************************************************************** 
% 
%              Dual-Youla method 
% 
%**************************************************************** 
elseif option==6 
  Cnd=clobjget('Cnd'); 
  [ac,bc,cc,dc]=clsplit(Cnd,size(Cnd,1)-2); 
  nCnd=length(ac); 
   
  Xnd=clobjget('Xnd'); 
  [ax,bx,cx,dx]=clsplit(Xnd,size(Xnd,1)-2); 
  nXnd=length(ax); 
 
  [sg,nsg]=clr2p(sgest,nsgest,Xnd,nXnd,Cnd,nCnd); 
% 
% H = [D_c + N_c G] H_est 
  sdc=[ac bc;cc(1,:) dc(1,:)]; 
  snc=[ac bc;cc(2,:) dc(2,:)]; 
  [st,nst]=clstack(sg,nsg,snc,nCnd,'series'); 
  [st,nst]=clstack(sdc,nCnd,st,nst,'add'); 
  [sh,nsh]=clstack(shest,nshest,st,nst,'series'); 
  [a,b,c,d]=clsplit(sh,nsh); 
  [a,b,c,d]=minreal(a,b,c,d); 
  sh=[a b;c d]; nsh=length(a); 
   
%**************************************************************** 
% 
%              Nonparametric identification 
% 
%**************************************************************** 
elseif option==7 
  info=' '; 
  clobjins(th,'P',title,info,0); 
end 
 
%**************************************************************** 
% 
%                Copy to model board 
% 
%**************************************************************** 
 
if (option==1 | option==2 | option==3 | option==6 |... 
   (option==5 & get(findobj('tag','CLIDENT'),'value')==3)), 
% Conversion of plant model G, H from system format into theta-format. 
  [ag,bg,cg,dg]=clsplit(sg); 
  ng=length(ag); 
  [ah,bh,ch,dh]=clsplit(sh); 
  nh=length(ah); 
  ch=ch/dh; 
  [numg,deng]=ss2tf(ag,bg,cg,dg,1); 
  [numh,denh]=ss2tf(ah,bh,ch,1,1); 
  thGH=poly2th(1,numg,numh,denh,deng,[],tsamp); 
%  MS=modstruc([nan*ag zeros(ng,nh);zeros(nh,ng) nan*ah],... 
%            [nan*bg;0*bh],[nan*cg nan*ch],nan*dg,[0*bg;nan*bh]); 
%  parval=[reshape(ag',1,ng*ng) reshape(ah',1,nh*nh) reshape(bg',1,ng) ... 
%    reshape(cg',1,ng) reshape(ch',1,nh) reshape(dg',1,1) reshape(bh',1,nh)]; 
%  thGH=ms2th(MS,'d',parval,[],tsamp); 
  clobjins(thGH,'P',title) 
end 
CLIDmnum(1,option)=CLIDmnum(1,option)+1; 
cllight(3);