# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# 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,prediction_horizon)
compare(data,sys1,style1,...,sysN,styleN,prediction_horizon)
compare(___,opt)
[y,fit,x0] = compare(___)

## 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.

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

To change display options, right-click the plot to access the context menu. For more details about the menu, see Tips.

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.

compare(data,sys,style,prediction_horizon) uses style to specify the line type, marker symbol, and color.

compare(data,sys1,...,sysN,prediction_horizon) compares multiple dynamic systems responses on the same axes. compare automatically chooses colors and line styles in the order specified by the ColorOrder and LineStyleOrder properties of the current axes.

compare(data,sys1,style1,...,sysN,styleN,prediction_horizon) compares multiple systems responses on the same axes using the line type, marker symbol, and color specified for each system.

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

[y,fit,x0] = compare(___) 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. sys iddata object or dynamic system model. 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 specified as one of the following: Inf — Compare simulated response of the system to data.Positive finite integer, K— Compare K-step ahead predicted response of the system to data. 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 line and marker, specified as a character vector. For example, 'b', 'b+:'. For more information about configuring style, see Specify Line Style, Color, and Markers in the MATLAB® documentation. opt Comparison option set. opt is an option set created using compareOptions, which specifies options including: Handling of initial conditionsSample range for computing fit numbersData offsetsOutput weighting

## 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 multimodel comparisons, y is a cell array, with one entry for each input model. For multiexperiment data, y is a cell array, with one entry for each experiment. For multimodel comparisons using multiexperiment data, y is an Nsys-by-Nexp cell array. 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. By default, the initial conditions required for computing the response are estimated to maximize the fit to data. Use the compareOptions option set to specify handling of initial conditions. fit NRMSE fitness value. The fit is calculated (in percentage) using: $\text{fit}=100\left(1-\frac{||y-\stackrel{^}{y}||}{||y-\text{mean}\left(y\right)||}\right)$ where y is the validation data output and $\stackrel{^}{y}$ 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 multimodel comparisons, fit is a cell array, with one entry for each input model. For multiexperiment data, fit is a cell array, with one entry for each experiment. For multimodel comparisons using multiexperiment data, fit is an Nsys-by-Nexp cell array. 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 multimodel comparisons, x0 is a cell array, with one entry for each input model. For multiexperiment data, x0 is a cell array, with one entry for each experiment. For multimodel comparisons using multiexperiment data, x0 is an Nsys-by-Nexp cell array. Nsys is the number of models, and Nexp is the number of experiments.

## Examples

collapse all

Estimate a state-space model for measured data.

sys = ssest(z1,3);

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

Compare the predicted output for 10 steps ahead to the measured output.

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

To change display options in the plot, right-click the plot to access the context menu. For example, to plot the error between the predicted output and measured output, select Error Plot from the context menu.

Compare the outputs of multiple estimated models, of differing types, to measured data.

This example compares 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 an estimated model to measured data. 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.

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);

To change display options in the plot, right-click the plot to access the context menu. For example, to view the confidence region for the simulated response, select ConfidenceRegion from the context menu. To specify number of standard deviations to plot, double-click the plot and open the Property Editor dialog box. In the dialog box, in the Options tab, specify the number of standard deviations in Confidence Region for Identified Models. The default value is 1 standard deviation.

collapse all

### Tips

• Right-clicking the plot opens the context menu, where you can access the following options:

• Systems — Select systems to view simulated or predicted response. By default, the response of all systems is plotted.

• Data Experiment — For multi-experiment data only. Toggle between data from different experiments.

• Characteristics — View the following data characteristics:

• Peak Value — View peak value of the data. Not applicable for frequency-response data.

• Peak Response — View peak response of the data. Applicable for frequency-response data only.

• Mean Value — View mean value of the data. Not applicable for frequency-domain or frequency-response data.

• Confidence Region — View the confidence region for the simulated response. Applicable when the prediction horizon is Inf. To specify number of standard deviations for plotting the response confidence region, double-click the plot and open the Property Editor dialog box. Specify the number of standard deviations in the Options tab, in Confidence Region for Identified Models. The default value is 1 standard deviation.

• Show — For frequency-domain and frequency-response data only.

• Magnitude — View magnitude of frequency response of the system.

• Phase — View phase of frequency response of the system.

• Show Validation Data — Plot validation data. By default, the validation data is always plotted.

• I/O Grouping — For datasets containing more than one input or output channel. Select grouping of input and output channels on the plot.

• None — Plot input-output channels in their own separate axes.

• All — Group all input channels together and all output channels together.

• I/O Selector — For datasets containing more than one input or output channel. Select a subset of the input and output channels to plot. By default, all output channels are plotted.

• Grid — Add grids to the plot.

• Normalize — Normalize the y-scale of all data in the plot.

• Full View — Return to full view. By default, the plot is scaled to full view.

• Prediction Horizon — For time-domain data with noise-component only. Set the prediction horizon, or choose simulation.

• Initial Condition — Specify handling of initial conditions. Not applicable for frequency-response data.

Specify as one of the following:

• Estimate — Treat the initial conditions as estimation parameters.

• Zero — Set all initial conditions to zero.

• Absorb delays and estimate — Absorb nonzero delays into the model coefficients and treat the initial conditions as estimation parameters. Use this option for discrete-time models only.

• Model Response Plot — Plot the simulated or predicted model response. Be default, the response plot is always shown.

• Error Plot — Plot the error between the model response and validation data.

• Properties — Open the Property Editor dialog box to customize plot attributes.