?? dstepb.m
字號:
function dstepb(Bsys,Tss,wcha)
global p n C1 C2 Cinf Mp tp tr Ts y t windstep
[bnum,bden]=tfdata(Bsys,'v');n=length(bnum);
for i=1:n
if bnum(i)==0
bnum1=bnum(i+1:n);
else
clear bnum;bnum=bnum1;break
end
end
p=roots(bden);ii=find(abs(p)>=1);n=length(ii);
if(n>0),disp('system is Unstable');
dcgwdisp=['系統不穩定!'];
helpdlg(dcgwdisp,'時域指標');break;
else,disp('system is stable'); % 判斷閉環系統的穩定性
t=0:Tss:5000; % 設置系統響應的時間間隔范圍
% 計算閉環系統階躍響應的參數
[y,t]=step(Bsys,t); n=length(t); Cinf=y(n); % Cinf為穩態終值
C1=Cinf+Cinf*wcha;C2=Cinf-Cinf*wcha; % C1,C2為上下誤差帶的兩個值
u1=find(C1<y);u2=find(C2>y); % u1為小于C1計算值集合下標的向量;
%u2為大于C2計算值集合下標的向量
u3=max(u1);u4=max(u2); % u3和u4分別為向量中的最大值,即為階躍響應輸出
%向量y中的元素進入上下誤差帶的最大下標值。
if u3>=u4,i=u3; % 判斷出u3,u4的最大值,并賦值給i
else
i=u4;
end
Ts=t(i); % 調節時間
Mp=max(y); % 最大超調量
tn=find(y==Mp);
tp=t(tn);
screen=get(0,'screensize');
winw=screen(3);winh=screen(4);
l8='采樣系統單位階躍響應; 誤差帶=';l9=num2str(wcha*100);l7='%';
l10=[l8,l9,l7];
windstep=figure('color',[1,1,1],'position',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],...
'name',l10,'numbertitle','off','menubar','figure',...
'resize','off');
step(Bsys) % 階躍響應的圖形
hold on
plot([tp,tp],[0,Mp],'k:')
Ts,y(i),plot([Ts,Ts],[0,y(i)],'k:')
plot([0,t(n)],[C1,C1],'r:')
plot([0,t(n)],[C2,C2],'r:')
text(tp,Mp,'Mp')
text(tp,0,'Tp')
text(Ts,0,'Ts')
syms s
%sys=tf(bnum,bden);[bnum,bden]=tfdata(sys,'v');
[numlength1 numlength2]=size(bnum);
[denlength1 denlength2]=size(bden);
l1=['('];
for i=1:numlength2-1
l1=[l1 num2str(bnum(1,i)) '*z^' num2str(numlength2-i) '+'];
end;
l1=[l1 num2str(bnum(1,numlength2)) ')'];
l2=['('];
for i=1:denlength2-1
l2=[l2 num2str(bden(1,i)) '*z^' num2str(denlength2-i) '+'];
end;
l2=[l2 num2str(bden(1,denlength2)) ')'];
l3=[l1 '/(' l2 ')'];
title(l3)
uicontrol(windstep,'style','push','string','穩態值',...
'position',[0.06,0.01,0.11,0.05],'units','normalized',...
'callback','dre_dcg');
uicontrol(windstep,'style','push','string','上升時間tr',...
'position',[0.22,0.01,0.11,0.05],'units','normalized',...
'callback','dre_tr');
uicontrol(windstep,'style','push','string','峰值時間tp和最大超調量Mp',...
'position',[0.37,0.01,0.25,0.05],'units','normalized',...
'callback','dtpmp');
uicontrol(windstep,'style','push','string','調整時間ts',...
'position',[0.66,0.01,0.11,0.05],'units','normalized',...
'callback','dre_ts');
uicontrol(windstep,'style','push','string','結束',...
'position',[0.83,0.01,0.11,0.05],'units','normalized',...
'callback','dfclosestep');
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -