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

📄 matlab real system parameter calculation.txt

📁 matlab 实现系统的参数计算
💻 TXT
字号:
matlab 实现系统的参数计算 

function f =sys2step(num,den,xt)
%%%%#######################################################%%%%%
%%系统单位阶跃响应的相关参数计算%%
% f=sys2step(num,den,T) 计算系统 G(s)=[num]/[den]的阶跃响应的相关参数
%     其中默认T为100;uses the user-supplied time vector T forsimulation. 
%      For discrete-time models, T should be of the form    Ti:Ts:Tf 
%     where Ts is the sample time.    For continuous-time models,
%      T should be of the form  Ti:dt:Tf where dt will become the sample 
%      time for the discrete approximation to the continuous system.    The
%      step input is always assumed to start at t=0 (regardless of Ti).
%
%     输出f为1*7的矩阵,f(1)为系统输出终值,f(2)为系统峰值,f(3)
%     为峰值时间,f(4)为系统延迟时间,f(5)为系统上升时间,
%     f(6)为系统调节时间,f(7)为系统超调量。
%% 
%%   
%%%%########################    #########################%%%%%

%%建立系统

if nargin ==2
      xt=100;
end
disp('========The system ========');
sys1=tf(num,den)
disp('===========================');
[y,t] = step(sys1,xt);
subplot(3,2,[1,2]);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('The step of system');
m=y(1);
lt=length(t);
for i=1:lt    %%找最大输出
      if y(i)>m;
          m=y(i);
      end
end
for i=1:lt %%找第一个最大输出值时间
          if y(i)==m
              max=y(i);         
              tt=t(i);
              a=i;
              break;
          end
end
subplot(3,2,[3 4 5 6]);
plot(t,y);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('The step of system');
axis([-0.5 tt+6 0 max+0.05]);
grid on;
      for i=a:lt %%确定有效输出长度
          if y(i)==0
              lt=i;
           break;
          end
      end
%%
disp('=====稳定输出:');
lim=(y(lt)+y(lt-1)+y(lt-2)+y(lt-3))./4    %%求最终输出
if lim<m     %%判断是否存在峰值输出
        for i=1:lt
          if y(i)==m
              disp('=====The max output of eyetem    :');
              max=y(i)
              disp('=====峰值时间    :');
              tp=t(i)
              a=i;
              break;
          end
        end
          else disp('======The system do not have max output====== ');
              a=1;
end
      for i=1:lt %%计算延迟时间
            if y(i)<lim+0.05&y(i)>lim-0.05
                  disp('=====The dely time    is    :');
                   td=t(i)./2
                  break;
            end
      end
      for i=1:lt %%计算上升时间
              if y(i)<0.1*lim&y(i)>0.02*lim
                  t1=t(i);
                  break;
              end
      end
for i=1:lt 
          if    y(i)<0.94*lim&y(i)>0.86*lim
              t2=t(i);
              break;
          end
end
disp('=====系统阶跃响应上升时间    :');
tu=t2-t1
%%%计算调节时间
lim1 = 1.05*lim;
lim2 = 0.95*lim;
j=0;
for i=a:lt
      if y(i)<lim1 & y(i)>lim2 
          for j=lt:-1:i
              if y(j)<lim1 & y(j)>lim2 
                  ts=t(j);           
              else break;
              end
          end
      end
      if j==i
          break;
      end
end
disp('=====系统调节时间    :');
             ts=t(i)

%%计算超调量 u
disp('=====系统超调量    :');
u=(max-lim)./max
disp('========The system ========');
sys1=tf(num,den)
disp('===========================');
disp('======f=[lim,max,tp,td,tu,ts,u]');
f=[lim,max,tp,td,tu,ts,u]
%%%%%%%%%%%%%%%%%%%%%    Thank     you!!     %%%%%%%%%%%%%%%%%%%%%%%%%%%% 

 

⌨️ 快捷键说明

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