HW 5 Submission
HW 5 Submission
Conant-Haque
Figure 2. Verification of Figure 1 using the built-in Bode functionality, since that is
considered more trustworthy than the manual work of the author.
Finally, the system response is investigated for a specific input frequency, in this case given
as 𝜔 = 50 rad/sec. The result of this investigation is Figure 3, below.
The result in Figure 3 very clearly matches results from the two previous parts of this
question, in the sense that it is the response which the Bode diagram predicts for the input
frequency 𝜔 = 50 rad/sec.
Autumn 2024 Elihu S. Conant-Haque
Autumn 2024 Elihu S. Conant-Haque
Autumn 2024 Elihu S. Conant-Haque
Appendix
Figure 5. MATLAB’s generated Bode plot for the transfer function G(s)
which was derived by observing key characteristics of a given Bode diagram.
Autumn 2024 Elihu S. Conant-Haque
Appendix
% -------------------------------------------------------------------------
% MATLAB code for plotting the frequency response of a transfer function
% Author: Elihu S. Conant-Haque
% Course: Modeling & Control of Dynamical Systems, MANE 4500
% School: Rensselaer Polytechnic Institute
% Term : Autumn 2024
% -------------------------------------------------------------------------
% EXECUTE PART I ----------------------------------------------------------
% Define the transfer function (User may tweak this according to use case)
num = [300 300*5]; % Numerator coefficients (300 * (s + 5))
den = [1 3 30] ; % Denominator coefficients (s^2 + 3s + 30)
% Frequency range for the response
omega = logspace(-1, 3, 1000); % Frequencies from 0.1 to 1000 rad/s
% Frequency response calculation
G = freqs(num, den, omega);
% Magnitude and phase calculation
mag = 20*log10(abs(G)) ; % Magnitude in dB
phase = angle(G) * (180/pi); % Phase in degrees
% Display the results
figure;
subplot(2,1,1);
semilogx(omega, mag);
grid on;
num_String = string(num(1)) + "*s " + string(num(2)) ;
den_String = string(den(1)) + "*{s}^2 " + string(den(2)) + "*s " + string(den(3)) ;
title(['Frequency response of transfer function G(s) = $\frac{300(s + 5)}{{s}^2 + 3s + 30}$'],
'Interpreter', 'latex')
subtitle("Bode diagram format", FontName="Times New Roman")
xlabel('Frequency (rad/s)', FontName="Times New Roman");
ylabel('Magnitude (dB)', FontName="Times New Roman");
subplot(2,1,2);
semilogx(omega, phase);
grid on;
xlabel('Frequency (rad/s)', FontName="Times New Roman");
ylabel('Phase (degrees)', FontName="Times New Roman");
% -------------------------------------------------------------------------
% EXECUTE PART II ---------------------------------------------------------
% Now verify the results by using the buit-in Bode disgram functionality
% Define the transfer function
sys = tf(num, den);
% Bode plot
figure;
bode(sys);
grid on;
title('Bode Plot of G(s)', FontName="Times New Roman");
% -------------------------------------------------------------------------
% EXECUTE PART III --------------------------------------------------------
% For the final part, probe the response at a certain frequency and plot it
% Input signal is a sin wave at 50 rad/s
t = 0 : 0.01 : 5 ; % Vector of times at which to evaluate
u = sin(50*t) ; % Input signal at 50 rad/s
% Probe the output response
[y, t] = lsim(sys, u, t);
% Now simply plot in- and output
figure;
plot(t, u, 'b', 'DisplayName', 'Input (sin(50t))');
Autumn 2024 Elihu S. Conant-Haque
hold on;
plot(t, y, 'r', 'DisplayName', 'Output');
grid on;
xlabel('Time (seconds)', FontName="Times New Roman");
ylabel('Amplitude', FontName="Times New Roman");
title('Input and Output Response at 50 rad/s', FontName="Times New Roman");
legend;
% COMPLETE ----------------------------------------------------------------
% VERIFY A HAND-DRAWN BODE PLOT -------------------------------------------
clear all
close all ;
clc ;
figure;
s = tf('s');
G = 36 * (s + 10) / ((s^2 + 0.9 * s + 9) * (s + 2));
bode(G);
grid on;
% COMPLETE ----------------------------------------------------------------
% VERIFY A TRANSFER FUNCTION DERIVED BY EYE -------------------------------
clear all
close all ;
clc ;
s = tf('s') ; % Make Laplace variable
w = 10; % Set natural freq
x = 0.158; % Set damping ratio
G = 0.1*(1+10*s)/(s^2*(s^2/w^2+2*x*w*s/w^2+1)) ; % Construct T. F.
bode(G) ;
grid on ;
% COMPLETE ----------------------------------------------------------------