aminit;

%Starks data
w=2:0.5:30;s=i*w;one=ones(size(w));
a=12;G=0.17*a^3./(s+a).^3;
Gd=G.*exp(-0.2*s);
dat=[-13.2 6.5   -4  ;
   -6   5.7 -4.5  ;
   -2   2   -8    ;
   3.5  5.5 -9    ;
   3.5  3   -10    ;
   3.5  1   -10.5    ;
   10.5 -9.5 -19.5   ;
   12   -12.5 -21  ;
   13   -12  -24   ;
   14.5 -12  -26   ;
   15.5 -23  -28];
dat1=[2.^(dat(:,1)./10) 0.1*2.^(dat(:,2)/10) 540*dat(:,3)/37];
dat2=[-6 13   -6;
   9     11   -8.5;
   16.5   3.5 -13.5;
   27.5   6   -20;
   28     2   -18.5;
   28.5  10.5 -20.5;
   42   -18.5 -33.5;
   44   -12   -38;
   46   -24.5 -42;
   49.5 -24   -47;
   52   -45   -51.5;
   55   -45   -54];
dat3=[0.5*2.^(dat2(:,1)/20.5) 0.1*2.^(dat2(:,2)/20.5) 360*dat2(:,3)/36.5];

% Generate the bode plot using standard commands
figure(1); clf; subplot(221); 
[magh, phaseh] = ambode(tf([0.17*a^3], [1 3*a 3*a^2 a^3]), {0.1 1});

subplot(magh); hold on;
pl1 = loglog(2*pi*dat3(:,1), dat3(:,2), 'ro', 'Markersize', AM_data_markersize);
pl3 = loglog(w, abs(G), 'Linewidth', AM_bode_linewidth);

set(gca,'Ytick',[0.01 0.02 0.05 0.10 0.20]);
set(gca,'Xtick',[2 5 10 20])
amaxis([2 22 0.01 0.3])

lgh = legend(gca, [pl1; pl3], 'Measured', 'Model', 'Location', 'southwest');
legend(lgh, 'boxoff');

subplot(phaseh); hold on;
pl3 = semilogx(w, 180*unwrap(angle(G))/pi, 'g--', 'Color', [0 0.5 0]);
semilogx(2*pi*dat3(:,1), dat3(:,3), 'ro', 'Markersize', AM_data_markersize);
semilogx(w, 180*unwrap(angle(Gd))/pi, 'b-');
semilogx(w, -180*one, 'k-', 'Linewidth', AM_ref_linewidth);
set(gca,'Xtick',[2 5 10 20]);
set(gca,'Ytick',[-360 -180 0])
amaxis([2 22 -400 0])

lgh = legend(gca, [pl3], 'Model w/out delay', 'Location', 'southwest');
legend(lgh, 'boxoff');


amprint('pupil-bode.eps');
