%Bode plots of systems with delay, RHP zero and RHP pole
%kja 070516

aminit;

%
% Time delay
%

w=logspace(-1,1,100);s=i*w;
gd=exp(-s);
gz=(1-s)./(1+s);
gp=(s+1)./(s-1);
one=ones(size(w));

% Generate a dummy plot to set up the axes
figure(1); clf; axes('position', [0.1 0.55 0.2 0.3]);
[mh, ph] = ambode(tf([1000000], [1 0 0 0 0 0]));

%
%Time delay
axes(mh); hold on;
loglog(w, abs(gd), 'b-', 'Linewidth', AM_data_linewidth);
ylabel('g');
amaxis([0.1 10 0.1 10])
set(gca,'Ytick',[0.1 1 10]);

axes(ph); hold on;
semilogx(w, 180*unwrap(angle(gd))/pi, 'b-', 'LineWidth', AM_bode_linewidth);
semilogx(w, 0*one, 'k--',  'LineWidth', AM_ref_linewidth);
set(gca,'Ytick',[-360 -180 0]);
amaxis([0.1 10 -360 10]);
xlabel('wT');
ylabel('p');

amprint('bode-delay.eps');

%
% Right half plane zero
%

% Generate a dummy plot to set up the axes
figure(2); clf; axes('position', [0.1 0.55 0.2 0.3]);
[mh, ph] = ambode(tf([1000000], [1 0 0 0 0 0]));

axes(mh); hold on;
loglog(w,abs(gz), 'b-', 'Linewidth', AM_data_linewidth);
ylabel('g');
amaxis([0.1 10 0.1 10]);
set(gca,'Ytick',[0.1 1 10]);

axes(ph); hold on;
semilogx(w, 180*unwrap(angle(gz))/pi, 'b-', 'LineWidth', AM_bode_linewidth);
semilogx(w, 0*one, 'k--',  'LineWidth', AM_ref_linewidth);
set(gca,'Ytick',[-360 -180 0]);
amaxis([0.1 10 -360 10]);
xlabel('wa');
ylabel('p');

amprint('bode-rhpz.eps');

%
% Right half plane pole
%

figure(3); clf; axes('position', [0.1 0.55 0.2 0.3]);
[mh, ph] = ambode(tf([1000000], [1 0 0 0 0 0]));

axes(mh); hold on;
loglog(w,abs(gp), 'b-', 'Linewidth', AM_data_linewidth);
ylabel('g');
amaxis([0.1 10 0.1 10]);
set(gca,'Ytick',[0.1 1 10]);

axes(ph); hold on;
semilogx(w, 180*unwrap(angle(gp))/pi, 'b-', 'LineWidth', AM_bode_linewidth);
semilogx(w, 0*one, 'k--',  'LineWidth', AM_ref_linewidth);
set(gca,'Ytick',[-360 -180 0]);
amaxis([0.1 10 -360 10]);
xlabel('wa');
ylabel('p');

amprint('bode-rhpp.eps');
