clear all; close all;
num = [1];
den = [1 2 1];
K1 = 1.0;
K2 = 2.4;
K3 = 3.0;
numc1 = [ K1 ];
numc2 = [ K2 ];
numc3 = [ K3 ];
denc = [ 1 0.1 ];
sys = tf( num, den );
c1 = tf( numc1, denc );
c2 = tf( numc2, denc );
c3 = tf( numc3, denc );
sysL1 = c1*sys;
sysL2 = c2*sys;
sysL3 = c3*sys;
w = logspace(-1, 1, 1000);
[gainL1 phaseL1 wL1] = bode(sysL1, w);
gainL1 = gainL1(:);
gain1dB = 20*log10(gainL1);
phaseL1 = phaseL1(:);
subplot(2,3,1)
semilogx(wL1, gain1dB);
xlim([10^(-1),10^1])
ylim([-40 25])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-40 -20 0 20])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('K=1')
subplot(2,3,4)
semilogx(wL1, phaseL1);
xlim([10^(-1),10^1])
ylim([-200 -90])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-180 -135 -90])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
[gainL2 phaseL2 wL2] = bode(sysL2, w);
gainL2 = gainL2(:);
gainL2dB = 20*log10(gainL2);
phaseL2 = phaseL2(:);
subplot(2,3,2)
semilogx(wL2, gainL2dB);
xlim([10^(-1),10^1])
ylim([-40 25])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-40 -20 0 20])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('K=2.4')
subplot(2,3,5)
semilogx(wL2, phaseL2);
xlim([10^(-1),10^1])
ylim([-200 -90])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-180 -135 -90])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
[gainL3 phaseL3 wL3] = bode(sysL3, w);
gainL3 = gainL3(:);
gain3dB = 20*log10(gainL3);
phaseL3 = phaseL3(:);
subplot(2,3,3)
semilogx(wL3, gain3dB);
xlim([10^(-1),10^1])
ylim([-40 25])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-40 -20 0 20])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('K=3')
subplot(2,3,6)
semilogx(wL3, phaseL3);
xlim([10^(-1),10^1])
ylim([-200 -90])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-180 -135 -90])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');