Estimate State-Space Models at the Command Line
Black Box vs. Structured State-Space Model Estimation
You can estimate state-space models in two ways at the command line, depending upon your prior knowledge of the nature of the system and your requirements.
Black Box Estimation
In this approach, you specify the model order, and, optionally, additional model structure
attributes that configure the overall structure of the state-space matrices. You call
n4sid with data and model order as primary input arguments, and use name-value
pairs to specify any additional attributes, such as model sample time, presence of feedthrough,
absence of noise component, etc. You do not work directly with the coefficients of the
A, B, C, D,
K, and X0 matrices.
In this approach, you create and configure an
idss model that contains the initial values for all the system matrices. You use
Structure property of the
idss model to specify all
the parameter constraints. For example, you can designate certain coefficients of system
matrices as fixed and impose minimum/maximum bounds on the values of the others. For quick
configuration of the parameterization and whether to estimate feedthrough and disturbance
Using the structured estimation approach, you cannot specify relationships among state-space coefficients. Each coefficient is essentially considered to be independent of others. For imposing dependencies, or to use more complex forms of parameterization, use the
Estimating State-Space Models Using ssest, ssregest and n4sid
You can estimate continuous-time and discrete-time state-space models using the iterative
ssest that minimizes the prediction errors to obtain
Use the following general syntax to both configure and estimate state-space models:
m = ssest(data,n,opt,Name,Value)
data is the estimation data,
n is the model
opt contains options for configuring the estimation of the
state-space models. These options include the handling of the initial conditions, input and
output offsets, estimation focus and search algorithm options. opt can be followed by name-value
pair input arguments that specify optional model structure attributes such as the presence of
feedthrough, the canonical form of the model, and input delay.
m = n4sid(data,n,opt,Name,Value) m = ssregest(data,n,opt,Name,Value)
Unless you specify the sample time as a name-value pair input argument,
ssregest estimate a discrete-time model,
ssest estimates a continuous-time model.
n4sid to initialize the state-space
matrices, and takes longer than
n4sid to estimate a model but typically
provides a better fit to data.
For information about validating your model, see Validating Models After Estimation
Choosing the Structure of A, B, C Matrices
By default, all entries of the A, B, and
C state-space matrices are treated as free parameters. Using the
Form name-value pair input argument of
ssest , you can choose various canonical forms, such as the companion and modal
forms, that use fewer parameters.
For more information about estimating a specific state-space parameterization, see:
Choosing Between Continuous-Time and Discrete-Time Representations
For estimation of state-space models, you have the option of switching the model sample
time between zero and that of the estimation data. You can do this using the
Ts name-value pair input argument.
ssestestimates a continuous-time model. If you are using data set with nonzero sample time,
data, which includes all time domain data, you can also estimate a discrete-time model by using:
model = ssest(data,nx,'Ts',data.Ts);
If you are using continuous-time frequency-domain data, you cannot estimate a discrete-time model.
ssregestestimate a model whose sample time matches that of the data. Thus, for time-domain data,
ssregestdeliver a discrete-time model. You can estimate a continuous-time model by using:
model = n4sid(data,nx,'Ts',0);
model = ssregest(data,nx,'Ts',0);
Choosing to Estimate D, K, and X0 Matrices
For state-space models with any parameterization, you can specify whether to estimate the D, K and X0 matrices, which represent the input-to-output feedthrough, 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 for the
'Feedthrough' name-value pair input argument.
By default, the D matrix is not estimated and its value is fixed to zero, except for static models.
Black box estimation: Use the
Feedthroughname-value pair input argument to denote the presence or absence of feedthrough from individual inputs. For example, in case of a two input model such that there is feedthrough from only the second input, use:
model = n4sid(data,n,'Feedthrough',[false true]);
Structured estimation: Configure the values of the
idssmodel that represents the desired model structure. To force no feedthrough for the i-th input, set:
init_sys.Structure.D.Value(:,i) = 0; init_sys.Structure.D.Free = true; init_sys.Structure.D.Free(:,i) = false;
The first line specifies the value of the i-th column of D as zero. The next line specifies all the elements of D as free, estimable parameters. The last line specifies that the i-th column of the D matrix is fixed for estimation.
K represents the noise matrix of the model, such that the noise component of the model is:.
For frequency-domain data, no noise model is estimated and K is set to 0. For time-domain data, K is estimated by default in the black box estimation setup. yn is the contribution of the disturbances to the model output.
Black box estimation: Use the
DisturbanceModelname-value pair input argument to indicate if the disturbance component is fixed to zero (specify
Value = 'none') or estimated as a free parameter (specify
Value = 'estimate'). For example, use :
model = n4sid(data,n,'DisturbanceModel','none');
Structured estimation: Configure the value of the
idssmodel that represents the desired model structure. You can fix some K matrix coefficients to known values and prescribe minimum/maximum bounds for free coefficients. For example, to estimate only the first column of the K matrix for a two output model:
kpar = init_sys.Structure.K; kpar.Free(:,1) = true; kpar.Free(:,2) = false; kpar.Value(:,2) = 0; % second column value is fixed to zero init_sys.Structure.K = kpar;
When not sure how to easily fix or free all coefficients of K,
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
ssest to refine the model while configuring the
K parameters to be free. For example:
init_sys = ssest(data, n,'DisturbanceModel','none'); init_sys.Structure.K.Free = true; sys = ssest(data,init_sys);
init_sys is the dynamic model without noise.
To set K to zero in an existing model, you can set its
Free flag to
m.Structure.K.Value = 0; m.Structure.K.Free = false;
The initial state vector X0 is obtained as the by-product of model
ssregest commands return the value of X0 as their
second output arguments. You can choose how to handle initial conditions during model
estimation by using the
InitialState estimation option. Use
ssregest) to create the estimation
option set. For example, in order to hold the initial states to zero during estimation using
opt = n4sidOptions;
opt.InitialState = 'zero';
[m,X0] = n4sid(data,n,opt);
X0 variable is a zero vector of length
When you estimate models using multiexperiment data, the
contains as many columns as data experiments.
For a complete list of values for the
InitialStates option, see Specifying Initial States for Iterative Estimation Algorithms.