Documentation

# ss

Create state-space model, convert to state-space model

## Syntax

sys = ss(A,B,C,D)
sys = ss(A,B,C,D,Ts)
sys = ss(D)
sys = ss(A,B,C,D,ltisys)
sys_ss = ss(sys)
sys_ss = ss(sys,'minimal')
sys_ss = ss(sys,'explicit')
sys_ss = ss(sys, 'measured')
sys_ss = ss(sys, 'noise')
sys_ss = ss(sys, 'augmented')

## Description

Use ss to create state-space models (ss model objects) with real- or complex-valued matrices or to convert dynamic system models to state-space model form. You can also use ss to create Generalized state-space (genss) models.

### Creation of State-Space Models

sys = ss(A,B,C,D) creates a state-space model object representing the continuous-time state-space model

$\begin{array}{l}\stackrel{˙}{x}=Ax+Bu\\ y=Cx+Du\end{array}$

For a model with Nx states, Ny outputs, and Nu inputs:

• A is an Nx-by-Nx real- or complex-valued matrix.

• B is an Nx-by-Nu real- or complex-valued matrix.

• C is an Ny-by-Nx real- or complex-valued matrix.

• D is an Ny-by-Nu real- or complex-valued matrix.

To set D = 0 , set D to the scalar 0 (zero), regardless of the dimension.

sys = ss(A,B,C,D,Ts) creates the discrete-time model

$\begin{array}{l}x\left[n+1\right]=Ax\left[n\right]+Bu\left[n\right]\\ y\left[n\right]=Cx\left[n\right]+Du\left[n\right]\end{array}$

with sample time Ts (in seconds). Set Ts = -1 or Ts = [] to leave the sample time unspecified.

sys = ss(D) specifies a static gain matrix D and is equivalent to

sys = ss([],[],[],D)

sys = ss(A,B,C,D,ltisys) creates a state-space model with properties inherited from the model ltisys (including the sample time).

Any of the previous syntaxes can be followed by property name/property value pairs.

'PropertyName',PropertyValue

Each pair specifies a particular property of the model, for example, the input names or some notes on the model history. See Properties for more information about available ss model object properties.

The following expression:

sys = ss(A,B,C,D,'Property1',Value1,...,'PropertyN',ValueN)

is equivalent to the sequence of commands:

sys = ss(A,B,C,D)
set(sys,'Property1',Value1,...,'PropertyN',ValueN)

### Conversion to State Space

sys_ss = ss(sys) converts a dynamic system model sys to state-space form. The output sys_ss is an equivalent state-space model (ss model object). This operation is known as state-space realization.

sys_ss = ss(sys,'minimal') produces a state-space realization with no uncontrollable or unobservable states. This state-space realization is equivalent to sys_ss = minreal(ss(sys)).

sys_ss = ss(sys,'explicit') computes an explicit realization (E = I) of the dynamic system model sys. If sys is improper, ss returns an error.

### Note

Conversions to state space are not uniquely defined in the SISO case. They are also not guaranteed to produce a minimal realization in the MIMO case. For more information, see Recommended Working Representation.

### Conversion of Identified Models

An identified model is represented by an input-output equation of the form , where u(t) is the set of measured input channels and e(t) represents the noise channels. If Λ = LL' represents the covariance of noise e(t), this equation can also be written as , where .

sys_ss = ss(sys) or sys_ss = ss(sys, 'measured') converts the measured component of an identified linear model into the state-space form. sys is a model of type idss, idproc, idtf, idpoly, or idgrey. sys_ss represents the relationship between u and y.

sys_ss = ss(sys, 'noise') converts the noise component of an identified linear model into the state space form. It represents the relationship between the noise input v(t) and output y_noise = HL v(t). The noise input channels belong to the InputGroup 'Noise'. The names of the noise input channels are v@yname, where yname is the name of the corresponding output channel. sys_ss has as many inputs as outputs.

sys_ss = ss(sys, 'augmented') converts both the measured and noise dynamics into a state-space model. sys_ss has ny+nu inputs such that the first nu inputs represent the channels u(t) while the remaining by channels represent the noise channels v(t). sys_ss.InputGroup contains 2 input groups- 'measured' and 'noise'. sys_ss.InputGroup.Measured is set to 1:nu while sys_ss.InputGroup.Noise is set to nu+1:nu+ny. sys_ss represents the equation

### Tip

An identified nonlinear model cannot be converted into a state-space form. Use linear approximation functions such as linearize and linapp.

### Creation of Generalized State-Space Models

You can use the syntax:

gensys = ss(A,B,C,D)

to create a Generalized state-space (genss) model when one or more of the matrices A, B, C, D is a tunable realp or genmat model. For more information about Generalized state-space models, see Models with Tunable Coefficients.

## Properties

ss objects have the following properties:

## Examples

### Create Discrete-Time State-Space Model

Create a state-space model with a sample time of 0.25 seconds and the following state-space matrices:

$A=\left[\begin{array}{cc}0& 1\\ -5& -2\end{array}\right]\phantom{\rule{1em}{0ex}}B=\left[\begin{array}{c}0\\ 3\end{array}\right]\phantom{\rule{1em}{0ex}}C=\left[\phantom{\rule{0.1em}{0ex}}\begin{array}{cc}0& 1\end{array}\right]\phantom{\rule{1em}{0ex}}D=\left[\phantom{\rule{0.1em}{0ex}}0\phantom{\rule{0.1em}{0ex}}\right]$

Specify the state-space matrices.

A = [0 1;-5 -2];
B = [0;3];
C = [0 1];
D = 0;

Specify the sample time.

