% cruise_spweight_bode.m - simulation of linear model with PI control
% kja 060727

aminit;
cruise_lin               %Get parameters of linear model

z0=1;w0=0.5;tmax=15;
w=logspace(-1,1);

% Sweep over parameter bp
figure(1); clf;
for bp=[0 0.5 1]
  % Compute controller parameters
  k=(a+2*z0*w0)/b;
  ki=w0^2/b;

  % Compute Gvr and Gvu
  den=[1 2*z0*w0 w0^2];
  Gvr=tf([bp*b*k b*ki],den);
  [aGvr,pGvr]=bode(Gvr,w);aGvr=aGvr(:)';
  Gur=tf(conv([bp*k ki],[1 -a]),den);
  [aGur,pGur]=bode(Gur,w);aGur=aGur(:)';

  % Plot
  subplot(321); 
  loglog(w, aGvr, 'b', 'Linewidth', AM_bode_linewidth);
  hold on;

  subplot(323); 
  loglog(w, aGur, 'b', 'Linewidth', AM_bode_linewidth);
  hold on;
end

subplot(321); hold on;
amaxis([0.1 10 0.01 2]); box on;
set(gca,'Ytick',[0.01 0.1 1])
set(gca,'Xtick',[0.1 1 10]);
ylabel('Gvr');

subplot(323); hold on;
amaxis([0.1 10 0.01 1]); box on;
set(gca,'Ytick',[0.01 0.1 1]);
set(gca,'Xtick',[0.1 1  10]);
ylabel('Gur');
xlabel('w');

amprint('cruise-spweight-bode.eps');
