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

📄 dsmystep.m

📁 详细介绍了Mathlab的使用方法与技巧
💻 M
字号:
%   t=[0:0.01:20];
   if szsystem==2
   dwmystep
   else
if stepabcd==1
   windstep=figure('color',[0.1,0.7,0.8],'position',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],...
       'name','离散系统S域输出Y(t)和状态X(t)之阶跃响应','numbertitle','off','menubar','figure',...
       'resize','off');
 end
  if stepabcd==0;
    figure(windstep)
 end

 stepabcd=0;
 
%以上完成系统的阶跃响应曲线作图
rr1=size(bnum);
rr2=size(bden);
finderr=0;
%判断是否为比例环节
if ((rr1(1,2)==1)&(rr2(1,2)==1)),
   finderr=1;
   dcg=dcgain(bnum,bden);
   [yc x]=step(bnum,bden);
   nsn=length(yc);t=1:nsn;
%   [yc x]=step(bnum,bden,t);
   yc1=yc/dcg;
   subplot(1,1,1);
   plot(t,yc1,'r',t,yc,'b');
   grid on;hold on
   xlabel('s/t');
   ylabel('Y(t)/dcg');
   legend('红线:Y(t)/dcg阶跃响应曲线','蓝线:Y(t)阶跃响应曲线',0);
   strtext=['这是比例环节,系统指标: 稳态值=' num2str(dcg) ' ; tr,tp,Mp,ts 无意义 '];
   title(strtext);
else,
%判断是否为积分环节
findjf1=0;
findjf2=0;
for i=1:1:rr1(1,2)-1
   if bnum(1,i)==0,
   else,findjf1=1;break;
   end
end
if bden(1,rr2(1,2))==0,
   for i=1:1:rr2(1,2)-2
     if bden(1,i)==0,
     else,findjf2=1;break;
     end
   end
else,
   findjf2=1;
end
if (findjf1==0&findjf2==0),
   finderr=1;
   dcg=dcgain(a,b,c,d);
   [yc x]=step(a,b,c,d,1);
 %  [yc x]=step(a,b,c,d,1,t);
   nsn=length(yc);t=1:nsn;
   
   yc1=yc/dcg;
   subplot(2,1,1);
   plot(t,x,'r');
   grid on;hold on
   xlabel('s/t');
   ylabel('X(t)');
   legend('红线:X(t)状态曲线',0);
   title('X(t)状态曲线');
   subplot(2,1,2);
   grid on;hold on
   step(a,b,c,d,1);
 %  plot(t,yc1,'r',t,yc,'b');
   grid on;hold on
   xlabel('s/t');
   ylabel('Y(t)和Y(t)/dcg');
   legend('红线:Y(t)/dcg阶跃响应曲线','蓝线:Y(t)阶跃响应曲线',0);
   strtext=[' 这是积分环节,无稳态值且tr,tp,Mp,ts 无意义 '];
   title(strtext);
end
end
if finderr==0,
dcg=dcgain(a,b,c,d);
Cinf=dcg;
%[yc x]=step(a,b,c,d,1,t);

[yc x]=step(a,b,c,d,1);
nsn=length(yc);t=1:nsn;

yc1=yc/dcg;
subplot(2,1,1);
plot(t,x,'r');
grid on;hold on
xlabel('s/t');
ylabel('X(t)');
legend('红线:X(t)状态曲线',0);
title('X(t)状态曲线');
subplot(2,1,2);
%plot(t,yc1,'r',t,yc,'b');
grid on;hold on
step(a,b,c,d,1)
%plot(t,yc,'b')
grid on;hold on
ylabel('Y(t)和Y(t)/dcg');
%legend('红线:Y(t)/dcg阶跃响应曲线','蓝线:Y(t)阶跃响应曲线',0);
%********************
[z p]=tf2zp(bnum,bden);
ii=find(real(p)>0);n1=length(ii);
if (n1<=0),%系统稳定
  syms s t;
  [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 '/(s*' l2 ')'];
  fun=ilaplace(eval(l3));
  %以上进行逆拉氏变换得出系统在阶跃输入下的时间响应函数
  ycn=step(bnum,bden);
  tn=length(ycn);
  ty=0:0.01:tn;cin=length(ty);
  ycnn=step(bnum,bden,ty);
  [z,p]=tf2zp(bnum,bden);
  
  
uicontrol(windstep,'style','push','string','稳态值',...
       'position',[0.06,0.01,0.11,0.05],'units','normalized',...
      'callback','mysteppre_dcg');
uicontrol(windstep,'style','push','string','上升时间tr',...
       'position',[0.22,0.01,0.11,0.05],'units','normalized',...
      'callback','mysteppre_tr');
uicontrol(windstep,'style','push','string','峰值时间tp和最大超调量Mp',...
       'position',[0.37,0.01,0.25,0.05],'units','normalized',...
      'callback','mysteppre_tpmp');
uicontrol(windstep,'style','push','string','调整时间ts',...
       'position',[0.66,0.01,0.11,0.05],'units','normalized',...
      'callback','mysteppre_ts');
uicontrol(windstep,'style','push','string','结束',...
       'position',[0.83,0.01,0.11,0.05],'units','normalized',...
      'callback','closestep');
else,
  strtext=['系统不稳定,系统指标dcg,tr,tp,mp,ts无法计算!'];title(strtext);
end
end
%else
%   abcdefg=0;
%   ksys=tf(bnum,bden);
%   ltiview('step',ksys)
%end
end
%end

⌨️ 快捷键说明

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