This example shows how to create a single-input and single-output
grey-box model structure when you know the variance of the measurement
noise. The code in this example uses the Control System
Toolbox™ command `kalman`

for computing the Kalman gain
from the known and estimated noise variance.

This example is based on a discrete, single-input and single-output (SISO) system represented by the following state-space equations:

$$\begin{array}{l}x(kT+T)=\left[\begin{array}{cc}par1& par2\\ 1& 0\end{array}\right]x(kT)+\left[\begin{array}{c}1\\ 0\end{array}\right]u(kT)+w(kT)\\ y(kT)=\left[\begin{array}{cc}par3& par4\end{array}\right]x(kT)+e(kT)\\ x(0)=x0\end{array}$$

where *w* and *e* are
independent white-noise terms with covariance matrices *R1* and *R2*,
respectively. *R1*=E{ww'} is a 2–by-2 matrix
and *R2*=E{ee'} is a scalar. *par1*, *par2*, *par3*,
and *par4* represent the unknown parameter values
to be estimated.

Assume
that you know the variance of the measurement noise *R2* to
be 1. *R1*(1,1) is unknown and is treated as an
additional parameter *par5*. The remaining elements
of *R1* are known to be zero.

You can represent the system described in Description of the SISO System as an `idgrey`

(grey-box)
model using a function. Then, you can use this file and the `greyest`

command
to estimate the model parameters based on initial parameter guesses.

To run this example, you must load an input-output data set
and represent it as an `iddata`

or `idfrd`

object
called `data`

. For more information about this operation,
see Representing Time- and Frequency-Domain Data Using iddata Objects or Representing Frequency-Response Data Using idfrd Objects.

To estimate the parameters of a grey-box model:

Create the file

`mynoise`

that computes the state-space matrices as a function of the five unknown parameters and the auxiliary variable that represents the known variance`R2`

. The initial conditions are not parameterized; they are assumed to be zero during this estimation.### Note

`R2`

is treated as an auxiliary variable rather than assigned a value in the file to let you change this value directly at the command line and avoid editing the file.function [A,B,C,D,K] = mynoise(par,T,aux) R2 = aux(1); % Known measurement noise variance A = [par(1) par(2);1 0]; B = [1;0]; C = [par(3) par(4)]; D = 0; R1 = [par(5) 0;0 0]; [~,K] = kalman(ss(A,eye(2),C,0,T),R1,R2);

Specify initial guesses for the unknown parameter values and the auxiliary parameter value

`R2`

:par1 = 0.1; % Initial guess for A(1,1) par2 = -2; % Initial guess for A(1,2) par3 = 1; % Initial guess for C(1,1) par4 = 3; % Initial guess for C(1,2) par5 = 0.2; % Initial guess for R1(1,1) Pvec = [par1; par2; par3; par4; par5] auxVal = 1; % R2=1

Construct an

`idgrey`

model using the`mynoise`

file:Minit = idgrey('mynoise',Pvec,'d',auxVal);

The third input argument

`'d'`

specifies a discrete-time system.Estimate the model parameter values from data:

opt = greyestOptions; opt.InitialState = 'zero'; opt.Display = 'full'; Model = greyest(data,Minit,opt)

- Estimate Linear Grey-Box Models
- Estimate Continuous-Time Grey-Box Model for Heat Diffusion
- Estimate Coefficients of ODEs to Fit Given Solution
- Estimate Model Using Zero/Pole/Gain Parameters
- Estimate Nonlinear Grey-Box Models