You can estimate statespace models in two ways at the command line, depending upon your prior knowledge of the nature of the system and your requirements.
In this approach, you specify the model order, and, optionally,
additional model structure attributes that configure the overall structure
of the statespace matrices. You call ssest
, ssregest
or n4sid
with
data and model order as primary input arguments, and use namevalue
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 the 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 dynamics, use ssform
.
After configuring the idss
model with desired
constraints, you specify this model as an input argument to the ssest
command. You cannot use n4sid
or ssregest
for
structured estimation.
Note:

You can estimate continuoustime and discretetime statespace
models using the iterative estimation command ssest
that
minimizes the prediction errors to obtain maximumlikelihood values.
Use the following general syntax to both configure and estimate statespace models:
m = ssest(data,n,opt,Name,Value)
where data
is the estimation data, n
is
the model order, and opt
contains options for configuring
the estimation of the statespace 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 namevalue
pair input arguments that specify optional model structure attributes
such as the presence of feedthrough, the canonical form of the model,
and input delay.
As an alternative to ssest
, you can use
the noniterative subspace estimators n4sid
or ssregest
:
m = n4sid(data,n,opt,Name,Value) m = ssregest(data,n,opt,Name,Value)
Unless you specify the sample time as a namevalue pair input
argument, n4sid
and ssregest
estimate
a discretetime model, while ssest
estimates
a continuoustime model.
Note:

For information about validating your model, see Validating Models After Estimation
By default, all entries of the A, B,
and C statespace matrices are treated as free
parameters. Using the Form
namevalue 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 statespace parameterization, see:
For estimation of statespace 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
namevalue pair
input argument.
By default, ssest
estimates a
continuoustime model. If you are using data set with nonzero sample
time, data
, which includes all time domain data,
you can also estimate a discretetime model by using:
model = ssest(data,nx,'Ts',data.Ts);
If you are using continuoustime frequencydomain data, you cannot estimate a discretetime model.
By default, n4sid
and ssregest
estimate
a model whose sample time matches that of the data. Thus, for timedomain
data, n4sid
and ssregest
deliver
a discretetime model. You can estimate a continuoustime model by
using:
model = n4sid(data,nx,'Ts',0);
or
model = ssregest(data,nx,'Ts',0);
For statespace models with any parameterization, you can specify whether to estimate the D, K and X0 matrices, which represent the inputtooutput feedthrough, noise model and the initial states, respectively.
For statespace 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'
namevalue
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 Feedthrough
namevalue 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 init_sys.Structure.D
, where init_sys
is
an idss
model that represents the desired model
structure. To force no feedthrough for the ith
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 ith column of D as zero. The next line specifies all the elements of D as free, estimable parameters. The last line specifies that the ith column of the D matrix is fixed for estimation.
Alternatively, use ssform
with 'Feedthrough'
namevalue
pair.
K represents the noise matrix of the model, such that the noise component of the model is:.
$$\begin{array}{l}\dot{x}=Ax+Ke\\ {y}_{n}=Cx+e\end{array}$$
For frequencydomain data, no noise model is estimated and K is set to 0. For timedomain data, K is estimated by default in the black box estimation setup. y^{n} is the contribution of the disturbances to the model output.
Black box estimation: Use
the DisturbanceModel
namevalue 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 init_sys.Structure.K
parameter,
where init_sys
is an idss
model
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;
Alternatively, use ssform
.
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 can use 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);
where init_sys
is
the dynamic model without noise.
To set K to zero in an existing
model, you can set its Value
to 0
and Free
flag
to false
:
m.Structure.K.Value = 0; m.Structure.K.Free = false;
The initial state vector X0 is obtained as
the byproduct of model estimation. The n4sid
, ssest
and 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 n4sidOptions
(for n4sid
), ssestOptions
(for ssest
)
or ssregestOptions
(for ssregest
)
to create the estimation option set. For example, in order to hold
the initial states to zero during estimation using n4sid
:
opt = n4sidOptions;
opt.InitialState = 'zero';
[m,X0] = n4sid(data,n,opt);
The returned X0
variable is a zero vector
of length n
.
When you estimate models using multiexperiment data, the X0
matrix
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.