MATLAB Answers

Unexpected results using step with input offset. Why does it behave different to lsim?

17 views (last 30 days)
puqeko on 16 Apr 2018
Edited: puqeko on 16 Apr 2018
I'm trying to understand why MATLAB produces different results when modelling the response of a system using lsim and step. For example, we can consider the following system which models two apposing propellors on a rotating arm. The system equation is
Here, x is the angle in degrees and r is a step input that goes from -15 degrees to +15 degrees at t=0 (t for time). The meaning of the constants is not relevant to my question. The transfer function is
The response is then plotted via two methods. The first uses step(sys, t, opts) with opts = stepDataOptions where the InputOffset is -15 degrees and the StepAmplitude is 30 degrees. Secondly, a state based model with initial conditions is plotted with lsim(A,B,C,D,u,t,y0). The two outputs are shown below with parameters chosen to be alpha=1,beta=3.6,gam=0.9,Kp=1,Kd=0.5,Ki=0.2;.
The step() function has a response with incorrect overshoot (or no overshoot in this particular case). I surmise this is due to invalid initial conditions. The step function seems to calculate initial conditions based on the steady state of the system at the initial reference value (i.e. -15 degrees). Specifically, the offset in the image above appears to be due to a difference in the initial value for xdotdot. Why does step(...) seem to calculate initial conditions differently?
Further description:
The initial conditions for this system as calculated for state based model are
x0 = y0;
xdot0 = 0;
xdotdot0 = beta*Kp*(top) - beta*Kp*bot - gam*bot;
i.e. The initial angle y0 is -15 degrees, the initial angular velocity is zero (since the arm is initially stationary), and the initial angular acceleration can be calculated from the system equation using the other initial conditions (where the integral term is also zero).
Note: For systems with steady state error, step will not start with an initial angle of -15 degrees. Since I wish for the initial angle to always be exactly -15 degrees, I've corrected for steady state error using the dc gain of the transfer function (see code below). However, the particular parameters selected above have unit gain so the difference in initial offset can be ignored in this example. However, setting Ki=0 will introduce steady state error in the system and both functions produce the same result. The problem seems to only occur when there is no steady state error.
By experimentation, I found that the last term ( -gam*bot ) in the xdotdot0 calculation represents the difference between the two outputs. Removing this term causes lsim to output the same incorrect result as step. I have no idea how this relates to the general way step calculates initial conditions from the transfer function or why step calculates initial values differently. The documentation does not seem to offer any insights on step's initial conditions. I would have expected step to output the same result as lsim.
If someone is able to explain why step produces different results in these sorts of cases, and how it calculates initial conditions, it would be greatly appreciated. Thanks for your time.
Code for example:
Plots the response of a simple system to an offset step response using two modelling methods.
% model the arm moving from angle top to angle bot
top = 15;
bot = -15;
% set system parameters
alpha=1.0; beta=3.6; gam=0.9;
Kp = 1; Kd = 0.5; Ki = 0.2;
% generate step responce with step(sys, t, opts)...
sys = tf([beta*Kp, beta*Ki], [1, alpha+beta*Kd, gam+beta*Kp, beta*Ki]);
% account from steady state error in initial conditions so that we always
% start at bot
gain = dcgain(sys);
if gain == 0
y0 = 0;
gain = 1;
t = (0:0.1:10)';
opt = stepDataOptions;
opt.StepAmplitude = top - bot*(1/gain);
opt.InputOffset = bot*(1/gain);
y_step = step(sys, t, opt);
% State based model with lsim(A,B,C,D,u,t,y0)
% initial conditions
x0 = bot;
xdot0 = 0;
xdotdot0 = beta*Kp*(top) - beta*Kp*bot - gam*bot;
% ^^ can remove last term (- gam*bot) to match step behaviour???
A=[-(alpha+beta*Kd) -(gam+beta*Kp) -beta*Ki; 1 0 0; 0 1 0];
B=[1;0;0]; C=[0 0 1]; D=0;
R=ones(length(t),1)*top; % reference as of t=0 is top for all t
% plot
plot(t, y_step, t, Y_lsim);
legend('step()', 'lsim()');
grid on;

Answers (0)

Community Treasure Hunt

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

Start Hunting!