% pidbode.m - sample Bode plot for Transfer Functions
% KJA, 200?

aminit;					% initialize parameters

% Use a PID controller as our example
C=tf([10 20 10],[1 0]);
n = 100;				% 100 points in plot
w=logspace(-2,2,n);			% entire frequency range
[ma, ph] = bode(C,w);			% generate Bode data
ma = ma(:); ph = ph(:);			% flatten out the data

% Generate the basic Bode plot
figure(1); clf; axes('position', [0.13 0.4096 0.7750 0.5]);
[magh, phaseh] = ambode(C, w);

% Asymptote in magnitude
mas=max(10./w,10*w);			% find peak
subplot(magh); hold on; loglog(w, mas, 'r--', 'Linewidth', AM_thick_linewidth);

% Redraw the magnitude on top of the asymptote
loglog(w, ma, 'b-', 'Linewidth', AM_bode_linewidth);

% Asymptote in phase
subplot(phaseh); hold on;
semilogx([0.01 0.1 10 100], [-90 -90 90 90], 'r--', ...
  'Linewidth', AM_thick_linewidth);
amaxis([0.01 100 -100 100]);

% Redraw the magnitude on top of the asymptote
semilogx(w, ph, 'b-', 'Linewidth', AM_bode_linewidth);

% Add a legend
lgh = legend('Actual', 'Approx', 'Location', 'southeast');
legend(lgh, 'boxoff');

amprint('pidbode.eps');