Ts = 0.25;

Create the state-space model.

sys = ss(A,B,C,D,Ts);

### Specify State and Input Names for Discrete-Time State-Space Model

Create state-space matrices and specify sample time.

A = [0 1;-5 -2];
B = [0;3];
C = [0 1];
D = 0;
Ts = 0.05;

Create state-space model, specifying the state and input names.

sys = ss(A,B,C,D,Ts,'StateName',{'Position' 'Velocity'},...
'InputName','Force');

The number of state and input names must be consistent with the dimensions of A, B, C, and D.

### Convert Transfer Function to State-Space Model

Compute the state-space model of the following transfer function:

$H\left(s\right)=\left[\begin{array}{c}\frac{s+1}{{s}^{3}+3{s}^{2}+3s+2}\\ \frac{{s}^{2}+3}{{s}^{2}+s+1}\end{array}\right]$

Create the transfer function model.

H = [tf([1 1],[1 3 3 2]) ; tf([1 0 3],[1 1 1])];

Convert this model to a state-space model.

sys = ss(H);

Examine the size of the state-space model.

size(sys)
State-space model with 2 outputs, 1 inputs, and 5 states.

The number of states is equal to the cumulative order of the SISO entries in H(s).

To obtain a minimal realization of H(s), enter

sys = ss(H,'minimal');
size(sys)
State-space model with 2 outputs, 1 inputs, and 3 states.

The resulting model has an order of three, which is the minimum number of states needed to represent H(s). To see this number of states, refactor H(s) as the product of a first-order system and a second-order system.

$H\left(s\right)=\left[\begin{array}{cc}\frac{1}{s+2}& 0\\ 0& 1\end{array}\right]\left[\begin{array}{c}\frac{s+1}{{s}^{2}+s+1}\\ \frac{{s}^{2}+3}{{s}^{2}+s+1}\end{array}\right]$

### Explicit Realization of Descriptor State-Space Model

Create a descriptor state-space model (EI).

a = [2 -4; 4 2];
b = [-1; 0.5];
c = [-0.5, -2];
d = [-1];
e = [1 0; -3 0.5];
sysd = dss(a,b,c,d,e);

Compute an explicit realization of the system (E = I).

syse = ss(sysd,'explicit')
syse =

A =
x1   x2
x1    2   -4
x2   20  -20

B =
u1
x1  -1
x2  -5

C =
x1    x2
y1  -0.5    -2

D =
u1
y1  -1

Continuous-time state-space model.

Confirm that the descriptor and explicit realizations have equivalent dynamics.

bodeplot(sysd,syse,'g--')

### Create State-Space Model with Both Fixed and Tunable Parameters

This example shows how to create a state-space genss model having both fixed and tunable parameters.

$A=\left[\begin{array}{cc}1& a+b\\ 0& ab\end{array}\right],\phantom{\rule{1em}{0ex}}B=\left[\begin{array}{c}-3.0\\ 1.5\end{array}\right],\phantom{\rule{1em}{0ex}}C=\left[\begin{array}{cc}0.3& 0\end{array}\right],\phantom{\rule{1em}{0ex}}D=0,$

where a and b are tunable parameters, whose initial values are -1 and 3, respectively.

Create the tunable parameters using realp.

a = realp('a',-1);
b = realp('b',3);

Define a generalized matrix using algebraic expressions of a and b.

A = [1 a+b;0 a*b];

A is a generalized matrix whose Blocks property contains a and b. The initial value of A is [1 2;0 -3], from the initial values of a and b.

Create the fixed-value state-space matrices.

B = [-3.0;1.5];
C = [0.3 0];
D = 0;

Use ss to create the state-space model.

sys = ss(A,B,C,D)
sys =

Generalized continuous-time state-space model with 1 outputs, 1 inputs, 2 states, and the following blocks:
a: Scalar parameter, 2 occurrences.
b: Scalar parameter, 2 occurrences.

Type "ss(sys)" to see the current value, "get(sys)" to see all properties, and "sys.Blocks" to interact with the blocks.

sys is a generalized LTI model (genss) with tunable parameters a and b. Confirm that the A property of sys is stored as a generalized matrix.

sys.A
ans =

Generalized matrix with 2 rows, 2 columns, and the following blocks:
a: Scalar parameter, 2 occurrences.
b: Scalar parameter, 2 occurrences.

Type "double(ans)" to see the current value, "get(ans)" to see all properties, and "ans.Blocks" to interact with the blocks.

### Extract Components from Identified State-Space Model

Extract the measured and noise components of an identified polynomial model into two separate state-space models. The former (measured component) can serve as a plant model while the latter can serve as a disturbance model for control system design.

z = iddata(y,u,0.04);
sys = ssest(z,3);

sysMeas = ss(sys,'measured')
sysNoise = ss(sys,'noise')

Alternatively, use ss(sys) to extract the measured component.

## Algorithms

For TF to SS model conversion, ss(sys_tf) returns a modified version of the controllable canonical form. It uses an algorithm similar to tf2ss, but further rescales the state vector to compress the numerical range in state matrix A and to improve numerics in subsequent computations.

For ZPK to SS conversion, ss(sys_zpk) uses direct form II structures, as defined in signal processing texts. See Discrete-Time Signal Processing by Oppenheim and Schafer for details.

For example, in the following code, A and sys.A differ by a diagonal state transformation:

n=[1 1];
d=[1 1 10];
[A,B,C,D]=tf2ss(n,d);
sys=ss(tf(n,d));
A

A =

-1   -10
1     0

sys.A

ans =
-1    -5
2     0

For details, see balance.