% file name: tposts.m finding tp, os, and ts.
% TPOSTS Determines time for peak overshoot, peak overshoot and
% settling time. Inputs: time vector t and response vector
% y must be of same dimensions. If response has not settled
% there will be error. For settling to occur, integration
% size must be small enough and integration interval
% large enough.
function [tp, os, ts]=tposts(t,y)
% Check input data for acceptability
[mt,nt]=size(t); if (mt<nt), m=mt; mt=nt; nt=m; end
[my,ny]=size(y); if (my<ny), m=my; my=ny; ny=m; end
if (mt ~= my), error(' Input vectors are not of same size'), end
if (nt ~= ny), error('Input vectors are not of same size'), end
if (nt ~= 1), error('Input vectors are not of proper dimensions'), end
if y(my) < 0, y=-y; end
m5pc=ceil(mt/20);
if (m5pc < 10), error('not enough data points'), end
for i=1:m5pc
if (abs(y(mt-i)-y(mt))/y(mt) >= 0.001)
error('steady state may not have reached')
end %if
end %for
% Finding peak time and overshoot
yss=y(mt);
[yp,kp]=max(y);
os=(yp-yss)/yss;
tp=t(kp);
% Finding settling time.
k=mt;
while abs((y(k)-yss)/yss ) <= .02,
k=k-1;
end
k=k+1; % to bring back y(k) within 2%
ys=y(k); % +- 2% steady state value
ts=t(k); % setlling time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
