声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1263|回复: 1

[编程技巧] 阶跃响应调节时间 MATLAB程序

[复制链接]
发表于 2010-3-16 15:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
求系统单位阶跃给定响应性能指标matlab程序哪里错了?

参照网友程序编写的求阶跃响应调节时间的程序,运行总是有误,
烦请高手指点,或是原程序的出处。谢谢
function [sigma,tp,ts]=perf(key,y,t)
%其中key用来选择调节时间的%5或%2误差,当key=1时表示选择%5误差带,
%key=2表示选择%2误差带。
%count sigma and tp
[mp,tf]=max(y);
cs=length(t);
yss=y(cs);
sigma=100*(mp-yss)/yss
tp=t(tf)
%count ts
i=cs+1;
n=0;
while n==0,
    i=i-1;
    if key==1
        if i==1
            n=1;
        elseif y(i)>1.05*yss
            n=1;
        end
    elseif key==2,
        if i==1,n=1;
        elseif y(i)>1.02*yss
            n=1;
        end
    end
end
t1=t(i);
cs=lengt(t);
j=cs+1;
n=0;
while n==0,
    j=j-1;
    if key==1
        if j==1
            n=1;
        elseif y(j)<0.95*yss
            n=1;
        end
    elseif key==2
        if j==1
            n=1;
        elseif y(j)<0.98*yss
            n=1;
        end
    end
end
t2=t(j);
if t2<tp
    if t1>t2
        ts=t1;
    end
elseif t2>tp
    if t2<t1
        ts=t2;
    else
        ts=t1;
    end
end



回复
分享到:

使用道具 举报

发表于 2010-3-16 20:08 | 显示全部楼层
什么错误 把它贴出来
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 07:20 , Processed in 0.053889 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表