Skip to Main Content Skip to Search
Product Documentation

compare - Compare model output and measured output

Syntax

compare(data,sys)
compare(data,sys,prediction_horizon)
compare(data,sys,style,prediction_horizon)
compare(data,sys1,...,sysN,style,prediction_horizon)
compare(data,sys1,style1,...,sysN,styleN,prediction_horizon)
compare(data,sys1,...,___,opt)
[y,fit,x0] = compare(data,___)

Description

compare(data,sys) plots the simulated response of a dynamic system model, sys, superimposed over validation data, data, for comparison. The plot also displays the normalized root mean square (NRMSE) measure of the goodness of the fit.

compare(data,sys,prediction_horizon) compares the predicted response of sys to the measured response in data. Measured output values in data up to time t-prediction_horizon are used to predict the output of sys at time t.

The matching of the input/output channels in data and sys is based on the channel names. So, it is possible to evaluate models that do not use all the input channels that are available in data.

compare(data,sys,style,prediction_horizon) allows specification of the line style, color, or marker for the plot.

compare(data,sys1,...,sysN,style,prediction_horizon) compares multiple dynamic systems responses in a single figure.

compare(data,sys1,style1,...,sysN,styleN,prediction_horizon) compares systems responses using the color, linestyle, and markers specified by the style strings.

compare(data,sys1,...,___,opt) configures the comparison using an option set, opt.

[y,fit,x0] = compare(data,___) returns the model response, y, goodness of fit value, fit, and the initial states, x0. No plot is generated.

Input Arguments

data

Validation data.

Specify data as either an iddata or idfrd object.

If sys is an iddata object, then data must be an iddata object with matching domain, number of experiments and time or frequency vectors.

If sys is a frequency response model (idfrd or frd), then data must be a frequency response model too.

data can represent either time- or frequency domain data when comparing with linear models. data must be time-domain data when comparing with a nonlinear model.

For frequency domain data, the real and imaginary parts of the corresponding frequency functions are shown in separate axes.

When data is an FRD model, the frequency responses of data and sys are plotted.

sys

Dynamic system model or data object.

Specify sys as either a dynamic system model or an iddata object.

When the time or frequency units of data do not match those of sys, sys is rescaled to match the units of data.

prediction_horizon

Prediction horizon.

Specify prediction_horizon as Inf to obtain a pure simulation of the system.

prediction_horizon is ignored when sys is an iddata object, an FRD model or a dynamic system with no noise component. prediction_horizon is also ignored when using frequency response validation data.

For time-series models, use a finite value for prediction_horizon.

Default: Inf

style

Line style, marker, and color of both the linear and marker, specified as a one-, two-, or three-part string enclosed in single quotes (' '). The elements of the string can appear in any order. The string can specify only the line style, the marker, or the color.

For more information about configuring the style string, see Colors, Line Styles, and Markers in the MATLAB documentation.

opt

Comparison option set.

opt is an option set that specifies, among other options, the following:

  • handling of initial conditions

  • sample range for computing fit numbers

  • data offsets

  • output weighting

Use compareOptions to create the option set.

Output Arguments

y

Model response.

Measured output values in data up to time t = t-prediction_horizon are used to predict the output of sys at time t.

For multi-model comparisons, y is a cell array, with one entry for each input model.

For multi-experiment data, y is a cell array, with one entry for each experiment.

For multi-model comparisons using multi-experiment data, y is an Nsys-by-Nexp cell array. Here, Nsys is the number of models, and Nexp is the number of experiments.

If sys is a model array, then, y is an array, with an entry corresponding to each model in sys and experiment in data..

fit

NRMSE fitness value.

The fit is calculated (in percentage) using :

where y is the validation data output and is the output of sys.

For FRD models, fit is calculated by comparing the complex frequency response; the magnitude and phase curves shown in the plot are not compared separately.

If data is an iddata object, fit is an Ny-by-1 vector, where Ny is the number of outputs.

If data is an FRD model with Ny outputs and Nu inputs, fit is an Ny-by-Nu matrix. Each entry of fit corresponds to an input/output pair in sys.

For multi-model comparisons, fit is a cell array, with one entry for each input model.

For multi-experiment data, fit is a cell array, with one entry for each experiment.

For multi-model comparisons using multi-experiment data, fit is an Nsys-by-Nexp cell array. Here, Nsys is the number of models, and Nexp is the number of experiments.

x0

Initial conditions used to compute system response.

When sys is an frd or iddata object, x0 is [].

For multi-model comparisons, x0 is a cell array, with one entry for each input model.

For multi-experiment data, x0 is a cell array, with one entry for each experiment.

For multi-model comparisons using multi-experiment data, x0 is an Nsys-by-Nexp cell array. Here, Nsys is the number of models, and Nexp is the number of experiments.

Examples

Compare Estimated Model to Data

Compare the output of an estimated state-space model to measured data.

Estimate a state-space model for measured data.

load iddata1 z1;
sys = ssest(z1,3)

sys, an idss model, is a continuous-time state-space model.

Compare the 10 step ahead predicted output to the measured output.

prediction_horizon = 10;
compare(z1,sys,prediction_horizon);

Compare Multiple Estimated Models

Compare the outputs of an estimated process model, and an estimated Output-Error polynomial model to measured data.

Estimate a process model and an Output-Error polynomial for frequency response data.

load demofr  % frequency response data
zfr = AMP.*exp(1i*PHA*pi/180);  
Ts = 0.1;
data = idfrd(zfr,W,Ts);  
sys1 = procest(data,'P2UDZ'); 
sys2 = oe(data,[2 2 1]);

sys1, an idproc model, is a continuous-time process model. sys2, an idpoly model, is a discrete-time Output-Error model.

Compare the frequency response of the estimated models to data.

compare(data,sys1,'g',sys2,'r');

Compare Estimated Model to Data and Specify Comparison Options

Compare an estimated model to measured data and specify that the initial conditions be estimated such that the prediction error of the observed output is minimized.

Estimate a transfer function for measured data.

load iddata1 z1;
sys = tfest(z1,3)

sys, an idtf model, is a continuous-time transfer function model.

Create an option set to specify the initial condition handling.

opt = compareOptions('InitialCondition','e');

Compare the estimated transfer function model's output to the measured data using the comparison option set.

compare(z1,sys,opt);

See Also

bode | chgFreqUnit | chgTimeUnit | compareOptions | forecast | goodnessOfFit | interp | predict | resid | sim

  


Free Control Systems Interactive Kit

Learn more about resources for designing, testing, and implementing control systems.

Get free kit

Trials Available

Try the latest control systems products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS