⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bstep.m

📁 详细介绍了Mathlab的使用方法与技巧
💻 M
字号:
function bstep(Bsys,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(p>=0);n=length(ii);
if(n>0),disp('system is Unstable');
    dcgwdisp=['系统不稳定!'];
   helpdlg(dcgwdisp,'时域指标');break;
else,disp('system is stable');                  % 判断闭环系统的稳定性
t=0:0.1:5000;                                  % 设置系统响应的时间间隔范围
% 计算闭环系统阶跃响应的参数
[y,x,t]=step(bnum,bden,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='系统输出Y(t)之单位阶跃响应;  误差带=';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(bnum,bden)                % 阶跃响应的图形
hold on
plot([tp,tp],[0,Mp],'k:')
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)) '*s^' num2str(numlength2-i) '+'];
  end;
  l1=[l1 num2str(bnum(1,numlength2)) ')'];
  l2=['('];
  for i=1:denlength2-1
     l2=[l2 num2str(bden(1,i)) '*s^' 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','re_dcg');
uicontrol(windstep,'style','push','string','上升时间tr',...
       'position',[0.22,0.01,0.11,0.05],'units','normalized',...
      'callback','re_tr');
uicontrol(windstep,'style','push','string','峰值时间tp和最大超调量Mp',...
       'position',[0.37,0.01,0.25,0.05],'units','normalized',...
      'callback','tpmp');
uicontrol(windstep,'style','push','string','调整时间ts',...
       'position',[0.66,0.01,0.11,0.05],'units','normalized',...
      'callback','re_ts');
uicontrol(windstep,'style','push','string','结束',...
       'position',[0.83,0.01,0.11,0.05],'units','normalized',...
      'callback','fclosestep');
  end
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -