%PEAKS.M 
%Calculated peak values and total variation of a prototype second-order system
%T(s)=1/(tau^2*s^2+2*tau*zeta*s+1)
%Variables: tau and zeta must be defined before using the procedure.
%
T = nd2sys(1,[tau*tau 2*tau*zeta 1]); 
S = msub(1,T); 
[A,B,C,D]=unpck(T); 
if zeta<1,
%To get accurate results for small zeta (<0.1), you have to reduce 
%the value of 0.001, to extend simulation time, or increase the value
%of 100, to get shorter integral step. Warning: This will need large
%memory and take a long time for simulation.
  t=timvec(A,B,C,-A\B,0.001,100);
else,
  t=timvec(A,B,C,-A\B,0.1,30);
end
y=step(A,B,C,D,1,t);
Ov=max([y;1]); %Overshoot
Tv=sum(abs(diff([y;1]))); %Total Variation
mt=hinfnorm(T,1.e-4);
ms=hinfnorm(S,1.e-4);
Mt=mt(1);
Ms=ms(1);

