Professional Documents
Culture Documents
(Script file)
%
% Implements unconstrained MPC for stable SISO discrete-time system
% defined as LTI object. Simulation of measurement noise, and of
% unmeasured input and output disturbances is included.
%
% The following are editable parameters (most have defaults):
% Tref: Time constant of exponential reference trajectory
% Ts: Sampling interval
% plant: Plant definition (discrete-time SISO LTI object)
% model: Model definition (discrete-time SISO LTI object)
% P: Vector of coincidence points
% M: Control horizon
% tend: Duration of simulation
% setpoint: Setpoint trajectory (column vector) - length must exceed
% no of steps in simulation by at least max(P).
% umpast, uppast, ympast, yppast: Initial conditions of plant & model.
% sd: Standard deviation of measurement noise.
% udist: Input disturbance trajectory (column vector)
% ydist: Output disturbance trajectory (column vector)
%
% Assumes Matlab 5.3. Uses Control Toolbox LTI object class.
% No other toolboxes required.
if Tref == 0,
tend = 100*Ts;
else
tend = 10*Tref; % Duration of simulation (default 10*Tref)
end
nsteps = floor(tend/Ts); % (Number of steps in simulation).
tvec = (0:nsteps-1)'*Ts; % Column vector of time points (first one 0)
% Initial conditions:
umpast = zeros(ndenm,1);
uppast = zeros(ndenp,1);
ympast = zeros(ndenm,1); % For model response
yppast = zeros(ndenp,1); % For plant response
%%%%%%%%%%%%%%%% SIMULATION:
for k=1:nsteps,
% Simulate plant:
% Update past plant inputs
uppast = [uu(k)+udist(k);uppast(1:length(uppast)-1)];
yp(k+1) = -denp(2:ndenp+1)*yppast+nump(2:nnump+1)*uppast; % Simulation
% Update past plant outputs
yppast = [yp(k+1);yppast(1:length(yppast)-1)];
% Simulate model:
% Update past model inputs
umpast = [uu(k);umpast(1:length(umpast)-1)];
ym(k+1) = -denm(2:ndenm+1)*ympast+numm(2:nnumm+1)*umpast; % Simulation
% Update past model outputs
ympast = [ym(k+1);ympast(1:length(ympast)-1)];
end % of simulation
figure
subplot(211)
% Plot output, solid line and set-point, dottedd line:
plot(tvec,ypd(1:nsteps),'-',tvec,ypm(1:nsteps),':',...
tvec,setpoint(1:nsteps),'--');
grid;
title(...
'Plant output (solid), Measured output (dotted) and set-point (dashed)')
xlabel('Time')
subplot(212)
% plot input signal as staircase graph:
stairs(tvec,uu,'-');
hold on;
stairs(tvec,uu+udist,':')
grid;
title('Controller output (solid), Plant input (dotted)')
xlabel('Time')