How to use the lsim function

I would like to check to see if the transfer function I developed through experimentation is correct by using two other transfer functions. This is my code:
%%Loading the data from excel to MATLAB for all trials
P5 = 'P5.csv'; % First trial: gain = 5
P5V2 = 'P5V2.csv'; % Second trial: gain = 5
P5V3 = 'P5V3.csv'; % Third trial: gain = 5
P4 = 'P4.csv'; % Lower gain
P6 = 'P5V3.csv'; % Higher gain
P10 = 'P10.csv';
P15 = 'P15.csv';
P2 = 'P2.csv';
% Reading the xls files into MATLAB
p5 = csvread(P5);
p5v2 = csvread(P5V2);
p5v3 = csvread(P5V3);
p4 = csvread(P4);
p6 = csvread(P6);
p10 = csvread(P10);
p15 = csvread(P15);
p2 = csvread(P2);
%%Analysis Question 1: Version 1 of Gain=5
time = p5(:,1);
output = p5(:,2);
error = p5(:,3);
% Creating a reference signal
% E = S - P, where S is the signal and P is position, then S = E + P
refsig = error + output;
% Plotting motor output vs. time of our best plot with a reference signal on
% the same graph using the hold on function
figure(1)
plot(time, refsig, 'b');
hold on
plot(time, output, 'r');
hold off
title('Motor Position Over a Period of Time at a Gain of 5');
xlabel('Time (s)');
ylabel('Motor Output');
ylim([-80 80]);
legend('Reference Signal','Motor Signal');
So want I would like to do is re-create my reference signal and simulate it in a closed loop using the 'lsim' function in MATLAB. The transfer function I checking is P5 and I am using P6 and P15 to compare the results with. So basically I am just unsure of how to use the lsim function. This is a second order system and I would like to simulate a step input.

回答(1 个)

Star Strider
Star Strider 2018-2-20

0 个投票

Use the step (link) function with your system object.

类别

帮助中心File Exchange 中查找有关 Plot Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by