clear all; close all;
num = [ 0 0 20 ];
den = [ 1 11 10 ];
numc0 = [ 1 ];
denc0 = [ 1 ];
numc1 = [ 10 ];
denc1 = [ 1 ];
omega1 = 1;
numPLG = [ 1 omega1 ];
denPLG = [ 1 0 ];
sys = tf( num, den );
c0 = tf( numc0, denc0 );
c1 = tf( numc1, denc1 );
cPLG = tf( numPLG, denPLG );
sysL0 = c0*sys;
sysL1 = c1*sys;
sysL2 = c1*cPLG*sys;
w = logspace(-1, 2, 1000);
figure(1)
[ gainL0 phaseL0 wL0 ] = bode( sysL0, w );
gainL0 = gainL0(:);
gainL0dB = 20*log10(gainL0);
phaseL0 = phaseL0(:);
subplot(2,3,1)
semilogx(wL0, gainL0dB);
xlim([10^(-1) 10^2])
ylim([-25 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-40 -20 0 20 40])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('L_0(s) = P(s)')
subplot(2,3,4)
semilogx(wL0, phaseL0);
xlim([10^(-1) 10^2])
ylim([-180 0])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90 -45 0])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
[ gainL1 phaseL1 wL1 ] = bode( sysL1, w );
gainL1 = gainL1(:);
gainL1dB = 20*log10(gainL1);
phaseL1 = phaseL1(:);
subplot(2,3,2)
semilogx(wL1, gainL1dB);
xlim([10^(-1) 10^2])
ylim([-25 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-40 -20 0 20 40])
grid;
xlabel('Frequency (rad/s)');
title('L_1(s) = P(s)C_1(s)')
subplot(2,3,5)
semilogx(wL1, phaseL1);
xlim([10^(-1),10^2])
ylim([-180 0])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90 -45 0])
grid;
xlabel('Frequency (rad/s)');
[ gainL2 phaseL2 wL2 ] = bode( sysL2, w );
gainL2 = gainL2(:);
gainL2dB = 20*log10(gainL2);
phaseL2 = phaseL2(:);
subplot(2,3,3)
semilogx(wL2, gainL2dB);
xlim([10^(-1) 10^2])
ylim([-25 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-40 -20 0 20 40])
grid;
xlabel('Frequency (rad/s)');
title('L_2(s) = P(s)C_2(s)')
subplot(2,3,6)
semilogx(wL2, phaseL2);
xlim([10^(-1) 10^2])
ylim([-180 0])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90 -45 0])
grid;
xlabel('Frequency (rad/s)');
figure(2)
sysc0 = feedback( sysL0, 1);
sysc1 = feedback( sysL1, 1);
sysc2 = feedback( sysL2, 1);
t = 0:0.001:2;
[ y0, t0 ] = step( sysc0, t );
[ y1, t1 ] = step( sysc1, t );
[ y2, t2 ] = step( sysc2, t );
subplot(1,3,1)
plot(t0,y0);
xlim([0 2])
ylim([0.0 1.5])
xticks([0 0.5 1.0 1.5 2.0])
yticks([0.0 0.5 1.0])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('C_0(s) = 1')
subplot(1,3,2)
plot(t1,y1);
xlim([0 2])
ylim([0.0 1.5])
xticks([0 0.5 1.0 1.5 2.0])
yticks([0.0 0.5 1.0])
grid;
xlabel('time t [s]');
title('C_1(s) = 10')
subplot(1,3,3)
plot(t2,y2);
xlim([0 2])
ylim([0.0 1.5])
xticks([0 0.5 1.0 1.5 2.0])
yticks([0.0 0.5 1.0])
grid;
xlabel('time t [s]');
title('C_2(s) = 10*(s+1)/s')