You are on page 1of 9

HW3 THR AE3200 Control Engineering 2023-2024

13621060 Hafizh Renanto Akhmad

close all
clear
clf
clc

w = [0.0001, 0.001:0.0001:1, 1.001:0.001:300, 301:1:10000];


wDiscrete = 0:5:300;

(i)

% Compute the obtained magnitude and phase functions


magGi = 5/2584 * sqrt(1 + (w / 2.5).^2) ./ (w .* sqrt((1 - w.^2/38).^2 + (3 .*
w/38).^2) .* sqrt((1 - w.^2/34).^2 + (10 .* w/34).^2));
logmagGi = 20 * log10(magGi);
phaGi = atan2d(0,5/2584) + atan2d(2.*w,5) - atan2d(1,0) - atan2d(3.*w,38-w.^2) -
atan2d(10.*w,34-w.^2);

magGiDiscrete = 5/2584 * sqrt(1 + (wDiscrete / 2.5).^2) ./ (wDiscrete .* sqrt((1


- wDiscrete.^2/38).^2 + (3 .* wDiscrete/38).^2) .* sqrt((1 - wDiscrete.^2/34).^2 +
(10 .* wDiscrete/34).^2));
logmagGiDiscrete = 20 * log10(magGiDiscrete);
phaGiDiscrete = atan2d(0,5/2584) + atan2d(2.*wDiscrete,5) - atan2d(1,0) -
atan2d(3.*wDiscrete,38-wDiscrete.^2) - atan2d(10.*wDiscrete,34-wDiscrete.^2);

realGi = magGi .* cosd(phaGi);


imagGi = magGi .* sind(phaGi);

realGiDiscrete = magGiDiscrete .* cosd(phaGiDiscrete);


imagGiDiscrete = magGiDiscrete .* sind(phaGiDiscrete);

