📄 mimo_tune.m
字号:
function Epsilon=mimo_tune(fun,f,Mp,y,vub,vlb,E_handle,ps,ms,qs,order,...
L_handle,input_delay,dec_M,pd_prime,pds,M1_handle,decade,tune_index,tole)
% This function bring the magnitude of the worse plant, Mp, of the diagonal elements
% to the reqiured Mp.
global Xwc_ub_w Tune_flag Epsilon
if strcmp(fun,'mimo1sen') | strcmp(fun,'mimo2sen')
errordlg('No tuning available for this frequency response');
n=length(order);
for i=1:n
Epsilon{1}(i)=str2num(get(E_handle(i),'String'));
if strcmp(fun,'mimo2com') | strcmp(fun,'mimo2sen')| strcmp(fun,'mimopartial')
Epsilon{2}(i)=str2num(get(E_handle(n+i),'String'));
end
end
return
end
n=length(order);
if tune_index==2 & (isempty(Tune_flag) | ~all(Tune_flag))
errordlg(['To tune the Mp of the diagonal elements by the SIMPLE tuning, ALL',...
' DIAGONAL ELEMENTs of the upper bound must be re-computed first!']);
for i=1:n
Epsilon{1}(i)=str2num(get(E_handle(i),'String'));
end
return
end
if tune_index==1 & (isempty(Tune_flag) | ~all(Tune_flag))
for i=1:n
Tune_flag(i)=i;
end
end
figure(f);
Mp=Mp(find(Tune_flag));
temp1=max(Mp);
for i=1:n
Epsilon{1}(i)=str2num(get(E_handle(i),'String'));
if strcmp(fun,'mimo2com') | strcmp(fun,'mimopartial')
Epsilon{2}(i)=str2num(get(E_handle(n+i),'String'));
mq{i}=mq_gen(1,1,dec_M(i),1,1,order(i),y);
[qd{i,i},qdnum{i,i},qdden{i,i}]=qd_mat(pd_prime{i,i},mq{i},Epsilon{2}(i),order(i),y);
qd{i,i}=strrep(qd{i,i},'e',['e(' num2str(i) ')']);
end
if Tune_flag(i)
temp1=max([temp1 ; Xwc_ub_w{i,i}(:,1)]);
end
end
y_limit=[min(Mp)-0.1 round(100*(temp1+0.05))/100];
if length(y_limit)==2
set(L_handle(1),'String',num2str(y_limit(2)));
set(L_handle(2),'String',num2str(y_limit(1)));
temp=axis;
axis([temp(1:2) y_limit]);
end
% Tune_flag
for i=1:n
if Tune_flag(i)
[temp,temp1]=max(Xwc_ub_w{i,i}(:,1));
xwc(i,:)=Xwc_ub_w{i,i}(temp1,2:end);
else
xwc(i,:)=[1 (vub+vlb)/2];
end
end
option=optimset('LargeScale','off','Display','off');
if tune_index==2
solver='tune_solve';
if strcmp(fun,'mimo1com')
qds='';
Epsilon{1}
Epsilon{1}=fsolve(solver,4*Epsilon{1},option,...
fun,xwc,Mp,vub,vlb,y,ps,ms,qs,order,input_delay,pds,qds);
for i=1:n
set(E_handle(i),'String',num2str(Epsilon{1}(i)));
end
else
qds=cell2str(qd);
if strcmp(fun,'mimopartial')
Epsilon{2}=fsolve(solver,Epsilon{2},option,...
fun,xwc,Mp,vub,vlb,y,ps,ms,qs,order,input_delay,pds,qds);
for i=1:n
set(E_handle(n+i),'String',num2str(Epsilon{2}(i)));
end
else
Epsilon{1}=fsolve(solver,Epsilon{1},option,...
fun,xwc,Mp,vub,vlb,y,ps,ms,qs,order,input_delay,pds,qds);
for i=1:n
set(E_handle(i),'String',num2str(Epsilon{1}(i)));
end
end
end
% Plot the frequency response of the worse case plants
% after the filetr time constant is changed.
for i=1:n
bg_color=get(M1_handle(n*(i-1)+i),'Backgroundcolor');
if Tune_flag(i)
freq=Xwc_ub_w{i,i}(:,2)';
[temp,temp1]=max(Xwc_ub_w{i,i}(:,1)');
x=Xwc_ub_w{i,i}(temp1,3:end);
data{i}=zeros(1,length(freq));
for k=1:length(freq)
data{i}(k)=feval(fun,x,y,Epsilon,1,freq(k),...
ps,ms,qs,order,i,i,input_delay,pds,qds);
end
end
end
else % if tune index==1 (Use the intensive tuning)
if strcmp(fun,'mimo1com')
qds='';
[Epsilon,XWC]=tune_solve1(Epsilon,fun,xwc,Mp,vub,vlb,y,ps,ms,qs,...
order,input_delay,pd_prime,pds,qds,E_handle,tole);
for i=1:n
set(E_handle(i),'String',num2str(Epsilon{1}(i)));
end
else
%qds=cell2str(qd);
[Epsilon,XWC]=tune_solve1(Epsilon,fun,xwc,Mp,vub,vlb,y,ps,ms,qs,...
order,input_delay,pd_prime,pds,mq,E_handle,tole);
if strcmp(fun,'mimopartial')
for i=1:n
set(E_handle(n+i),'String',num2str(Epsilon{2}(i)));
end
else
for i=1:n
set(E_handle(i),'String',num2str(Epsilon{1}(i)));
end
end
end
% Plot the frequency response of the worse case plants
% after the filetr time constant is changed.
for i=1:n
bg_color=get(M1_handle(n*(i-1)+i),'Backgroundcolor');
freq=Xwc_ub_w{i,i}(:,2)';
data{i}=zeros(1,length(freq));
temp=length(XWC(i,:));
for k=1:length(freq)
data{i}(k)=feval(fun,XWC(i,1:temp-1),y,Epsilon,1,freq(k),...
ps,ms,qs,order,i,i,input_delay,pds,qds);
end
Tune_flag(i)=i;
end
end
figure(f);
for i=1:n
bg_color=get(M1_handle(n*(i-1)+i),'Backgroundcolor');
if Tune_flag(i)
g=loglog(Xwc_ub_w{i,i}(:,2),data{i}',':',10.^decade,[Mp(i) Mp(i)],'-.');
set(g,'color',bg_color);
h=text(mean(10.^decade)/2,Mp(i),['Mp = ' num2str(Mp(i))]);
set(h,'color',bg_color,'VerticalAlignment','bottom');
end
if i==1
hold on
end
end
hold off
y_limit=get(gca,'YLim');
temp=(log(y_limit(2))-log(y_limit(1)))/20;
h=text(10.^decade(1)*1.2,exp(log(y_limit(2))-temp),'- - - - - Expected worse case response with the new filter time constants');
set(h,'color',bg_color,'VerticalAlignment','bottom');
h=text(10.^decade(1)*1.2,exp(log(y_limit(2))-2*temp),'_____ Original upper bounds','Interpreter','none');
set(h,'color',bg_color,'VerticalAlignment','bottom');
Tune_flag=zeros(1,n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -