How can analyse respones in MATLAB live screen?

4 views (last 30 days)

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 1 Apr 2021
With *.mlx editor, you can insert a slider to assign the magnitude value of y0, w1, w2, and set the value range of t. The rest is just putting your two expressions alike, e.g.:
y = y0*sin(w1*t);
x = y0*cos(w2*t);
  2 Comments
May Juabran
May Juabran on 1 Apr 2021
Students are required to input below:
Setup time limits in seconds for running the simulations:
time_length_long = 10; % set up the long time period timestamps
time_length_short = 5; % short period timestamps (for seeing detail in the responses)
Do not change the lines below:
% simulation timestamps:
time_long = 0:0.01:time_length_long;
time_short = 0:0.01:time_length_short;
Students are required to input below:
Unit step base movement:
% perform a step response simulation to get the datapoints for plotting the response
% hint: use the 'step' function
% type 'help step' in the command window for more information
% use the long timestamps
response_mass_1_unit_step = 0;
num1 = '[4s^{3}+3s^{2}+2s+1]';%% numerator for transfer function
den1 = '[5s^4+4s^3+3s^2+2s+1]';%% denominatorfor transfer function
%% tf function creates continuous-time transfer function model
%% num1 and den1 are numerator and denominator
g1 =tf(num1,den1);
sys =ss(g1);%%ss function creates a state space model of static gain...
%% steps function creates step response of a dynamic model system
h = step(sys);
%% time interval
t = 0:0.01:0.01;
%% plotting the first image
subplot(2,1,1);
plot(h,t);
title('Simulation: Mass 1 Response to Input:Unit Step');
xlabel('Step Response');
ylabel('long timestamps');
%% all the functio below has also the same meaning as above explained
% plot the figure:
figure(3)
plot(0,0) % plot the response against the long timestamps generated above
title('Simulation: Mass 1 Response to Input: Unit Step')
xlabel('')
ylabel('')
% perform a step response simulation to get the datapoints for plotting the response
% hint: use the 'step' function
% type 'help step' in the command window for more information
% use the long timestamps
response_mass_2_unit_step = 0;
% plot the figure:
figure(4)
plot(0,0) % plot the response against the long timestamps generated above
title('Simulation: Mass 2 Response to Input: Unit Step')
xlabel('')
ylabel('')
Harmonic motion of the base at :
% generate the input sinusoidal function using the long timestamps above:
y_t_omega_1_long = 0;
% perform a linear simulation for the sinusoidal excitation (mass 1)
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the long timestamps
response_mass_1_omega_1_long = 0;
% plot the figure:
figure(5)
plot(0,0) % plot the response against the long timestamps generated above
axis([0 1 -1 1]) % set up sensible axes limits
title('Simulation: Mass 1 Response to Input: $$ y_{0}sin(\omega_{1} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')
% perform a linear simulation for the sinusoidal excitation (mass 2)
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the long timestamps
response_mass_2_omega_1_long = 0;
% plot the figure:
figure(6)
plot(0,0) % plot the response against the long timestamps generated above
axis([0 1 -1 1]) % set up sensible axes limits
title('Simulation: Mass 2 Response to Input: $$ y_{0}sin(\omega_{1} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')
Harmonic motion of the base at :
% generate the input function using the long timestamps above
y_t_omega_2_long = 0;
% perform a linear simulation for the sinusoidal excitation (mass 1)
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the long timestamps
response_mass_1_omega_2_long = 0;
% plot the figure:
figure(7)
plot(0,0) % plot the response against the long timestamps generated above
axis([0 1 -1 1]) % set up sensible axes limits
title('Simulation: Mass 1 Response to Input: $$ y_{0}sin(\omega_{2} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')
% perform a linear simulation for the sinusoidal excitation (mass 2)
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the long timestamps
response_mass_2_omega_2_long = 0;
% plot the figure:
figure(8)
plot(0,0) % plot the response against the long timestamps generated above
axis([0 1 -1 1]) % set up sensible axes limits
title('Simulation: Mass 2 Response to Input: $$ y_{0}sin(\omega_{2} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')
Now generate a couple of plots that show more detail in the responses at the two natural frequencies. Here it is okay to plot both masses on the same figure, since you are interested in seeing how the masses move relative to one another.
% joint plot with mass 1 and mass 2 at omega_1:
% generate the input function using the short timestamps above
y_t_omega_1_short = 0;
figure(9)
% perform linear simulations for the sinusoidal excitation (mass 1 and mass 2) at omega 1
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the short timestamps
response_mass_1_omega_1_short = 0;
response_mass_2_omega_1_short = 0;
plot(0,0,0,0) % plot the response against the short timestamps generated above, you can plot both responses here in one line
legend('',''); % add a legend so you know which line is which
title('Simulation: System Response to Input: $$ y_{0}sin(\omega_{1} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')
% joint plot with mass 1 and mass 2 at omega_2:
y_t_omega_2_short = 0;
figure(10)
% perform linear simulations for the sinusoidal excitation (mass 1 and mass 2) at omega 2
% hint: use the 'lsim' function
% type 'help lsim' in the command window for more information
% use the short timestamps
response_mass_1_omega_2_short = 0;
response_mass_2_omega_2_short = 0;
plot(0,0,0,0) % plot the response against the short timestamps generated above, you can plot both responses here in one line
legend('',''); % add a legend so you know which line is which
title('Simulation: System Response to Input: $$ y_{0}sin(\omega_{2} t) $$', 'Interpreter','latex')
xlabel('')
ylabel('')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!