Unwrap

% Chapter 15 Exercise 7.
% —  UNWRAP, from Control Toolbox
% — USES some functions not available in MATLAB prior to level 4.0
%     Users of old versions are suggested to simply delete the
%     offending lines. The result will be esthetically less
%     pleasant, but still corrct.

k   = 5;
R   = 6;
al  = 4;
omn = 20;
zi  = 0.6;

num = k*conv([1/(R/al) 1],[0 0 0 omn^2]);
den = conv([1/(R*al) 1],conv([1 0],[1 2*zi*omn omn^2]));

om  = logspace(-1,3);
s   = sqrt(-1)*om;
ol  = polyval(num,s)./polyval(den,s);  % open loop transfer function
cl  = ol./(1+ol);                      % closed loop transfer function
cldb = 20*log10(abs(cl));              % its magnitude, db
cldeg= 180/pi*unwrap(angle(cl));       % its phase, degrees
subplot(2,1,1);
semilogx(om, cldb); grid               % magnitude plot
subplot(2,1,2);
semilogx(om, cldeg); grid              % phase plot

phaaxis   = [0.01 100 -270 0];         % extremes of phse plot
phaticks  =-270:90:0;                  % ticks
axis(phaaxis);                         % define extremes
set(gca,’Ytick’,phaticks);             % define ticks position