## Estimate Parameters from Measured Data

#### Objectives

This tutorial shows how to estimate parameters of a single-input single-output (SISO) Simulink® model from measured input and output (I/O) data.

### Note

Simulink Design Optimization™ software estimates parameters from real, time-domain data only.

You can perform the following tasks using the Parameter Estimation tool:

• Load a saved session containing data

• Estimate model parameters using default settings

• Validate the model, and refine the estimation results

This tutorial uses the `spe_engine_throttle1` Simulink model, which represents an engine throttle system. The throttle system controls the flow of air and fuel mixture to the engine cylinders. The throttle body contains a butterfly valve that opens when a driver presses the accelerator pedal. Opening this valve increases the amount of fuel mixture entering the cylinders, which increases the engine speed. A DC motor controls the opening angle of the butterfly valve in the throttle system. The models for these components are described in Motor Subsystem and Throttle Subsystem.

The input to the throttle system is the motor current (in amperes), and the output is the angular position of the butterfly valve (in degrees).

Motor Subsystem.  The `Motor` subsystem contains the DC motor model. To open the model, double-click the corresponding block. Components of the `Motor` subsystemDescription
Variables

U is the input current to the motor.

T is the torque applied by the motor.

Parameters

`K`t is the torque gain of the motor, represented by `Kt` in the model.

`t`d is the input time delay of the motor, represented by `input_delay` in the model.

Equation

The torque applied by the motor is described in the following equation:

`$T\left(t\right)={K}_{t}U\left(t-{t}_{d}\right)$`

where t is time.

InputU
OutputT

Throttle Subsystem.  The `Throttle` subsystem contains the butterfly valve model. To open the model, right-click the corresponding block, and select Mask > Look Under Mask. The `Hard Stops` block models the valve angular position limit of 15° to 90°.

The following table describes the variables, parameters, states, differential equations, inputs, and outputs of the .

Components of the `Throttle` subsystemDescription
Variables

T is the torque applied by the DC motor.

θ is the angular position of the valve, represented by `x` in the model.

Thardstop is the torque applied by the hard stop.

Parameters

`J` is the valve inertia.

`c` is the valve viscous friction.

`k` is the valve spring constant.

States

$\theta$ is the angular position.

$\stackrel{˙}{\theta }$ is the angular velocity.

Equations

The mathematical system for the butterfly valve is described in the following equation:

`$J\stackrel{¨}{\theta }+c\stackrel{˙}{\theta }+k\theta =T+{T}_{hardstop}$`

where ${15}^{\circ }\le \theta \le {90}^{\circ }$, with initial conditions ${\theta }_{0}={15}^{\circ }$, and ${\stackrel{˙}{\theta }}_{0}=0$.

The torque applied by the ```Hard Stops``` block is described in the following equation:

`${T}_{hardstop}=\left\{\begin{array}{l}0,\\ K\left({90}^{\circ }-\theta \right),\\ K\left({15}^{\circ }-\theta \right),\end{array}\begin{array}{l}{15}^{\circ }\le \theta \le {90}^{\circ }\\ \theta >{90}^{\circ }\\ \theta <{15}^{\circ }\end{array}\right\}$`

where `K` is the gain of the `Hard Stops` block.

InputT
Outputθ

### Estimate Model Parameters Using Default Estimation Settings

#### Overview of the Estimation Process

Simulink Design Optimization software uses optimization techniques to estimate model parameters. In each optimization iteration, it simulates the model with the current parameter values. It computes and minimizes the error between the simulated and measured output. The estimation is complete when the optimization method finds a local minimum.

To start the estimation process, first open the engine throttle system Simulink model by typing the following at the MATLAB® prompt:

`spe_engine_throttle1`

In the Simulink Editor, select Analysis > Parameter Estimation.

This action opens a new session with the name Parameter Estimation - spe_engine_throttle1 in the Parameter Estimation tool.

### Note

#### Specify Estimation Data and Parameters

1. Load or import the estimation data. 1. If you prepared data and saved your session as described in Prepare Data for Parameter Estimation, load the preconfigured session. On the Parameter Estimation tab, click the ```Open Session``` drop down list. Select the correct option to browse to the location of your saved session, for example, ```Open from file```. Then select the MAT-file.

2. If you do not have a previously saved session, create a new experiment. on the Parameter Estimation tab, click . In the Experiments list on the left pane. You can rename it by right-clicking and selecting Rename from the list. For example, call it `NewData1`.

To import data into the experiment, right-click and select Edit... to launch the experiment editor. Import the output data by typing in the dialog box in the Outputs panel, for example `[time1,position1]`. Import the input data by typing in the dialog box in the Inputs panel, for example `[time1,input1]`. 2. Specify parameters for estimation. On the Parameter Estimation tab, click the button to open the Edit: Estimated Parameters dialog box. In the Parameters Tuned for all Experiments panel, click the button to launch the Select Model Variables dialog box.

