Products & Services Industries Academia Support User Community Company

Learn more about System Identification Toolbox   

Identifying State-Space Models

What Are State-Space Models?

Definition of State-Space Models

State-space models are models that use state variables to describe a system by a set of first-order differential or difference equations, rather than by one or more nth-order differential or difference equations. State variables x(t) can be reconstructed from the measured input-output data, but are not themselves measured during an experiment.

The state-space model structure is a good choice for quick estimation because it requires only two parameters:

The model order for state-space models is an integer equal to the dimension of x(t) and relates to the number of delayed inputs and outputs used in the corresponding linear difference equation.

Continuous-Time Representation

In continuous-time, the state-space description has the following form:

It is often easier to define a parameterized state-space model in continuous time because physical laws are most often described in terms of differential equations. In this case, the matrices F, G, H, and D contain elements with physical significance—for example, material constants. x0 specifies the initial states.

Discrete-Time Representation

Discrete-time state-space models provide the same type of linear difference relationship between the inputs and the outputs as the linear ARX model, but are rearranged such that there is only one delay in the expressions. The discrete-time state-space model structure is often written in the innovations form that describes noise:

where T is the sampling interval, u(kT) is the input at time instant kT, and y(kT) is the output at time instant kT.

Relationship Between Continuous-Time and Discrete-Time State Matrices

The relationships between the discrete state-space matrices A, B, C, D, and K and the continuous-time state-space matrices F, G, H, D, and are given for piece-wise-constant input, as follows:

These relationships assume that the input is piece-wise-constant over time intervals .

The exact relationship between K and is complicated. However, for short sampling intervals T, the following approximation works well:

State-Space Representation of Transfer Functions

For linear models, the general symbolic model description is given by:

G is a transfer function that takes the input u to the output y. H is a transfer function that describes the properties of the additive output noise model.

The discrete-time state-space representation is given by the following equation:

where T is the sampling interval, u(kT) is the input at time instant kT, and y(kT) is the output at time instant kT.

The relationships between the transfer functions and the discrete-time state-space matrices are given by the following equations:

where Inx is the nx-by-nx identity matrix, Iny is the nx-by-nx identity matrix, and ny is the dimension of y and e.

Data Supported by State-Space Models

Types of Supported Data

You can estimate linear state-space models from data with the following characteristics:

You must first import your data into the MATLAB workspace, as described in Data Import and Processing.

Estimating Continuous-Time Models

Use either of the following ways to estimate continuous-time, state-space models:

Designating Data for Estimating Discrete-Time Models

You can estimate arbitrary-order, linear state-space models for both time- or frequency-domain data.

You must specify your data to have the sampling interval equal to the experimental data sampling interval.

You can set the sampling interval when you import data into the GUI or set the Ts property of the data object at the command line.

Supported State-Space Parameterizations

The System Identification Toolbox product supports the following parameterizations that indicate which parameters are estimated and which remain fixed at specific values:

You can only estimate free state-space models in discrete time. Continuous state-space models are available for canonical and structured parameterizations and grey-box models.

Preliminary Step – Estimating State-Space Model Orders

Why Estimate Model Orders?

To estimate a state-space model, you must provide a model order and one or more input delays.

To get an initial model order for your system, you can estimate a group of state-space models with a range of orders for a specific delay and compare the performance of these models. You choose the model order that include states with the highest contribution to the input-output behavior of the model and use this order as an initial guess for further modeling.

The model order is always a single integer—regardless of the number of inputs and outputs. However, the number of input delays must correspond to the number of input channels.

Estimating Model Order in the GUI

You must have already imported your data into the GUI, as described in Importing Data into the GUI.

