?? design1.m
字號:
%**********************
%求給定極點配置的狀態(tài)反饋向量K
wind_demo6=figure('color',[1,1,1],'position',[0.05*winw,0.05*winh,0.9*winw,0.9*winh],...
'name','控制器設(shè)計:求給定極點配置的狀態(tài)反饋向量K','numbertitle','off','menubar','none',...
'resize','on','clipping','off');
color=[0.8;.8;.8];
uicontrol('style','frame','position',[0,0,1,1],...
'units','normalized','backgroundcolor',color);
pos=[0.02,0.93,0.18,0.03];
showtext(pos,color,'當(dāng)前系統(tǒng)狀態(tài)空間:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.75,.75,.18],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.88,0.03,0.03];
showtext(pos,color,'AK:');
demo_edita=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.88,0.7,0.04],...
'string',mat2str(ak),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.84,0.03,0.03];
showtext(pos,color,'BK:');
demo_editb=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.84,0.7,0.04],...
'string',mat2str(bk),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.8,0.03,0.03];
showtext(pos,color,'CK:');
demo_editc=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.8,0.7,0.04],...
'string',mat2str(ck),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.76,0.03,0.03];
showtext(pos,color,'DK:');
demo_editd=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.76,0.7,0.04],...
'string',mat2str(dk),'back',[0.95;.95;0.95],'units','normalized');
%*************
color=[0.9;.9;.9];
pos=[0.02,0.7,0.24,0.03];
showtext(pos,color,'當(dāng)前系統(tǒng)的開環(huán)極點為:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.64,.75,.06],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.65,0.03,0.03];
showtext(pos,color,'PK:');
%[z,p,k]=ss2zp(a,b,c,d,1);
pos=[0.06,0.65,.71,.03];
uicontrol(wind_demo6,'style','edit','pos',[0.07,0.65,0.7,0.04],...
'string',mat2str(pk),'back',[0.95;.95;0.95],'units','normalized');
%*************
color=[0.9;.9;0.9];
pos=[0.02,0.6,0.34,0.03];
showtext(pos,color,'輸入反饋后系統(tǒng)希望的閉環(huán)極點為:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.54,.75,.06],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.55,0.02,0.03];
showtext(pos,color,'P:');
demo_editp=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.55,0.7,0.04],...
'string','[ ]','back',[0.95;.95;0.95],'units','normalized');
%***************
color=[0.9;.9;0.9];
pos=[0.02,0.49,0.15,0.03];
showtext(pos,color,'系統(tǒng)的增益K為:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.43,.75,.05],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.44,0.02,0.03];
showtext(pos,color,'K:');
%***************
color=[0.9;.9;0.9];
pos=[0.02,0.39,0.2,0.03];
showtext(pos,color,'反饋后系統(tǒng)狀態(tài)空間:');
color=[.8;.8;.8];
uicontrol('style','frame','position',[0.025,0.21,.75,.18],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.34,0.02,0.03];showtext(pos,color,'A:');
pos=[0.03,0.30,0.02,0.03];showtext(pos,color,'B:');
pos=[0.03,0.26,0.02,0.03];showtext(pos,color,'C:');
pos=[0.03,0.22,0.02,0.03];showtext(pos,color,'D:');
%***************
color=[0.9;.9;0.9];
pos=[0.02,0.17,0.2,0.03];
showtext(pos,color,'反饋后系統(tǒng)傳遞函數(shù):');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.07,.75,.10],...
'units','normalized','backgroundcolor',color);
pos=[0.03,0.12,0.045,0.03];showtext(pos,color,'分子:');
pos=[0.03,0.08,0.045,0.03];showtext(pos,color,'分母:');
%***************
str1=['set(demo6_1,''enable'',''on'');set(demo6_3,''enable'',''on'');set(demo6_4,''enable'',''on'');',...
'demop=eval(get(demo_editp,''string''));',...
'kk=place(ak,bk,demop);',... %MIMO極點配置
'af=ak-bk*kk;bf=bk;cf=ck;df=dk;',...
'[numf,denf]=ss2tf(af,bf,cf,df,1);bnum=numf;bden=denf;',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.44,0.71,0.04],',...
' ''string'',mat2str(kk),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
% 'pos=[0.055,0.44,0.71,0.03],',...
%showtext(pos,color,mat2str(kk));'];
str2=['set(demo6_2,''enable'',''on'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.34,0.71,0.04],',...
' ''string'',mat2str(af),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.30,0.71,0.04],',...
' ''string'',mat2str(bf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.26,0.71,0.04],',...
' ''string'',mat2str(cf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.22,0.71,0.04],',...
' ''string'',mat2str(df),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
str3=['set(demo6_5,''enable'',''on'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.08,0.12,0.685,0.04],',...
' ''string'',mat2str(numf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.08,0.08,0.685,0.04],',...
' ''string'',mat2str(denf),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
str4=['wbode=figure(''color'',[.1,.7,.8],''position'',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],',...
' ''name'',''反饋前后閉環(huán)Bode圖對比分析'',''numbertitle'',''off'',''menubar'',''figure'',''resize'',''off'');',...
'[mag,phase,w]=bode(bnum,bden);',...
'subplot(2,2,1);semilogx(w,20*log10(mag));',...
'grid;ylabel(''幅值/db'');title(''系統(tǒng)反饋前Bode圖之幅值圖'');',...
'subplot(2,2,2);semilogx(w,phase);',...
'grid;ylabel(''相位/deg'');title(''系統(tǒng)反饋前Bode圖之相位圖'');',...
'[mag,phase,w]=bode(numf,denf);',...
'subplot(2,2,3);semilogx(w,20*log10(mag));',...
'grid;xlabel(''頻率'');ylabel(''幅值/db'');title(''系統(tǒng)反饋后Bode圖之幅值圖'');',...
'subplot(2,2,4);semilogx(w,phase);',...
'grid;xlabel(''頻率'');ylabel(''相位/deg'');title(''系統(tǒng)反饋后Bode圖之相位圖'');'];
str5=['t=[0:0.01:20];',...
'wstep=figure(''color'',[.1,0.7,.8],''position'',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],',...
' ''name'',''反饋前后Step階躍響應(yīng)對比分析'',''numbertitle'',''off'',''menubar'',''figure'',''resize'',''off'');',...
'dcg=dcgain(a,b,c,d);',...
'[yc x]=step(a,b,c,d,1,t);',...
'yc1=yc/dcg;',...
'subplot(2,1,1);',...
'plot(t,x,''r'',t,yc1,''b'');',...
'grid;xlabel(''s/t'');ylabel(''Y(t)和X(t)'');title(''反饋前藍線:Y(t)階躍響應(yīng);紅線:X(t)狀態(tài)曲線'');',...
'dcg=dcgain(af,bf,cf,df);',...
'[yc x]=step(af,bf,cf,df,1,t);',...
'yc1=yc/dcg;',...
'subplot(2,1,2);',...
'plot(t,x,''r'',t,yc1,''b'');',...
'grid;xlabel(''s/t'');ylabel(''Y(t)和X(t)'');title(''反饋后藍線:Y(t)階躍響應(yīng);紅線:X(t)狀態(tài)曲線'');'];
str6=['at=a;bt=b;ct=c;dt=d;numt=bnum;dent=bden;numt1=num;dent1=den;numt2=ffnum;dent2=ffden;',...
'a=af;b=bf;c=cf;d=df;bnum=numf;bden=denf;[num,den]=cloop(bnum,bden,1);ffnum=1;ffden=1;',...
'[ff,pp]=uiputfile(''*.mat'',''保存模型數(shù)據(jù)'',0.3*winw,0.4*winh);eval([''save '' pp,ff '' a b c d num den bnum bden ffnum ffden'']);test=1;',...
'a=at;b=bt;c=ct;d=dt;bnum=numt;bden=dent;num=numt1;den=dent1;ffnum=numt2;ffden=dent2;'];
uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','求狀態(tài)反饋向量K',...
'position',[0.8,0.85,0.18,0.06],'units','normalized',...
'callback',str1);
demo6_1=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','求反饋后狀態(tài)空間',...
'position',[0.8,0.75,0.18,0.06],'units','normalized','enable','off',...
'callback',str2);
demo6_2=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','求反饋后閉環(huán)傳遞函數(shù)',...
'position',[0.8,0.65,0.18,0.06],'units','normalized','enable','off',...
'callback',str3);
demo6_3=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','反饋前后閉環(huán)Bode圖',...
'position',[0.8,0.55,0.18,0.06],'units','normalized','enable','off',...
'callback',str4);
demo6_4=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','反饋前后Step圖',...
'position',[0.8,0.45,0.18,0.06],'units','normalized','enable','off',...
'callback',str5);
demo6_5=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','保存反饋后模型',...
'position',[0.8,0.35,0.18,0.06],'units','normalized','enable','off',...
'callback',str6);
uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','結(jié)束',...
'position',[0.8,0.25,0.18,0.06],'units','normalized',...
'callback','close(wind_demo6)');
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -