clear all; close all;
K = 1;
omegan = 0.1;
zeta = 0.2;
num = [ 0 0 K * omegan^2 ];
den = [ 1 2*zeta*omegan omegan^2 ];
numc0 = [ 1 ];
denc0 = [ 1 ];
numc1 = [ 100 ];
denc1 = [ 1 ];
omega1 = 0.1;
numPLG = [ 1 omega1 ];
denPLG = [ 1 0 ];
omega3 = 8;
omega4 = 0.5;
numPLE = [ omega3 omega3 * omega4 ];
denPLE = [ omega4 omega4 * omega3 ];
omega5 = 10;
zeta5 = 0.5;
num5 = [omega5^2];
den5 = [1, 2 * zeta5 * omega5, omega5^2];
sys = tf( num, den );
c0 = tf( numc0, denc0 );
c1 = tf( numc1, denc1 );
cPLG = tf( numPLG, denPLG );
cPLE = tf( numPLE, denPLE );
cont_roll = tf(num5, den5);
sysL3 = c1*cPLG*cPLE*sys;
sysL4 = c1*cPLG*cPLE*cont_roll*sys;
sysc3 = feedback( sysL3, 1 );
sysc4 = feedback( sysL4, 1 );
figure(1)
t = 0:0.01:10;
us = ones( size( t ) );
ns = 0.3 * sin( 25*t);
[ y3, t3 ] = lsim( sysc3, us + ns, t );
[ y4, t4 ] = lsim( sysc4, us + ns, t );
subplot(1,2,1);
plot(t3,y3);
xlim([0,10])
ylim([0.0 1.5])
xticks([0 2 4 6 8 10])
yticks([0.0 0.5 1.0 1.5])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('C_3(s)');
subplot(1,2,2);
plot(t4,y4);
xlim([0,10])
ylim([0.0 1.5])
xticks([0 2 4 6 8 10])
yticks([0.0 0.5 1.0 1.5])
grid;
xlabel('time t [s]');
ylabel('y(t)')
title('C_4(s)')
c4 = c1*cPLG*cPLE*cont_roll;
w = logspace(-2, 2, 1000);
figure(2)
[ gainc4 phasec4 wc4 ] = bode( c4, w );
gainc4 = gainc4(:);
gainc4dB = 20*log10(gainc4);
phasec4 = phasec4(:);
subplot(2,2,1)
semilogx(wc4, gainc4dB);
xlim([10^(-2),10^(2)])
ylim([0 70])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([0 20 40 60])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('C_4(s)')
subplot(2,2,3)
semilogx(wc4, phasec4);
xlim([10^(-2),10^(2)])
ylim([-90 50])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-90 -45 0 45])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');
[ gainL4 phaseL4 wL4 ] = bode( sysL4, w );
gainL4 = gainL4(:);
gainL4dB = 20*log10(gainL4);
phaseL4 = phaseL4(:);
subplot(2,2,2)
semilogx(wL4, gainL4dB);
xlim([10^(-2),10^(2)])
ylim([-60 60])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-40 0 40])
grid;
xlabel('Frequency (rad/s)');
ylabel('Gain [dB]');
title('L_4(s) = P(s)C_4(s)')
subplot(2,2,4)
semilogx(wL4, phaseL4);
xlim([10^(-2),10^(2)])
ylim([-225 0])
xticks([10^(-1) 10^(0) 10^(1)])
yticks([-180 -90 0])
grid;
xlabel('Frequency (rad/s)');
ylabel('Phase [deg]');