To estimate model orders for a specific input delay:

  1. In the System Identification Tool GUI, select Estimate > Linear parametric models to open the Linear Parametric Models dialog box.

  2. In the Structure list, select State Space: n [nk].

  3. Edit the Orders field to specify a range of orders for a specific delay. For example, enter the following values for n and nk:

    1:10 [1]

      Tip   As a shortcut for entering 1:10 [1], click Order Selection.

  4. Verify that the Method is set to N4SID.

  5. Click Estimate to open the Model Order Selection window, which displays the relative measure of how much each state contributes to the input-output behavior of the model (log of singular values of the covariance matrix). The following figure shows an example plot.

  6. Select the rectangle that represents the cutoff for the states on the left that provide a significant contribution to the input-output behavior, and click Insert to estimate a model with this order. Red indicates the recommended choice. States 1 and 2 provide the most significant contribution. The contributions to the right of state 2 drop significantly. For information about using the Model Order Selection window, see Using the Model Order Selection Window.

    This action adds a new model to the Model Board in the System Identification Tool GUI. The default name of the parametric model combines the string n4s and the selected model order.

  7. Click Close to close the Model Order Selection window.

After estimating model orders, use this value as an initial guess for estimating other state-space models, as described in How to Estimate State-Space Models in the GUI.

Estimating the Model Order at the Command Line

You can estimate the state-space model order using the n4sid command.

Use following syntax to specify the range of model orders to try for a specific input delay.

m = n4sid(data,n1:n2,'nk',nk);

where data is the estimation data set, n1 and n2 specify the range of orders, and nk specifies the input delay. For multiple-input systems, nk is a vector of input delays.

This command opens the Model Order Selection window. For information about using this plot, see Using the Model Order Selection Window.

Alternatively, you can use the pem command to open the Model Order Selection window, as follows:

m = pem(Data,'nx',nn)

where nn = [n1,n2,...,nN] specifies the vector or range of orders you want to try.

To omit opening the Model Order Selection window and automatically select the best order, use the following syntax:

m = pem(Data,'best')

For a tutorial on estimating model orders for a multiple-input system, see Estimating a State-Space Model in System Identification Toolbox Getting Started Guide.

Using the Model Order Selection Window

You can generate the Model Order Selection window for your data to select the number of states that provide the highest relative contribution to the input-output behavior of the model (log of singular values of the covariance matrix).

For a procedure on generating this plot in the System Identification Tool GUI, see Estimating Model Order in the GUI. To open this plot at the command line, see Estimating the Model Order at the Command Line.

The following figure shows a sample Model Order Selection window.

The horizontal axis corresponds to the model order n. The vertical axis, called Log of Singular values, shows the singular values of a covariance matrix constructed from the observed data.

You use this plot to decide which states provide a significant relative contribution to the input-output behavior, and which states provide the smallest contribution. Based on this plot, select the rectangle that represents the cutoff for the states on the left that provide a significant contribution to the input-output behavior. The recommended choice is red.

For example, in the previous figure, states 1 and 2 provide the most significant contribution. However, the contributions of the states to the right of state 2 drop significantly. This sharp decrease in the log of the singular values after n=2 indicates that using two states is sufficient to get an accurate model.

How to Estimate State-Space Models in the GUI

Supported State-Space Models in the GUI

Only free parameterization is directly supported in the System Identification Tool GUI. You can also estimate canonical and structured parameterizations at the command line and import them into the System Identification Tool GUI for parameter estimation. For more information about state-space parameterization, see Supported State-Space Parameterizations.

Prerequisites

Before you can perform this task, you must have

Estimating State-Space Models in the GUI

To estimate a state-space model with free parameterization in the System Identification Tool GUI:

  1. In the System Identification Tool GUI, select Estimate > Linear parametric models to open the Linear Parametric Models dialog box.

  2. In the Structure list, select State Space: n [nk].

    This action updates the options in the Linear Parametric Models dialog box to correspond with this model structure. For information about each model structure, see What Are State-Space Models?.

  3. In the Orders field, specify the model order and delay, as follows:

    • For single-input models. Enter the model order integer and the input delay in terms of the number of samples. Omitting nk uses the default value nk=1.

      For example, enter 4 [2] for a fourth-order model and nk=2.

    • For multiple-input models. Enter the model order integer and the input delay vector—which is a 1-by-nu vector whose ith entry is the delay for the ith input.

      For example, for a two-input system, enter 4 [1 1] for a fourth-order model and a delay of 1 for each input.

    • For multiple-output models. Enter the model order integer the same way as for single-input models.

      Tip   To enter model order and any delays using the Order Editor dialog box, click Order Editor.

  4. Select the estimation Method as N4SID or PEM. For more information about these methods, Algorithms for Estimating State-Space Models.

  5. In the Name field, edit the name of the model or keep the default. The name of the model should be unique in the Model Board.

  6. In the Focus list, select how to weigh the relative importance of the fit at different frequencies. For more information about each option, see Options for Frequency-Weighing Focus.

  7. (PEM only) In the Initial state list, specify how you want the algorithm to treat initial states. For more information about the available options, see Options for Initial States.

      Tip   If you get an inaccurate fit, try setting a specific method for handling initial states rather than choosing it automatically.

  8. In the Covariance list, select Estimate if you want the algorithm to compute parameter uncertainties. Effects of such uncertainties are displayed on plots as model confidence regions.

    To omit estimating uncertainty, select None. Skipping uncertainty computation reduces computation time for complex models and large data sets.

  9. (PEM only) To view the estimation progress in the MATLAB Command Window, select the Trace check box. During estimation, the following information is displayed for each iteration:

    • Loss function — Equals the determinant of the estimated covariance matrix of the input noise.

    • Parameter values — Values of the model structure coefficients you specified.

    • Search direction — Change in parameter values from the previous iteration.

    • Fit improvements — Shows the actual versus expected improvements in the fit.

  10. Click Estimate to add this model to the System Identification Tool GUI.

  11. (PEM only) To stop the search and save the results after the current iteration has been completed, click Stop Iterations. To continue iterations from the current model, click the Continue iter button to assign current parameter values as initial guesses for the next search.

Next Steps

How to Estimate State-Space Models at the Command Line

Supported State-Space Models

You can only estimate discrete-time state-space models with free parameterization. Continuous state-space models are available for canonical and structured parameterizations.

Prerequisites

Before you can perform this task, you must have

Estimating State-Space Models Using pem and n4sid

You can estimate continuous-time and discrete-time polynomial model using the iterative estimation command pem that minimizes the prediction errors to obtain maximum-likelihood values. You can also use the noniterative subspace command n4sid.

Use the following general syntax to both configure and estimate state-space models:

m = pem(data,n,
             'nk',nk,
             'Property1',Value1,...,
             'PropertyN',ValueN)

where data is the estimation data, n is the model order, and nk specifies the input delays for each input.

As an alternative to pem, you can use n4sid:

m = n4sid(data,n,
              'nk',nk,
              'Property1',Value1,...,
              'PropertyN',ValueN)

For more information about the most common property-value pairs you can specify, see Common Properties to Specify Model Estimation.

For detailed information about the syntax, see the corresponding reference page.

For more information about estimating model order, see Estimating the Model Order at the Command Line.

For information about validating your model, see Overview of Model Validation and Plots

Common Properties to Specify Model Estimation

The following properties are common to specify in the estimation syntax:

For more information about these properties, see the idss reference page.

Choosing to Estimate D, K, and X0 Matrices

For state-space models with any parameterization, you can specify whether to estimate the K and X0 matrices, which represent the noise model and the initial states, respectively.

For state-space models with structured parameterization, you can also specify to estimate the D matrix. However, for free and canonical forms, the structure of the D matrix is set based on your choice of nk.

For more information about state-space structure, see What Are State-Space Models?.

D Matrix.   By default, the D matrix is not estimated. Set the model property nk to estimate the D matrix, as follows:

To omit estimating the D matrix, set the nk value or values to 1, which is the default.

K Matrix.   K represents the noise model.

For frequency-domain data, no noise model is estimated and K is set to 0. For time-domain data, K is estimated by default.

