%Comparison of models
% kja 060712

aminit;					% initialize macros

t=0:0.02:10;
T=0.025;
k=100;
A=conv([T 1],[T 1]);
A=conv(A,[1 1]);
P1=tf(k,[1 1]);
P2=tf(k,A); 
clp=A+[0 0 0 k];
roots(clp);
yp1=step(P1,t);
yp2=step(P2,t);

figure(1); clf;
subplot(321)
pl=plot(t,yp1,'-',t,yp2,'--');
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 5 0 100])
title('Open loop')
ylabel('y');

lgh = legend('System 1', 'System 2', 'Location', 'southeast');
legend(lgh, 'boxoff');

%--------------------
t2=0:0.01:1;
T1=feedback(P1,1);
T2=feedback(P2,1);
yt1=step(T1,t2);
yt2=step(T2,t2);

subplot(323)
pl=plot(t2,yt1,'-',t2,yt2,'--');
set(pl,'Linewidth', AM_data_linewidth);
amaxis([0 0.5 -1 3])
title('Closed loop')
xlabel('t');ylabel('y');

amprint('modcomp1.eps');

figure(2); clf;

%--------------------
P3=tf(100,[1 1]);
P4=tf(100,[1 -1]);
yp3=step(P3,t);
yp4=step(P4,t);

subplot(321)
pl=plot(t,yp3,'-',t,yp4,'--')
set(pl,'Linewidth', AM_data_linewidth);
amaxis([0 2 0 500]);
title('Open loop')
ylabel('y');

lgh = legend('System 1', 'System 2', 'Location', 'northwest');
legend(lgh, 'boxoff');

%--------------------
t4=0:0.001:0.1;
T3=feedback(P3,1);
T4=feedback(P4,1);
yt3=step(T3,t4);
yt4=step(T4,t4);

subplot(323)
pl=plot(t4,yt3,'-',t4,yt4,'--');
set(pl,'Linewidth', AM_data_linewidth);
amaxis([0 0.1 -0 1.2]);
title('Closed loop')
xlabel('t');ylabel('y');


amprint('modcomp2.eps');
