clear all; close all;
num = [1];
den1 = [1 1];
den2 = [1 0];
numc = [10];
denc = [1];
sys1 = tf( num, den1 );
sys2 = tf( num, den2 );
c = tf( numc, denc);
sysL1 = c*sys1;
sysL2 = c*sys2;
sysC1 = feedback( sysL1, 1 );
sysC2 = feedback( sysL2, 1 );
w = logspace(-1, 2, 1000);
figure(1)
[ gainL1 phaseL1 wL1] = bode( sysL1, w );
gainL1 = gainL1(:);
gainL1dB = 20*log10(gainL1);
phaseL1 = phaseL1(:);
subplot(2,2,1)
semilogx(wL1, gainL1dB);
xlim([10^(-1),10^2])
ylim([-25 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-20 0 20 40])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('L_{1}(s) = P_{1}(s) C(s)')
subplot(2,2,3)
semilogx(wL1, phaseL1);
xlim([10^(-1),10^2])
ylim([-200 0])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90 -45 0])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
[ gainL2 phaseL2 wL2 ] = bode( sysL2, w );
gainL2 = gainL2(:);
gainL2dB = 20*log10(gainL2);
phaseL2 = phaseL2(:);
subplot(2,2,2)
semilogx(wL2, gainL2dB);
xlim([10^(-1),10^2])
ylim([-25 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-20 0 20 40])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('L_{2}(s) = P_{2}(s) C(s)')
subplot(2,2,4)
semilogx(wL2, phaseL2);
xlim([10^(-1),10^2])
ylim([-200 0])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90 -45 0])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
figure(2)
t = 0:0.01:5;
[ y1, t1 ] = step( sysC1, t );
[ y2, t2 ] = step( sysC2, t );
subplot(1,2,1)
plot(t1,y1);
xlim([0 5])
ylim([0.0 1.2])
xticks([0 1 2 3 4 5])
yticks([0.0 0.5 1.0])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('P_{1}(s), C(s)')
subplot(1,2,2)
plot(t2,y2);
xlim([0 5])
ylim([0.0 1.2])
xticks([0 1 2 3 4 5])
yticks([0.0 0.5 1.0])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('P_{2}(s), C(s)')