To modify whether K is estimated for time-domain data, you can specify the DisturbanceModel property in the estimator syntax.

Initially, you can omit estimating the noise parameters in K to focus on achieving a reasonable model for the system dynamics. After estimating the dynamic model, you can use pem to refine the model and set the K parameters to be estimated. For example:

m = pem(Data,md,'DisturbanceModel','Estimate')

where md is the dynamic model without noise.

To set K to zero, set the value of the DisturbanceModel property to 'None'. For example:

m = pem(Data,n,'DisturbanceModel','None')

XO Matrices.   X0 stores the estimated or specified initial states of the model.

To specify how to handle the initial states, set the value of the InitialStates model property. For example, to set the initial states to zero, set the InitialStates property to 'zero', as follows:

m = pem(Data,n,'InitialStates','zero')

When you estimate models using multiexperiment data and InitialStates is set to 'Estimate', X0 stores the estimated initial states corresponding to the last experiment in the data set.

For a complete list of values for the InitialStates property, see Options for Initial States.

How to Estimate Free-Parameterization State-Space Models

The default parameterization of the state-space matrices A, B, C, D, and K is free; that is, any elements in the matrices are adjustable by the estimation routines. Because the parameterization of A, B, and C is free, a basis for the state-space realization is automatically selected to give well-conditioned calculations.

You can only estimate discrete-time state-space models with any parameterization. Continuous state-space models are available for canonical and structured parameterizations only.

To estimate the disturbance model K, you must use time domain data.

Suppose that you have no knowledge about the internal structure of the discrete-time state-space model. To quickly get started, use the following syntax:

m = pem(data)

where data is your estimation data. This command estimates a state-space model for an automatically selected order between 1 and 10.

To find a black-box model of a specific order n, use the following syntax:

m = pem(Data,n)

The iterative algorithm pem is initialized by the subspace method n4sid. You can use n4sid directly, as an alternative to pem:

m = n4sid(Data,n)

How to Estimate State-Space Models with Canonical Parameterization

What Is Canonical Parameterization?

Canonical parameterization represents a state-space system in its minimal form, using the minimum number of free parameters to capture the dynamics. Thus, free parameters appear in only a few of the rows and columns in system matrices A, B, C, and D, and the remaining matrix elements are fixed to zeros and ones.

Of the two popular canonical forms, which include controllable canonical form and observable canonical form, the toolbox supports only controllable forms. Controllable canonical structures include free parameters in output rows of the A matrix, free B and K matrices, and the fixed C matrix. The representation within controllable canonical forms is not unique and the exact form depends on the actual choices of canonical indices. For more information about the distribution of free parameters in canonical forms, see the appendix on identifiability of black-box multivariable model structures in System Identification: Theory for the User, Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999 (equation 4A.16).

Estimating Canonical State-Space Models

You can estimate state-space models with canonical parameterization at the command line.

To specify a canonical form for A, B, C, and D, set the SSparameterization model property directly in the estimator syntax, as follows:

m = pem(data,n,'SSparameterization','canonical')

If you have time-domain data, the preceding command estimates a discrete-time model.

If you have continuous-time frequency-domain data, the preceding syntax estimates an nth order continuous-time state-space model with no direct contribution from the input to the output (D=0). To include a D matrix, set the nk property to 0 in the estimation, as follows:

m = pem(data,n,'SSparameterization','canonical',
               'nk',0)

You can specify additional property-value pairs similar to the free-parameterization case, as described in How to Estimate Free-Parameterization State-Space Models.

For information about validating your model, see Overview of Model Validation and Plots.

How to Estimate State-Space Models with Structured Parameterization

What Is Structured Parameterization?

Structured parameterization lets you exclude specific parameters from estimation by setting these parameters to specific values. This approach is useful when you can derive state-space matrices from physical principles and provide initial parameter values based on physical insight. You can use this approach to discover what happens if you fix specific parameter values or if you free certain parameters.

