## Estimate Process Models at the Command Line

### Prerequisites

Before you can perform this task, you must have

### Using procest to Estimate Process Models

You can estimate process models using the iterative estimation method `procest` that minimizes the prediction errors to obtain maximum likelihood estimates. The resulting models are stored as `idproc` model objects.

You can use the following general syntax to both configure and estimate process models:

`m = procest(data,mod_struc,opt)`

`data` is the estimation data and `mod_struc` is one of the following:

• A character vector that represents the process model structure, as described in Process Model Structure Specification.

• A template `idproc` model. `opt` is an option set for configuring the estimation of the process model, such as handling of initial conditions, input offset and numerical search method.

Tip

You do not need to construct the model object using `idproc` before estimation unless you want to specify initial parameter guesses, minimum/maximum bounds, or fixed parameter values, as described in Estimate Process Models with Fixed Parameters.

You can use `procest` to refine parameter estimates of an existing process model, as described in Refine Linear Parametric Models.

For detailed information, see `procest` and `idproc`.

### Estimate Process Models with Free Parameters

This example shows how to estimate the parameters of a first-order process model:

`$G\left(s\right)=\frac{{K}_{p}}{1+s{T}_{p1}}{e}^{-s{T}_{d}}$`

This process has two inputs and the response from each input is estimated by a first-order process model. All parameters are free to vary.

`load co2data`

Specify known sample time of 0.5 min.

`Ts = 0.5;`

Split data set into estimation data `ze` and validation data `zv`.

```ze = iddata(Output_exp1,Input_exp1,Ts,... 'TimeUnit','min'); zv = iddata(Output_exp2,Input_exp2,Ts,... 'TimeUnit','min');```

Estimate model with one pole, a delay, and a first-order disturbance component. The data contains known offsets. Specify them using the `InputOffset` and `OutputOffset` options.

```opt = procestOptions; opt.InputOffset = [170;50]; opt.OutputOffset = -45; opt.Display = 'on'; opt.DisturbanceModel = 'arma1'; m = procest(ze,'p1d',opt)```
```m = Process model with 2 inputs: y = G11(s)u1 + G12(s)u2 From input "u1" to output "y1": Kp G11(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = 2.6553 Tp1 = 0.15515 Td = 2.3175 From input "u2" to output "y1": Kp G12(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = 9.9756 Tp1 = 2.0653 Td = 4.9195 An additive ARMA disturbance model exists for output "y1": y = G u + (C/D)e C(s) = s + 2.676 D(s) = s + 0.6228 Parameterization: {'P1D'} {'P1D'} Number of free coefficients: 8 Use "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using PROCEST on time domain data "ze". Fit to estimation data: 91.07% (prediction focus) FPE: 2.431, MSE: 2.412 ```

Use dot notation to get the value of any model parameter. For example, get the value of dc gain parameter `Kp` .

`m.Kp`
```ans = 1×2 2.6553 9.9756 ```

### Estimate Process Models with Fixed Parameters

This example shows how to estimate a process model with fixed parameters.

When you know the values of certain parameters in the model and want to estimate only the values you do not know, you must specify the fixed parameters after creating the `idproc` model object. Use the following commands to prepare the data and construct a process model with one pole and a delay:

`load co2data`

Specify known sample time is 0.5 minutes.

`Ts = 0.5;`

Split data set into estimation data `ze` and validation data `zv`.

```ze = iddata(Output_exp1,Input_exp1,Ts,... 'TimeUnit','min'); zv = iddata(Output_exp2,Input_exp2,Ts,... 'TimeUnit','min'); mod = idproc({'p1d','p1d'},'TimeUnit','min')```
```mod = Process model with 2 inputs: y = G11(s)u1 + G12(s)u2 From input 1 to output 1: Kp G11(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = NaN Tp1 = NaN Td = NaN From input 2 to output 1: Kp G12(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = NaN Tp1 = NaN Td = NaN Parameterization: {'P1D'} {'P1D'} Number of free coefficients: 6 Use "getpvec", "getcov" for parameters and their uncertainties. Status: Created by direct construction or transformation. Not estimated. ```

The model parameters `Kp` , `Tp1` , and `Td` are assigned `NaN` values, which means that the parameters have not yet been estimated from the data.

Use the `Structure` model property to specify the initial guesses for unknown parameters, minimum/maximum parameter bounds and fix known parameters.

Set the value of `Kp` for the second transfer function to `10` and specify it as a fixed parameter. Initialize the delay values for the two transfer functions to 2 and 5 minutes, respectively. Specify them as free estimation parameters.

```mod.Structure(2).Kp.Value = 10; mod.Structure(2).Kp.Free = false; mod.Structure(1).Tp1.Value = 2; mod.Structure(2).Td.Value = 5;```

Estimate `Tp1` and `Td` only.

`mod_proc = procest(ze,mod)`
```mod_proc = Process model with 2 inputs: y = G11(s)u1 + G12(s)u2 From input "u1" to output "y1": Kp G11(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = -3.2213 Tp1 = 2.1707 Td = 4.44 From input "u2" to output "y1": Kp G12(s) = ---------- * exp(-Td*s) 1+Tp1*s Kp = 10 Tp1 = 2.0764 Td = 4.5205 Parameterization: {'P1D'} {'P1D'} Number of free coefficients: 5 Use "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using PROCEST on time domain data "ze". Fit to estimation data: 77.44% FPE: 15.5, MSE: 15.39 ```

In this case, the value of `Kp` is fixed, but `Tp1` and `Td` are estimated.