%G. Vinnicombe. original version 1993, updated for Matlab 5, Oct 1998

aminit;
figure(1); clf;

%sflag =0, no hidden lines =1 dashed hidden lines, =2 solid hidden lines 
mags=[ .1 .2 1/2.5 1/1.5 1 1.5 2.5 5 10];
thetas=[0 45 90 135];
thd=15,phid=-25;
sflag=0;
if phid<0;phid=phid+360;end

%x to left, y +ve away
r=.5;th=thd/180*pi
plot(circ(r*j, r), 'k-', 'LineWidth', AM_ref_linewidth);
hold on
n=max(size(mags));

%x-axis
z=0*ones(46,1);
%x=[-1.34 linspace(-1.34,1.34,40) 1.35 1.33  1.35 1.33 1.35]';
%y=[0 0 zeros(1,40)  .02  0   -.02 0]';
x=[linspace(-2.1,2.2,46)]';
y=zeros(46,1);
f=plotsp(phid, thd, [x y z], 1, 'k');               %Real axis
amtext(real(f(46))+0.05, imag(f(46)) + 0.01,'Re')        %Real axis mark
arrow([real(f(45)) imag(f(45))], [real(f(46)) imag(f(46))], AM_normal_arrowsize);
%y-axis
z=0*ones(22,1);
y=[-1.34 linspace(-1.34,1.34,20) 1.35]';
x=[0 0 zeros(1,20)]';
f=plotsp(phid, thd, [x y z], 1, 'k');               %Imaginary axis
amtext(real(f(22))-0.1,imag(f(22))+0.1,'Im')          %Imaginary axis mark
arrow([real(f(21)) imag(f(21))], [real(f(22)) imag(f(22))], AM_normal_arrowsize);
%f=plotsp(phid,thd,[.4 0 0;pl2sp(.4)],2);
%plot(real(f(1)),imag(f(1)),'+')
%plot(real(f(2)),imag(f(2)),'o')
%text(real(f(1)),imag(f(1)),'0.4')
%text(real(f(2)),imag(f(2)),'0.4')
%plotsp(phid,thd,[0 0 1;pl2sp(.4)],2,'--');
f=plotsp(phid,thd,[1 -1 0;pl2sp(1-j)], 2, 'r', 'r', 'LineWidth', AM_ref_linewidth);
plot(real(f(1)),imag(f(1)), 'r+')
plot(real(f(2)),imag(f(2)), 'ro')
amtext(real(f(1)),imag(f(1))+0.1,'1-{\iti}')
amtext(real(f(2))+0.075,imag(f(2))+0.05,'1-{\iti}')
plotsp(phid,thd,[0 0 1;pl2sp(1-j)],2,'r--', 'r--', 'LineWidth', AM_ref_linewidth); %Dashed line for 1-i
%f=plotsp(phid,thd,pl2sp([.4;1-j]),2,'--');
%f=(f(1)+f(2))/2;
%text(real(f),imag(f),'k(0.4,1-i)')


for i=1:n;
c=circ(0,mags(i));
plotsp(phid,thd,pl2sp(c),sflag,'k-');
end
l=tan(pi/4+.5*[-pi:pi/25:pi])';
n=max(size(thetas));
for i=1:n;
plotsp(phid,thd,pl2sp(l*exp(j*thetas(i)/180*pi)),0,'k-');
end
%c=plotsp(phid,thd,pl2sp([-1;0;1e10;j; -j ]),0,'+w');
%text(real(c),imag(c),['-1 ';'0  ';'Inf';'i  ';'-i '])
if thd>0
c=plotsp(phid,thd,pl2sp([1e10]),0,'r+');
%text(real(c),imag(c),['Inf'])
else
c=plotsp(phid,thd,pl2sp([0]),0,'r+');
%text(real(c),imag(c),['0'])
end
if phid>90 &phid<270
c=plotsp(phid,thd,pl2sp([j;]),0,'r+');
%text(real(c),imag(c),['i'])
else
c=plotsp(phid,thd,pl2sp([-j;]),0,'r+');
text(real(c),imag(c),['-i'])
end
%if phid>0 & phid<180
  %[c,fr]=plotsp(phid,thd,pl2sp(mags'),0,'+')
  %for k=find(fr>0)';
	%text(real(c(k)),imag(c(k)),[' ' num2str(mags(k))]);
  %end
%else 
  %[c,fr]=plotsp(phid,thd,pl2sp(-mags'),0,'+');
  %for k=find(fr>0)';
	%text(real(c(k)),imag(c(k)),[' ' num2str(-mags(k))]);
  %end
%end

% Plot map of frequency response
f1=freqresp(tf(2,[1 1]),logspace(-2,1));
plotsp(phid,thd,pl2sp(f1(:)),1,'b-', 'b-', 'LineWidth', AM_thick_linewidth);
f2=freqresp(tf(2,[1 -1]),logspace(-2,1));
plotsp(phid,thd,pl2sp(f2(:)),1,'b--', 'b-', 'LineWidth', AM_thick_linewidth);

% Plot Nyquist curve
x=squeeze(real(f1));y=squeeze(imag(f1));z=zeros(size(x));
plotsp(phid,thd,[x,y,z],1,'b-', 'b-', 'LineWidth', AM_data_linewidth);
x=squeeze(real(f2));y=squeeze(imag(f2));z=zeros(size(x));
plotsp(phid,thd,[x,y,z],1,'b--', 'b-', 'LineWidth', AM_data_linewidth);

axis equal
set(gca,'vis','off')

amprint('showchordal2.eps');