In the case of structured parameterization, there are two stages to the estimation procedure:

  1. Using the idss command to specify the structure of the state-space matrices and the initial values of the free parameters

  2. Using the pem estimation command to estimate the free model parameters

This approach differs from estimating models with free and canonical parameterizations, where it is not necessary to specify initial parameter values before the estimation. For free parameterization, there is no structure to specify because it is assumed to be unknown. For canonical parameterization, the structure is fixed to a specific form.

For information about validating your model, see Overview of Model Validation and Plots.

Specifying the State-Space Structure

To specify the state-space model structure, first define the A, B, C, D, K and X0 matrices in the MATLAB workspace.

To define a discrete-time state-space structure, use the following syntax:

m = idss(A,B,C,D,K,X0,...
         'Ts',T,...
         'SSparameterization','structured')

where A, B, C, D, and K specify both the fixed parameter values and the initial values for the free parameters. T is the sampling interval. Setting SSparameterization to 'structured' flags that you want to estimate a partial structure for this state-space model.

Similarly, to define a continuous-time state-space structure, use the following syntax:

m = idss(A,B,C,D,K,X0,...
         'Ts',0,...
         'SSparameterization','structured')

In the continuous-time case, you must set the sampling interval property Ts to zero.

After you create the nominal model structure, you must specify which parameters to estimate and which to set to specific values. To accomplish this, you must edit the structures of the following model properties: As, Bs, Cs, Ds, Ks, and x0s. These structure matrices are properties of the nominal model you constructed and have the same sizes as A, B, C, D, K, and x0, respectively. Initially, the structure matrices contain NaN values.

Specify the structure matrix values, as follows:

For example, suppose that you constructed a nominal state-space model m with the following A matrix:

A = [2 0; 0 3]

Suppose you want to fix A(1,2)=A(2,1)=0. To specify the parameters you want to fix, enter their values at the corresponding locations in the structure matrix As:

m.As = [NaN 0; 0 NaN]

The estimation algorithm only estimates the parameters in A that have a NaN value in As.

Finally, use pem to estimate the model, as described in How to Estimate State-Space Models at the Command Line.

Use physical insight, whenever possible, to initialize the parameters for the iterative search algorithm. Because it is possible that the numerical minimization gets stuck in a local minimum, try several different initialization values for the parameters. For random initialization, use the init command. When the model structure contains parameters with different orders of magnitude, try to scale the variables so that the parameters are all roughly the same magnitude.

The iterative search computes gradients of the prediction errors with respect to the parameters using numerical differentiation. The step size is specified by the nuderst M-file. The default step size is equal to 10–4 times the absolute value of a parameter or equal to 10–7, whichever is larger. To specify a different step size, edit the nuderst M-file.

Are Grey-Box Models Similar to State-Space Models with Structured Parameterization?

Structured parameterization state-space models are similar to grey-box modeling. However, the state-space models are simpler to estimate than grey-box models. To learn more about grey-box models, see ODE Parameter Estimation (Grey-Box Modeling).

Example – Estimating Structured Discrete-Time State-Space Models

In this example, you estimate the unknown parameters ( ) in the following discrete-time model:

Suppose that the nominal values of the unknown parameters ( ) are -1, 2, 3, 4, and 5, respectively.

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

To construct and estimate the parameters of this discrete-time state-space model:

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

    A = [1,-1;0,1];
    B = [2;3];
    C = [1,0];
    D = 0;
    K = [4;5];
  2. Construct the state-space model object:

    m = idss(A,B,C,D,K);
  3. Specify the parameter values in the structure matrices that you do not want to estimate:

    m.As = [1, NaN; 0 ,1];
    m.Bs = [NaN;NaN];
    m.Cs = [1, 0];
    m.Ds = 0;
    m.Ks = [NaN;NaN];
    m.x0s = [0;0];
  4. Estimate the model structure:

    m = pem(data,m)
    

    where data is name of the iddata object containing time-domain or frequency-domain data. The iterative search starts with the nominal values in the A, B, C, D, K, and x0 matrices.

