www.gusucode.com > mpc 案例源码 matlab代码程序 > mpc/IdentifyPlantFromDataExample.m

    %% Identify Plant from Data at the Command Line
% This example shows how to identify a plant model at the
% command line. For information on identifying models using the System
% Identification app, see <docid:ident_gs.bqs6ip8>.

%% 
% Load the measured input/output data.
load plantIO

%%
% This command imports the plant input signal, |u|, plant output signal,
% |y|, and sample time, |Ts| to the MATLAB(R) workspace.

%%
% Create an |iddata| object from the input and output data.
mydata = iddata(y,u,Ts);

%%
% You can optionally assign channel names and units for the input and
% output signals.
mydata.InputName = 'Voltage';
mydata.InputUnit = 'V';
mydata.OutputName = 'Position';
mydata.OutputUnit = 'cm';

%%
% Typically, you must preprocess identification I/O data before estimating
% a model. For this example, remove the offsets from the input and output
% signals by detrending the data.
mydatad = detrend(mydata);

%%
% You can also remove offsets by creating an |ssestOptions| object and
% specifying the |InputOffset| and |OutputOffset| options.

%% 
% For this example, estimate a second-order, linear state-space model using
% the detrended data. To estimate a discrete-time model, specify the sample
% time as |Ts|.
ss1 = ssest(mydatad,2,'Ts',Ts)

%%
% You can use this identified plant as the internal prediction model for
% your MPC controller. When you do so, the controller converts the
% identified model to a discrete-time, state-space model.

%%
% By default, the MPC controller discards any unmeasured noise components
% from your identified model. To configure noise channels as unmeasured
% disturbances, you must first create an augmented state-space model from
% your identified model. For example:
ss2 = ss(ss1,'augmented')

%%
% This command creates a state-space model, |ss2|, with two input groups,
% |Measured| and |Noise|, for the measured and noise inputs respectively.
% When you import the augmented model into your MPC controller, channels in
% the |Noise| input group are defined as unmeasured disturbances.