%Basic Nyquist plot
%kja 040502

aminit;					% initialize settings

% Start a new figure and set up the axes like we want them
figure(1); clf; xsubplot(221); hold on;
amaxis([-1.8 1.8 -1.8 1.8]); daspect(daspect); 

% Draw the Nyquist plot for the transfer function
[num, den] = pade(1, 4);
G = tf([1.4], [1 2 1]) * tf(num, den);
amnyquist(G, {0.005 100});

% Add a line for the vector L(iw)
H = freqresp(G, 0.2)
line([0 real(H)], [0 imag(H)], 'Color', 'r', 'LineWidth', AM_ref_linewidth);
plot(real(H), imag(H), 'ro', 'MarkerSize', AM_bode_markersize)
amtext(1.25, -0.8, 'r');

% Mark the -1 point
amtext(-1.05, -0.3, 'o')

amprint('nyqplot.eps');

return;

% Old code (not used)
% Start with a polezero diagram
figure(1); clf; subplot(221);
ampolezero(tf([1], [1]), [-1.8 1.8 -1.8 1.8]); hold on;

L='1.4*exp(-s)./((s+1).^2)';
w=0:0.005:10;s=i*w;lv=eval(L);

% Generate the Nyquist plot
pl=plot(real(lv),imag(lv));
set(pl,'Linewidth', AM_bode_linewidth)
hold on;

% Generate the mirror image
plot(real(lv), -imag(lv), '--', 'LineWidth', AM_bode_linewidth);

% add arrowheads
Aind = ceil(length(lv) / 25);
arrow([real(lv(Aind)), imag(lv(Aind))], ...
  [real(lv(Aind-1)), imag(lv(Aind-1))], AM_normal_arrowsize, ...
  'FaceColor', 'b', 'EdgeColor', 'b');
arrow([real(lv(Aind-1)), -imag(lv(Aind-1))], ...
  [real(lv(Aind)), -imag(lv(Aind))], AM_normal_arrowsize, ...
  'FaceColor', 'b', 'EdgeColor', 'b');

% Add a line for the vector L(iw)
[xx,kk]=min(abs(abs(angle(lv(1:200))+0.5)));
line([real(lv(kk)) 0], [imag(lv(kk)) 0], ...
  'Color', 'r', 'LineWidth', AM_ref_linewidth);
plot(real(lv(kk)), imag(lv(kk)), 'ro', 'MarkerSize', AM_bode_markersize)
amtext(0.75, -0.25, 'r');

% Plot the phase line, adding an arrowhead
% fi= 0:0.01:2*pi + angle(lv(kk));
% plot(0.3*cos(fi),0.3*sin(fi),'b-', 'LineWidth', AM_ref_linewidth)
% text(1.3,-0.7,'w')
% text(0.2,-0.4,'fi');

% Add the -1 point
plot(-1, 0, 'k+', 'MarkerSize', 6);
amtext(-1.05, -0.3, 'o')