fprintf("The value of magnitudes of G in dB for angular frequency 0-300 rad/s with


increment of 5 rad/s are:")

The value of magnitudes of G in dB for angular frequency 0-300 rad/s with increment of 5 rad/s are:

disp(logmagGiDiscrete)

Inf -59.1037 -78.0685 -93.2694 -103.6289 -111.5465 -117.9697 -123.3787 -128.0526 -132.1684 -135.8458 -139.

fprintf("The value of phases of G in degree for angular frequency 0-300 rad/s with
increment of 5 rad/s are:")

The value of phases of G in degree for angular frequency 0-300 rad/s with increment of 5 rad/s are:

disp(phaGiDiscrete)

1
-90.0000 -155.4467 -291.6401 -317.7879 -329.0597 -335.5005 -339.6960 -342.6540 -344.8547 -346.5572 -347.9141 -349.

% Create the Bode plot


figure(1)

% Create subplot for magnitude part


axmag = subplot(2,1,1);
hold on
plot(w, logmagGi, 'Parent', axmag);
scatter(wDiscrete, logmagGiDiscrete, 'filled', 'Parent', axmag);
grid on

axmag.Title.String = "Magnitude";

axmag.XLim = [0.001 300];


axmag.XScale = 'log';

axmag.YLim = [-250 50];

axmag.XLabel.String = "\omega (rad/s)";


axmag.YLabel.String = "‖G‖ (dB)";

axmag.Box = "on";
hold off

% Create subplot for phase part


axpha = subplot(2,1,2);
hold on
plot(w, phaGi, 'Parent', axpha);
scatter(wDiscrete, phaGiDiscrete, 'filled', 'Parent', axpha);
grid on

axpha.Title.String = "Phase";

axpha.XLim = [0.001 300];

axpha.XScale = 'log';

axpha.YTick = [-360 -270 -180 -90];


axpha.YLim = [-405 -45];

axpha.XLabel.String = "\omega (rad/s)";


axpha.YLabel.String = "∠G (°)";

axpha.Box = "on";
hold off

2
% Create the Nyquist plot
figure(2);
axnyq = gca;

hold on
plot(realGi, imagGi, 'Parent', axnyq);
scatter(realGiDiscrete, imagGiDiscrete, "filled", 'Parent', axnyq);

grid on
axis equal

axnyq.XAxisLocation = "origin";
axnyq.YAxisLocation = "origin";

axnyq.XLabel.String = "G_{Re}";
axnyq.YLabel.String = "G_{Im}";

axnyq.Box = "on";

axnyq.YLim = [-2.5e-3 2.5e-3];


axnyq.XLim = [-2.5e-3 2.5e-3];

hold off

3
% Create the Nichols chart
figure(3);
axnic = gca;

hold on
plot(phaGi, logmagGi/20, 'Parent', axnic);
scatter(phaGiDiscrete, logmagGiDiscrete/20, 'filled', 'Parent', axnic);

grid on

axnic.XAxisLocation = "origin";
% axnic.YAxisLocation = "origin";

axnic.XLabel.String = "∠G (°)";


axnic.YLabel.String = "log‖G‖";

axnic.XTick = [-360 -270 -180 -90];


axnic.XLim = [-405 -45];

axnic.YLim = [logmagGi(end)/20 logmagGi(1)/20];

axnic.Box = "on";

hold off

4
(ii)

% Compute the obtained magnitude and phase functions


magGi = 2/37 * sqrt(1 + (w / 5).^2) .* sqrt(1 + (w / 2).^2) ./ (sqrt((1 -
w.^2/5).^2 + (2 .* w/5).^2) .* sqrt((1 - w.^2/37).^2 + (12 .* w/37).^2));
logmagGi = 20 * log10(magGi);
phaGi = atan2d(0,-2/37) + atan2d(w,5) + atan2d(-w,2) - atan2d(2.*w,5-w.^2) -
atan2d(12.*w,37-w.^2);

magGiDiscrete = 2/37 * sqrt(1 + (wDiscrete / 5).^2) .* sqrt(1 + (wDiscrete /


2).^2) ./ (sqrt((1 - wDiscrete.^2/5).^2 + (2 .* wDiscrete/5).^2) .* sqrt((1 -
wDiscrete.^2/37).^2 + (12 .* wDiscrete/37).^2));
logmagGiDiscrete = 20 * log10(magGiDiscrete);
phaGiDiscrete = atan2d(0,-2/37) + atan2d(wDiscrete,5) + atan2d(-wDiscrete,2) -
atan2d(2.*wDiscrete,5-wDiscrete.^2) - atan2d(12.*wDiscrete,37-wDiscrete.^2);

realGi = magGi .* cosd(phaGi);


imagGi = magGi .* sind(phaGi);

realGiDiscrete = magGiDiscrete .* cosd(phaGiDiscrete);


imagGiDiscrete = magGiDiscrete .* sind(phaGiDiscrete);

5
fprintf("The value of magnitudes of G in dB for angular frequency 0-300 rad/s with
increment of 5 rad/s are:")

The value of magnitudes of G in dB for angular frequency 0-300 rad/s with increment of 5 rad/s are:

disp(logmagGiDiscrete)

-25.3434 -31.1094 -41.2442 -47.6594 -52.4016 -56.1527 -59.2498 -61.8847 -64.1761 -66.2028 -68.0191 -69.

fprintf("The value of phases of G in degree for angular frequency 0-300 rad/s with
increment of 5 rad/s are:")

The value of phases of G in degree for angular frequency 0-300 rad/s with increment of 5 rad/s are:

disp(phaGiDiscrete)

180.0000 -75.3236 -121.0659 -139.3205 -149.0723 -155.0945 -159.1695 -162.1055 -164.3194 -166.0477 -167.4339 -168.

% Create the Bode plot


figure(4)

% Create subplot for magnitude part


axmag = subplot(2,1,1);
hold on
plot(w, logmagGi, 'Parent', axmag);
scatter(wDiscrete, logmagGiDiscrete, 'filled', 'Parent', axmag);
grid on

axmag.Title.String = "Magnitude";

axmag.XLim = [0.001 300];


axmag.XScale = 'log';

axmag.YLim = [-110 -15];

axmag.XLabel.String = "\omega (rad/s)";


axmag.YLabel.String = "‖G‖ (dB)";

axmag.Box = "on";
hold off

% Create subplot for phase part


axpha = subplot(2,1,2);
hold on
plot(w, phaGi, 'Parent', axpha);
scatter(wDiscrete, phaGiDiscrete, 'filled', 'Parent', axpha);
grid on

axpha.Title.String = "Phase";

axpha.XLim = [0.001 300];

6
axpha.XScale = 'log';

axpha.YTick = [-180 -90 0 90 180];


axpha.YLim = [-225 225];

axpha.XLabel.String = "\omega (rad/s)";


axpha.YLabel.String = "∠G (°)";

axpha.Box = "on";
hold off

% Create the Nyquist plot


figure(5);
axnyq = gca;

hold on
plot(realGi, imagGi, 'Parent', axnyq);
scatter(realGiDiscrete, imagGiDiscrete, "filled", 'Parent', axnyq);

grid on
axis equal

axnyq.XAxisLocation = "origin";
axnyq.YAxisLocation = "origin";

axnyq.XLabel.String = "G_{Re}";

7
axnyq.YLabel.String = "G_{Im}";

axnyq.Box = "on";

axnyq.YLim = [-0.06 0.09];


axnyq.XLim = [-0.06 0.09];

hold off

% Create the Nichols chart


figure(6);
axnic = gca;

hold on
plot(phaGi, logmagGi/20, 'Parent', axnic);
scatter(phaGiDiscrete, logmagGiDiscrete/20, 'filled', 'Parent', axnic);

grid on

axnic.XAxisLocation = "origin";
axnic.YAxisLocation = "origin";

axnic.XLabel.String = "∠G (°)";


axnic.YLabel.String = "log‖G‖";

axnic.XTick = [-180 -90 0 90 180];

8
axnic.XLim = [-225 225];

axnic.YLim = [min(logmagGi)/20 max(logmagGi)/20];

axnic.Box = "on";

hold off

You might also like