Unit Step Function and Sinusoidal Input
34 views (last 30 days)
Show older comments
For the given system with transfer function
G(S) = 10 / (S2 + 2S + 20)
If G(S) = Y(S) / X(S), where Y(S) is the output and X(S) is the input. Compute for the output if the input is a. unit step function and b. sinusoidal input. Then simulate using MATLAB and compare the result. Plot the response of the system. Compare the result of the two different inputs.
0 Comments
Answers (2)
Shubham
on 18 Jul 2024
Hi Jose,
I understand that you have a transfer function ( G(s) ) and want to find the output ( Y(s) ) for two inputs: a unit step and a sinusoidal function. You also want to simulate these responses using MATLAB and compare the results by plotting them.
Below is the MATLAB script to achieve your task:
% Define the transfer function G(s) = 10 / (s^2 + 2s + 20)
num = 10;
den = [1 2 20];
G = tf(num, den);
% Time vector for simulation
t = 0:0.01:10;
% Unit Step Input
u_step = ones(size(t));
[y_step, ~] = lsim(G, u_step, t);
% Sinusoidal Input
omega = 1; % Frequency of the sinusoidal input
u_sin = sin(omega * t);
[y_sin, ~] = lsim(G, u_sin, t);
% Compare the results
figure;
plot(t, y_step, 'b', 'LineWidth', 1.5, 'DisplayName', 'Unit Step Response');
hold on;
plot(t, y_sin, 'r', 'LineWidth', 1.5, 'DisplayName', 'Sinusoidal Response');
title('Comparison of System Responses');
xlabel('Time (s)');
ylabel('Output y(t)');
legend show;
grid on;
You can refer to the following documentation link for more information on "tf" function: https://www.mathworks.com/help/releases/R2024a/control/ref/tf.html?searchHighlight=tf&s_tid=doc_srchtitle
Hope this helps.
0 Comments
Rahul
on 18 Jul 2024
You can achieve your desired result by following this code:
% Define the transfer function
num = 10;
den = [1 2 20];
G = tf(num, den); % Function for transfer function
omega = 1;
t = 0:0.01:10;
u = sin(omega * t);
% Compare the results
figure;
subplot(2,1,1);
step(G); % (a) Unit step response
title('Step Response of the System');
subplot(2,1,2);
lsim(G, u, t); % (b) Sinusoidal input response
title('Sinusoidal Response of the System');
You can refer to the following links to know more about the functions used:
‘tf’ function: https://www.mathworks.com/help/releases/R2024a/control/ref/tf.html?searchHighlight=tf&s_tid=doc_srchtitle
‘step’ function: https://www.mathworks.com/help/releases/R2024a/control/ref/dynamicsystem.step.html?searchHighlight=step&s_tid=doc_srchtitle
‘lsim’ function: https://www.mathworks.com/help/releases/R2024a/control/ref/dynamicsystem.lsim.html?searchHighlight=lsim&s_tid=doc_srchtitle
Hope this helps!
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!