% hall_loci_v2.m
% Adds the loci of constant gain of the complementary sensitivity 
% function to a Nyquist plot
%   kja 071212

aminit;

% Create patch vectors
M=1.1;cx1=-M^2/(M^2-1);r1=M/(M^2-1);
dpi=pi/200;xl=12; yl=r1*dpi; yh=xl;
X1=[-xl -xl];Y1=[-yh -yl];
for ff=-pi+dpi:dpi:pi-dpi;    
    X1=[X1 cx1+r1*cos(ff)];Y1=[Y1 r1*sin(ff)];
end
X1=[X1 -xl -xl];Y1=[Y1 yl yh];
M=1/M;cx2=-M^2/(M^2-1);r2=-M/(M^2-1);
X2=[xl xl];Y2=[yh yl];
for ff=dpi:dpi:2*pi-dpi,
    X2=[X2 cx2+r2*cos(ff)];Y2=[Y2 r2*sin(ff)];
end
X2=[X2 xl xl];Y2=[Y2 -yl -yh];
X=[X1 X2 -xl];Y=[Y1 Y2 -yh];
patch(X,Y,[0.8 0.8 0.8]);
hold on;
%
% Constant gain loci
MMt=[1.02 1.05 1.1 1.2 1.5 2];
s='b-';
for ii=1:6,
  M=MMt(ii);
  cx=M^2/(M^2-1);cy=0;r=M/(M^2-1);
  circplot(-cx,cy,r,s);hold on;
  M=1/M;
  cx=-M^2/(M^2-1);cy=0;r=M/(M^2-1);
  circplot(cx,cy,r,s);hold on;
end
%
% Constant phase loci
PP=pi*[10 20 40 60 80]/180;s=':';
for jj=1:5,
  fi=PP(jj);
  cx=-0.5;cy=0.5/tan(fi);r=0.5/sin(fi);
  circplot(cx,cy,r,s);
  circplot(cx,-cy,r,s);
end 
%
% Lines and axis
xxx=-xl:0.5:xl;one=ones(size(xxx));
pl=plot(-0.5*one,xxx,'b--');
set(pl,'Linewidth',1.5);
line([-xl xl], [0 0]);
line([0 0],[-yh yh]);
yx=(cx2-cx1)/2;
axis([-xl xl -yh yh]);
axis square
xlabel('re L(iw)');ylabel('imag L(iw)');
%set(gca,'Ytick',[-4 -2 0 2 4]);

amprint('hall-loci.eps');

