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.1037e+000 -78.0685e+000 -93.2694e+000 -103.6289e+000 -111.5465e+000 -117.9697e+000 -1

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.0000e+000 -155.4467e+000 -291.6401e+000 -317.7879e+000 -329.0597e+000 -335.5005e+000 -339.6960e+000 -3

% 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 = "Bode Plot";

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.Title.String = "Nyquist Diagram";

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, 'Parent', axnic);
scatter(phaGiDiscrete, logmagGiDiscrete, 'filled', 'Parent', axnic);

grid on

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

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


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

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


axnic.XLim = [-405 -45];

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

axnic.Box = "on";

axnic.Title.String = "Nichols Chart";

4
hold off

(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.3434e+000 -31.1094e+000 -41.2442e+000 -47.6594e+000 -52.4016e+000 -56.1527e+000 -59.2498e+000 -

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.0000e+000 -75.3236e+000 -121.0659e+000 -139.3205e+000 -149.0723e+000 -155.0945e+000 -159.1695e+000 -1

% 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 = "Bode Plot";

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.Title.String = "Nyquist Diagram";

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, 'Parent', axnic);
scatter(phaGiDiscrete, logmagGiDiscrete, 'filled', 'Parent', axnic);

grid on

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

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


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

8
axnic.XTick = [-180 -90 0 90 180];
axnic.XLim = [-225 225];

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

axnic.Box = "on";

axnic.Title.String = "Nichols Chart";

hold off

You might also like