% Generates Fig 5.13
% Computer Controlled Systems (3rd ed)
% Author: B. Wittenmark
% Last edit: 1997-07-02
% Copyright (c) 1996 by K. J. Åström, B. Wittenmark and
% Department of Automatic Control, Lund Institute of
% Technology, Lund, Sweden

close all; clear all;

newplot;
set(gcf,'PaperUnits','centimeters','PaperPosition',[2 2 13 10])
set(gcf,'Units','centimeters','position',get(gcf,'PaperPosition'))

lw=2;
K=1;
a=2;
z=0.707;
an=0.01;
wn=2;
td=50;
tn=100;
l0=-0.05;
x10=0;
x20=0;
h=1;
w=0.2;
%
wh=w*h;
z1=sqrt(1-z*z);
a1m=-2*exp(-z*wh)*cos(z1*wh);
a2m=exp(-2*z*wh);
ams=1+a1m+a2m;

ae=exp(-a*h);
a1o=-2*ae;
a2o=ae*ae;
aos=1+a1o+a2o;
amp=2+a1m;
aop=2+a1o;

p1=ams*aos;
pp=amp*aos+ams*aop;
p2p=2*(ams+amp*aop+aos);
h2=h*h;
s0=(p1/4-pp/2+p2p/2)/h2;
s1=(-p1+2*pp-p2p)/h2;
s2p=(7*p1/4-3*pp/2+p2p/2);
s2=s2p/h2;
r=s2p/2-a2m*a2o;
r1=r-1;
r2=-r;
t0=ams/h2;
t1=t0*a1o;
t2=t0*a2o;
%
clf;
%
[t,x,y]=sim('block510',[0, 150]);
subplot(3,1,1);
plot(t,y(:,3),'k-',t,y(:,1),'k','Linew',lw);
axis([0,150,0,1.2]);
set(gca,'FontSize',9,'Fontname','NewCenturySchlbk')
set(gca,'xtick',[0 50 100 150]);
set(gca,'ytick',[0 1]);
ylabel('Output','Fontname','NewCenturySchlbk','Fontsize',9)
%title(['Fig 5.13']);
text(-18,1.2,'(a)','Fontname','NewCenturySchlbk','Fontsize',9)
drawnow;
hold on
title('h=1(k), 2(b), 0.1(r); [\zeta=0.707, w = 0.2; \alpha=2]' )

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h=2;
%
wh=w*h;
z1=sqrt(1-z*z);
a1m=-2*exp(-z*wh)*cos(z1*wh);
a2m=exp(-2*z*wh);
ams=1+a1m+a2m;

ae=exp(-a*h);
a1o=-2*ae;
a2o=ae*ae;
aos=1+a1o+a2o;
amp=2+a1m;
aop=2+a1o;

p1=ams*aos;
pp=amp*aos+ams*aop;
p2p=2*(ams+amp*aop+aos);
h2=h*h;
s0=(p1/4-pp/2+p2p/2)/h2;
s1=(-p1+2*pp-p2p)/h2;
s2p=(7*p1/4-3*pp/2+p2p/2);
s2=s2p/h2;
r=s2p/2-a2m*a2o;
r1=r-1;
r2=-r;
t0=ams/h2;
t1=t0*a1o;
t2=t0*a2o;
%
%
[t,x,y]=sim('block510',[0, 150]);
subplot(3,1,1);
plot(t,y(:,1),'b--','Linew',lw);
axis([0,150,0,1.2]);
drawnow;
%
subplot(3,1,2);
[ts,ys]=stairs(t,y(:,2));
plot(ts,ys,'b','Linew',lw);
axis([0,150,-0.035,0.13]);
set(gca,'FontSize',9,'Fontname','NewCenturySchlbk')
set(gca,'xtick',[0 50 100 150]);
set(gca,'ytick',[0 0.1]);
ylabel('Input','Fontname','NewCenturySchlbk','Fontsize',9)
text(-18,0.13,'(b)','Fontname','NewCenturySchlbk','Fontsize',9)
drawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h=0.1;
%
wh=w*h;
z1=sqrt(1-z*z);
a1m=-2*exp(-z*wh)*cos(z1*wh);
a2m=exp(-2*z*wh);
ams=1+a1m+a2m;

ae=exp(-a*h);
a1o=-2*ae;
a2o=ae*ae;
aos=1+a1o+a2o;
amp=2+a1m;
aop=2+a1o;

p1=ams*aos;
pp=amp*aos+ams*aop;
p2p=2*(ams+amp*aop+aos);
h2=h*h;
s0=(p1/4-pp/2+p2p/2)/h2;
s1=(-p1+2*pp-p2p)/h2;
s2p=(7*p1/4-3*pp/2+p2p/2);
s2=s2p/h2;
r=s2p/2-a2m*a2o;
r1=r-1;
r2=-r;
t0=ams/h2;
t1=t0*a1o;
t2=t0*a2o;
%
[t,x,y]=sim('block510',[0, 150]);
subplot(3,1,1);
plot(t,y(:,1),'r-.','Linew',lw);
axis([0,150,0,1.2]);
drawnow;
%
subplot(3,1,3);
[ts,ys]=stairs(t,y(:,2));
plot(ts,ys,'r','Linew',lw);
axis([0,150,-0.035,0.13]);
set(gca,'FontSize',9,'Fontname','NewCenturySchlbk')
set(gca,'xtick',[0 50 100 150]);
set(gca,'ytick',[0 0.1]);
ylabel('Input','Fontname','NewCenturySchlbk','Fontsize',9)
xlabel('Time','Fontname','NewCenturySchlbk','Fontsize',9)
text(-18,0.13,'(c)','Fontname','NewCenturySchlbk','Fontsize',9)
drawnow;
ylblalgn;
