% Fig. 6.54   Feedback Control of Dynamic Systems, 8e 
%             Franklin, Powell, Emami
%

clear all;
%close all;
clf
 
w = logspace(-1,2,100);
k = 10;

num = k;
den = [1 1 0];

[m,p] = bode(num,den,w);

num = conv(num,[.5 1]);
den = conv(den,[.1 1]);

[mc,pc] = bode(num,den,w);

figure(1)

subplot(2,1,1)

loglog(w,m,'LineWidth',2);

text( 5*0.1, 1, "10/[1 1 0]")

axis([ 0.1, 100, 1e-4, 1e2])

set(findall(gcf,'type','line'),'linewidth',3);

grid on;
xlabel('\omega (rad/sec)');
ylabel('Magnitude');
title('(a) magnitude');
%pause;

subplot(2,1,2)
semilogx(w,p,'LineWidth',2);
axis([ 0.1, 100, -180, -80])

set(findall(gcf,'type','line'),'linewidth',3);
grid on;
xlabel('\omega (rad/sec)');
ylabel('Phase');
title('(b) phase');


figure(2)

subplot(2,1,1)

loglog(w,m,w,mc,'LineWidth',2);

set(findall(gcf,'type','line'),'linewidth',3);

text( 5*0.1, 1, "10/[1 1 0]")
text( 3*1, 10, "K D_c = 10 [0.5 1]/[0.1 1]")


axis([ 0.1, 100, 1e-4, 1e2])


grid on;
xlabel('\omega (rad/sec)');
ylabel('Magnitude');
title('(a) magnitude');
%pause;

subplot(2,1,2)
semilogx(w,p,w,pc,'LineWidth',2);
axis([ 0.1, 100, -180, -80])

set(findall(gcf,'type','line'),'linewidth',3);

grid on;
xlabel('\omega (rad/sec)');
ylabel('Phase');
title('(b) phase');