Example – Estimating Structured Continuous-Time State-Space Models

In this example, you estimate the unknown parameters ( ) in the following continuous-time model:

This equation represents an electrical motor, where is the angular position of the motor shaft, and is the angular velocity. The parameter is the inverse time constant of the motor, and is the static gain from the input to the angular velocity.

The motor is at rest at t=0, but its angular position is unknown. Suppose that the approximate nominal values of the unknown parameters are and . 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:

To construct and estimate the parameters of this continuous-time state-space model:

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

      Note   The following 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.

    A = [0 1;0 -1];
    B = [0;0.25];
    C = eye(2);
    D = [0;0];
    K = zeros(2,2);
    x0 = [0;0];
  2. Construct the continuous-time state-space model object:

    m = idss(A,B,C,D,K,x0,'Ts',0);
  3. Specify the parameter values in the structure matrices that you do not want to estimate:

    m.As = [0 1;0 NaN];
    m.Bs = [0;NaN];
    m.Cs = m.c;
    m.Ds = m.d;
    m.Ks = m.k;
    m.x0s = [NaN;0]
    m.NoiseVariance = [0.01 0; 0 0.1];
  4. Estimate the model structure:

    m = pem(data,m)
    

    where data is name of the iddata object containing time-domain or frequency-domain data. 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 sampling interval as the data.

  5. To simulate this system using the sampling interval T = 0.1 for input u and the noise realization e, use the following commands:

    e = randn(300,2);
    u = idinput(300);
    simdat = iddata([],[u e],'Ts',0.1);
    y = sim(m,simdat)

    The continuous system is automatically sampled using Ts=0.1. The noise sequence is scaled according to the matrix m.noisevar.

If you discover that the motor was not initially at rest, you can estimate x2(0) by setting the second element of the x0s structure matrix to NaN, as follows:

m_new = pem(data,m,'x0s',[NaN;NaN])

How to Estimate the State-Space Equivalent of ARMAX and OE Models

You can estimate the equivalent of ARMAX and output-error (OE) multiple-output models using state-space model structures. For the ARMAX case, specify to estimate the K matrix for the state-space model. For the OE case, set K to zero.

For more information about ARMAX and OE models, see Identifying Input-Output Polynomial Models.

Options for Frequency-Weighing Focus

You can specify how the estimation algorithm weighs the fit at various frequencies. This information supports the estimation procedures How to Estimate State-Space Models in the GUI and How to Estimate State-Space Models at the Command Line.

In the System Identification Tool GUI. Set Focus to one of the following options:

At the command line. Specify the focus as an argument in the model-estimation command using the same options as in the GUI. For example, use this command to emphasize the fit between the 5 and 8 rad/s:

pem(data,4,'Focus',[5 8])

Options for Initial States

If you estimate state-space models using the iterative estimation algorithm pem, you must specify how the algorithm treats initial states. This information supports the estimation procedures How to Estimate State-Space Models in the GUI and How to Estimate State-Space Models at the Command Line.

In the System Identification Tool GUI. Set Initial state to one of the following options:

At the command line. Specify the initial states as an argument in the estimation command pem. For example, use this command to estimate a fourth-order state-space model and set the initial states to be estimated from the data:

m=pem(data,4,'InitialState','estimate')

For a complete list of values for the InitialState model property, see the idss reference page.

Algorithms for Estimating State-Space Models

For linear state-space models, you can use the subspace method, called N4SID. You can use the subspace method N4SID to get an initial model (see the n4sid reference page), and then try to refine the initial estimate using the iterative prediction-error method PEM (see the pem reference page).

N4SID is faster than PEM, but is typically less accurate and robust, and requires additional arguments that might be difficult to specify.

You can use the iterative prediction-error minimization (PEM) (maximum likelihood) algorithm for all linear and nonlinear model types.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS