Unit Step Function and Sinusoidal Input

조회 수: 34 (최근 30일)
jose Miguel
jose Miguel 2024년 7월 18일
답변: Shubham 2024년 7월 18일
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.

답변 (2개)

Shubham
Shubham 2024년 7월 18일
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.

Rahul
Rahul 2024년 7월 18일
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:
Hope this helps!

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by