MATLAB Examples

Estimate Structured Continuous-Time State-Space Models

This example shows how to estimate the unknown parameters of a continuous-time model.

In this example, you estimate ${\theta _1},{\theta _2},{\theta _3}$ in the following continuous-time model:

\dot x(t) = \left[ {\begin{array}{*{20}{c}}
0&{{\theta _1}}
\end{array}} \right]x(t) + \left[ {\begin{array}{*{20}{c}}
{{\theta _2}}
\end{array}} \right]u(t)\\
y(t) = \left[ {\begin{array}{*{20}{c}}
\end{array}} \right]x(t) + e(t)\\
x(0) = \left[ {\begin{array}{*{20}{c}}
{{\theta _3}}\\
\end{array}} \right]

This equation represents an electrical motor, where ${y_1}(t) = {x_1}(t)$ is the angular position of the motor shaft, and ${y_2}(t) = {x_2}(t)$ is the angular velocity. The parameter $- {\theta _1}$ is the inverse time constant of the motor, and ${\theta _2}$ $/$ ${\theta _1}$ is the static gain from the input to the angular velocity.

The motor is at rest at t=0 , but its angular position ${\theta _3}$ is unknown. Suppose that the approximate nominal values of the unknown parameters are ${\theta _1} =  - 1$ and ${\theta _2} = 0.25$.

The variance of the errors in the position measurement is 0.01 , and the variance in the angular velocity measurements is 0.1 . For more information about this example, see the section on state-space models in System Identification: Theory for the User, Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999.

The continuous-time state-space model structure is defined by the following equation:

\dot x(t) = Fx(t) + Gu(t) + \tilde Kw(t)\\
y(t) = Hx(t) + Du(t) + w(t)\\
x(0) = x0

Construct the parameter matrices and initialize the parameter values using the nominal parameter values.

A = [0 1;0 -1];
B = [0;0.25];
C = eye(2);
D = [0;0];
K = zeros(2,2);
x0 = [0;0];

The matrices correspond to continuous-time representation. However, to be consistent with the idss object property name, this example uses A, B, and C instead of F, G, and H.

Construct the continuous-time state-space model object.

m = idss(A,B,C,D,K,'Ts',0);

Specify the parameter values in the structure matrices that you do not want to estimate.

S = m.Structure;
S.A.Free(1,:) = false;
S.A.Free(2,1) = false;
S.B.Free(1) = false;
S.C.Free = false;
S.D.Free = false;
S.K.Free = false;
m.Structure = S;
m.NoiseVariance = [0.01 0; 0 0.1];

The initial state is partially unknown. Use the InitialState option of the ssestOptions option set to configure the estimation behavior of X0.

opt = ssestOptions;
opt.InitialState = idpar(x0);
opt.InitialState.Free(2) = false;

Estimate the model structure.

z = iddata(y,u,0.1);
m = ssest(z,m,opt);

The iterative search for a minimum is initialized by the parameters in the nominal model m . The continuous-time model is sampled using the same sample time as the data during estimation.

Simulate this system using the sample time T=0.1 for input u and the noise realization e.

e = randn(300,2);
u1 = idinput(300);
simdat = iddata([],u1,'Ts',0.1);
simopt = simOptions('AddNoise',true,'NoiseData',e);
y1 = sim(m,simdat,simopt);

The continuous system is sampled using Ts=0.1 for simulation purposes. The noise sequence is scaled according to the matrix m.NoiseVariance .

If you discover that the motor was not initially at rest, you can estimate ${x_2}(0)$ by setting the second element of the InitialState parameter to be free.

opt.InitialState.Free(2) = true;
m_new = ssest(z,m,opt);