clear all; close all;
num = [ 0 0 1 ];
den = [ 1 1 0 ];
numc0 = [ 1 ];
denc0 = [ 1 ];
numc1 = [ 12 ];
denc1 = [ 1 ];
omega3 = 10;
omega4 = 1;
numPLE = [ omega3 omega3 * omega4 ];
denPLE = [ omega4 omega4 * omega3 ];
sys = tf( num, den );
c0 = tf( numc0, denc0 );
c1 = tf( numc1, denc1 );
cPLE = tf( numPLE, denPLE );
sysL0 = c0*sys;
sysL1 = c1*sys;
sysL2 = c1*cPLE*sys;
w = logspace(-1, 2, 1000);
figure(1)
[ gainL0 phaseL0 wL0 ] = bode( sysL0, w );
gainL0 = gainL0(:);
gainL1dB = 20*log10(gainL0);
phaseL0 = phaseL0(:);
subplot(2,3,1)
semilogx(wL0, gainL1dB);
xlim([10^(-1),10^2])
ylim([-30 45])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-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 -90])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90])
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([-30 45])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-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 -90])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90])
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([-30 45])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-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 -90])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([-180 -135 -90])
grid;
xlabel('Frequency (rad/s)');
figure(2)
sysc0 = feedback( sysL0, 1 );
sysc1 = feedback( sysL1, 1 );
sysc2 = feedback( sysL2, 1 );
t = 0:0.01:6;
[ y0, t0 ] = step( sysc0, t );
[ y1, t1 ] = step( sysc1, t );
[ y2, t2 ] = step( sysc2, t );
subplot(1,3,1)
plot(t0,y0);
xlim([0,6])
ylim([0.0 2.0])
xticks([0 2.0 4.0])
yticks([0.0 1.0 2.0])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('C_0(s) = 1')
subplot(1,3,2)
plot(t1,y1);
xlim([0,6])
ylim([0.0 2.0])
xticks([0 2.0 4.0])
yticks([0.0 1.0 2.0])
grid;
xlabel('time t [s]');
title('C_1(s) = 12')
subplot(1,3,3)
plot(t2,y2);
xlim([0,6])
ylim([0.0 2.0])
xticks([0 2.0 4.0])
yticks([0.0 1.0 2.0])
grid;
xlabel('time t [s]');
title('C_2(s) = 12*(10/1)*(s+1)/(s+10)')
figure(3)
C2 = c1*cPLE;
[ gainc2 phasec2 wc2 ] = bode( C2, w );
gainc2 = gainc2(:);
gainc2dB = 20*log10(gainc2);
phasec2 = phasec2(:);
subplot(2,1,1)
semilogx(wc2, gainc2dB);
xlim([10^(-1),10^2])
ylim([-10 50])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([0 20 40])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
subplot(2,1,2)
semilogx(wc2, phasec2);
xlim([10^(-1),10^2])
ylim([-10 90])
xticks([10^(-1) 10^(0) 10^(1) 10^(2)])
yticks([0 45 90])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');