% leadcomp.m - figure for a lead compesator
% RMM, 19 Nov 05

aminit;					% initialize MATALB

w = logspace(-2, 2, 200); s=i*w;
glead = 4 * (s + 0.25) ./ (s + 4);
gpd= s + 0.25;
glag = 0.25 * (s + 4) ./ (s + 0.25);
gpi = 0.25 * (s + 4) ./ s;

% Clear out any previous settings
figure(1); clf; axes('position', [0.13 0.55 0.3347 0.4]);
[magh, phaseh] = ambode(frd(glead, w));

% Magnitude
subplot(magh); hold on;
loglog(w, abs(gpd), '--', 'Color', [0 0.5 0], 'LineWidth', AM_bode_linewidth);
loglog(w, abs(glead), 'b-', 'LineWidth', AM_bode_linewidth);
hold on;
loglog([0.01 100], [1 1], 'k', 'LineWidth', AM_ref_linewidth);
hold on; loglog([0.25 0.25], [0.1 10], 'k:', [4 4], [0.1 10], 'k:', ...
  'LineWidth', AM_ref_linewidth);
amaxis([0.01 100 0.1 10]);
set(gca, 'XTickLabel', []);
ylabel('mag');

lgh = legend('Lead', 'PD', 'Location', 'southeast');
legend(lgh, 'boxoff');

% Phase
subplot(phaseh); hold on;
pl=semilogx(w, angle(glead)*180/pi, '-', w, angle(gpd)*180/pi,'--');
set(pl,'Linewidth',AM_bode_linewidth);
hold on; loglog([0.25 0.25], [0 90], 'k:', [4 4], [0 90], 'k:');
amaxis([0.01 100 0 95]);
set(gca, 'XTickLabel', [' ']);
set(gca, 'YTick', [0 45 90], 'YTickLabel', [0 45 90]);
text(0.25, -15, 'a');
text(4, -15, 'b');
xlabel('freq');
ylabel('phase');

amprint('leadcomp.eps');

% Clear out any previous settings
figure(2); clf; axes('position', [0.13 0.55 0.3347 0.4]);
[magh, phaseh] = ambode(frd(glag, w));

% Magnitude
subplot(magh); hold on;
loglog(w, abs(gpi), '--', 'LineWidth', AM_bode_linewidth, 'Color', [0 0.5 0]);
loglog(w, abs(glag), 'b-', 'LineWidth', AM_bode_linewidth);
hold on;
loglog([0.01 100], [1 1], 'k', 'LineWidth', AM_ref_linewidth);
hold on; loglog([0.25 0.25], [0.1 10], 'k:', [4 4], [0.1 10], 'k:', ...
  'LineWidth', AM_ref_linewidth);
amaxis([0.01 100 0.1 10]);
set(gca, 'XTickLabel', []);
ylabel('mag');

lgh = legend('Lag', 'PI', 'Location', 'northeast');
legend(lgh, 'boxoff');

% Phase
subplot(phaseh); hold on;
pl=semilogx(w, angle(glag)*180/pi, '-', w, angle(gpi)*180/pi,'--');
set(pl,'Linewidth',AM_bode_linewidth);
hold on; loglog([0.25 0.25], [-90 0], 'k:', [4 4], [-90 0], 'k:');
amaxis([0.01 100 -90 0]);
set(gca, 'XTickLabel', [' ']);
set(gca, 'YTick', [-90 -45 0], 'YTickLabel', [-90 -45 0]);
text(0.25, -105, 'b');
text(4, -105, 'a');
xlabel('freq');
ylabel('phase');

amprint('lagcomp.eps');

