prepare Bode grid

% Chapter 15 Exercise 9.
% — prepare Bode grid
mag = subplot(2,1,1);                  % get handle to upper plot
pha = subplot(2,1,2);                  % get handle to lower plot
noms = 50;                             % number of frequencies
om  = logspace(-2,2,noms);             % array of significant frequencies
ommin = om(1); ommax=om(noms);         % margins frequencies
magmin=-40;    magmax = 0;             % margins magnitude
phamin= 0;     phamax = 90;            % margins phase
magticks=linspace(magmin, magmax,5);
phaticks=linspace(phamin, phamax,5);

subplot(mag);
magmargs = [ommin ommax magmin, magmax];

semilogx(om, zeros(size(om)));
axis(magmargs);
set(gca,’YTick’,magticks);
grid on;
hold on;

subplot(pha);
phamargs = [ommin ommax phamin, phamax];
semilogx(om, zeros(size(om)));
axis(phamargs);
set(gca,’YTick’,phaticks);
grid on;
hold on;

% — compute and plot lead compensators
alphas = [sqrt(2) 2 2*sqrt(2) 4 4*sqrt(2)];
s     = sqrt(-1)*om;
for k=1:length(alphas),
al = alphas(k);
num = [1 1/al];
den = [1 al];
p   = polyval(num,s)./polyval(den,s);
pdb = 20*log10(abs(p));
pdeg= 180/pi*angle(p);

subplot(mag);
semilogx(om, pdb);

subplot(pha);
semilogx(om, pdeg);
end; % for loop