Select the parameters `J`, `c`, `input_delay`, and `k`, and click .

### Note

In your application, if the model parameters you want to estimate are not listed in the Select Model Variables dialog box, first specify these parameters as variables. See, Add Model Parameters as Variables for Estimation. The Edit: Estimated Parameters window now looks as follows. The tool selects the parameters you add for estimation by default. When estimating a large number of parameters, you can first select a subset of parameters to estimate.

You can also first use sensitivity analysis to identify the parameters that most influence the estimation, and then specify these parameters for estimation. To open the Sensitivity Analysis tool, in the Parameter Estimation tab, click Sensitivity Analysis. In the Sensitivity Analysis tool, you can identify the model parameters that most influence the estimation problem and compute initial values for the estimation parameters.

3. Specify an experiment for estimation. On the Parameter Estimation tab, click , and select the box under the Estimation column. Click . 4. To add progress plots, click on the Parameter Estimation tab. Here you can choose the Parameter Trajectory and Estimation Cost iteration plots. You can also choose an experiment plot of measured and simulated data for `NewData1`.

5. Estimate the parameters using the default settings. On the Parameter Estimation tab, click to open the Parameter Trajectory plot and Estimation Progress Report window and estimate the parameters. The plot shows the change in the parameter values at each iteration. The Estimation Progress Report shows the iteration number, number of times the objective function is evaluated, and the value of the cost function at the end of each iteration. After the estimation converges, the Estimation Progress Report looks like this figure. The estimated parameters are saved in the Parameter Estimation tool, in the Results section of the Data Browser pane, as `EstimatedParams`. Right-click `EstimatedParams`, and select Open... to view the results. 6. Examine the estimated cost function graph. Cost function is the error between the simulated and measured output. During estimation, the default optimization method `Nonlinear least squares`, `lsqnonlin`, minimizes the cost function by changing the parameter values. The following figure displays the change in the expected cost during iterations. 7. Examine the simulated response plot to see how well the simulated output matches the measured output. The experiment plot shows that the output simulated using the estimated parameters is close to the measured outputs. ### Improve Estimation Results Using Parameter Bounds

You can improve the accuracy of estimation by specifying bounds on parameter values. This technique restricts the region in which the optimization method searches for a local minima.

The engine throttle system has these characteristics:

• All parameter values are positive.

• Maximum time delay of the system, represented by `input_delay`, is 0.1 s.

Therefore, specify 0 as the minimum value for all parameters, and 0.1 as the maximum value of `input_delay`. In the Parameter Estimation tool, click the button to specify bounds on the parameter values. For each parameter, click the right arrow toggle to display the minimum, maximum, and scale fields. Specify the minimum value for each parameter by replacing `-Inf` with `0` in the Minimum field. Specify the maximum value for `input_delay` by replacing `+Inf` with `0.1` in the corresponding Maximum field. After estimating the parameters, analyze the results using the experiment plot and the plot for expected cost. The data simulated using the estimated parameter values agree better with the measured data than when the parameter limits were not specified. ### Validate Estimated Model Parameters

After estimating model parameters, validate the model using another data set (validation data). A good match between the simulated response and the validation data indicates that you have not overfitted the model.

To validate the estimated parameters using a validation data set:

1. Create a new experiment to use for validation. Name it `ValidationData`. Import the validation I/O data, `input2` and `position2`, and the time vector, `time2` in the `ValidationData` experiment. To do this, in the Parameter Estimation tool, in the Experiments pane, right-click `ValidationData` and select Edit... to open the experiment editor. Then, type `[time2,position2]` in the output dialog box and `[time2,input2]` in the input dialog box. For more information, see Import Data for Parameter Estimation. 2. Select the experiment for validation. On the Parameter Estimation tab, click . By default, the `ValidationData` experiment is selected for estimation. Deselect the check box that corresponds to `ValidationData` for estimation and select the check box for validation. 3. Select results to use. On the Validation tab, click . Deselect `Use current parameter values` and select `EstimatedParams`, and click . 4. Select the plots for measured and simulated data, and residuals on the Validation tab. You can assess how much the data simulated using the estimated parameters agrees with the measured data using these plots. On the Validation tab, click to start validation.

5. Examine the plots.

1. Examine the experiment plot to see how well the simulated output matches the output data. The simulated response as shown in light brown on the top experiment plot is overlaid on the measured out put data, and closely matches the measured validation data.

2. Examine the residuals plot to compare the difference between the simulated response and measured data. The difference between the simulated and measured data varies between 2 and -2.5. The residuals lie within 6% of the maximum output variation and do not display any systematic patterns. This indicates a good fit between the simulated output and measured data.

6. Save the session. On the Parameter Estimation tab, click . From the drop-down list select where to save the session. Specify the file name, and click or OK to save your parameter estimation session as a MAT-file. 