%   loopshaping.m
%   Typical loop transfer function
%   kja080117

aminit;

k=22; a=1.5; b=80;
P = tf([k], [1 0 0]) * tf([5*b], [1 5*b]);
C = tf([b^2/a^2], [1 0]) * tf([1 2*a a^2], [1 2*b b^2]);
L = P*C;

subplot(221); 
[mag, phase, w] = bode(L, {0.1 1000});
loglog([0.01 10 1000], [1 1 1], 'k-+', 'LineWidth', AM_ref_linewidth);
hold on;
loglog(w, mag(:)); 
amaxis([0.1 1000 0.001 40000])
set(gca, 'XTick', [0.1 1 10 100 1000], 'XTickLabel', []);
set(gca, 'YTick', logspace(-3, 5, 9), 'YTickLabel', [], 'YMinorTick', 'off');
xlabel('Frequency'); ylabel('L');

amtext(10, 5, 'wgc', 'HorizontalAlignment', 'center');

% subplot(phaseh); hold on;
% semilogx([0.01 1000], [-180, -180], 'k', 'LineWidth', AM_ref_linewidth);
% amaxis([0.1 1000 -360 0])

subplot(222);
[magh, phaseh] = ambode(1/(1+L));

subplot(magh); 
[mag, phase, w] = bode(1/(1+L), {0.1 1000});
loglog([0.1 1000], [1 1], 'k', 'LineWidth', AM_ref_linewidth); hold on;
loglog(w, mag(:));
amaxis([0.1 1000 0.01 5]);
set(gca, 'XTick', [0.1 1 10 100 1000], 'XTickLabel', []);
set(gca, 'YTick', [0.01 0.1 1], 'YTickLabel', [], 'YMinorTick', 'off');
ylabel('S');

subplot(phaseh); 
[mag, phase, w] = bode(L/(1+L), {0.1 1000});
loglog([0.1 1000], [1 1], 'k', 'LineWidth', AM_ref_linewidth);
hold on;
loglog(w, mag(:)); 
amaxis([0.1 1000 0.01 5]);
set(gca, 'XTick', [0.1 1 10 100 1000], 'XTickLabel', []);
set(gca, 'YTick', [0.01 0.1 1], 'YTickLabel', [], 'YMinorTick', 'off');
xlabel('Frequency'); ylabel('T');

amprint('typicalbode.eps');
