Quantcast

Documentation Center

  • Trial Software
  • Product Updates

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

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

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:

<argumentlist>

a,b,c,d,e

State-space matrices.

  • a — State matrix A. Square real- or complex-valued matrix with as many rows as states.

  • b — Input-to-state matrix B. Real- or complex-valued matrix with as many rows as states and as many columns as inputs.

  • c — State-to-output matrix C. Real- or complex-valued matrix with as many rows as outputs and as many columns as states.

  • d — Feedthrough matrix D. Real- or complex-valued matrix with as many rows as outputs and as many columns as inputs.

  • eE matrix for implicit (descriptor) state-space models. By default e = [], meaning that the state equation is explicit. To specify an implicit state equation E dx/dt = Ax + Bu, set this property to a square matrix of the same size as a. See dss for more information about creating descriptor state-space models.

Scaled

Logical value indicating whether scaling is enabled or disabled.

When Scaled = 0 (false), most numerical algorithms acting on the state-space model automatically rescale the state vector to improve numerical accuracy. You can disable such auto-scaling by setting Scaled = 1 (true). For more information about scaling, see prescale.

StateName

State names. For first-order models, set StateName to a string. For models with two or more states, set StateName to a cell array of strings . Use an empty string '' for unnamed states.

StateUnit

State units. Use StateUnit to keep track of the units each state is expressed in. For first-order models, set StateUnit to a string. For models with two or more states, set StateUnit to a cell array of strings. StateUnit has no effect on system behavior.

InternalDelay

Vector storing internal delays.

Internal delays arise, for example, when closing feedback loops on systems with delays, or when connecting delayed systems in series or parallel. For more information about internal delays, see Closing Feedback Loops with Time Delays in the Control System Toolbox™ User's Guide.

For continuous-time models, internal delays are expressed in the time unit specified by the TimeUnit property of the model. For discrete-time models, internal delays are expressed as integer multiples of the sampling period Ts. For example, InternalDelay = 3 means a delay of three sampling periods.

You can modify the values of internal delays. However, the number of entries in sys.InternalDelay cannot change, because it is a structural property of the model.

InputDelay — Input delays0 (default) | scalar | vector

Input delay for each input channel, specified as a numeric vector. For continuous-time systems, specify input delays in the time unit stored in the TimeUnit property. For discrete-time systems, specify input delays in integer multiples of the sampling period Ts. For example, InputDelay = 3 means a delay of three sampling periods.

For a system with Nu inputs, set InputDelay to an Nu-by-1 vector. Each entry of this vector is a numerical value that represents the input delay for the corresponding input channel.

You can also set InputDelay to a scalar value to apply the same delay to all channels.

OutputDelay

Output delays. OutputDelay is a numeric vector specifying a time delay for each output channel. For continuous-time systems, specify output delays in the time unit stored in the TimeUnit property. For discrete-time systems, specify output delays in integer multiples of the sampling period Ts. For example, OutputDelay = 3 means a delay of three sampling periods.

For a system with Ny outputs, set OutputDelay to an Ny-by-1 vector, where each entry is a numerical value representing the output delay for the corresponding output channel. You can also set OutputDelay to a scalar value to apply the same delay to all channels.

Ts

Sampling time. For continuous-time models, Ts = 0. For discrete-time models, Ts is a positive scalar representing the sampling period. This value is expressed in the unit specified by the TimeUnit property of the model. To denote a discrete-time model with unspecified sampling time, set Ts = -1.

Changing this property does not discretize or resample the model. Use c2d and d2c to convert between continuous- and discrete-time representations. Use d2d to change the sampling time of a discrete-time system.

TimeUnit

String representing the unit of the time variable. For continuous-time models, this property represents any time delays in the model. For discrete-time models, it represents the sampling time Ts. Use any of the following values:

  • 'nanoseconds'

  • 'microseconds'

  • 'milliseconds'

  • 'seconds'

  • 'minutes'

  • 'hours'

  • 'days'

  • 'weeks'

  • 'months'

  • 'years'

Changing this property changes the overall system behavior. Use chgTimeUnit to convert between time units without modifying system behavior.

InputName

Input channel names. Set InputName to a string for single-input model. For a multi-input model, set InputName to a cell array of strings.

Alternatively, use automatic vector expansion to assign input names for multi-input models. For example, if sys is a two-input model, enter:

sys.InputName = 'controls';

The input names automatically expand to {'controls(1)';'controls(2)'}.

You can use the shorthand notation u to refer to the InputName property. For example, sys.u is equivalent to sys.InputName.

Input channel names have several uses, including:

  • Identifying channels on model display and plots

  • Extracting subsystems of MIMO systems

  • Specifying connection points when interconnecting models

InputUnit

Input channel units. Use InputUnit to keep track of input signal units. For a single-input model, set InputUnit to a string. For a multi-input model, set InputUnit to a cell array of strings. InputUnit has no effect on system behavior.

InputGroup

Input channel groups. The InputGroup property lets you assign the input channels of MIMO systems into groups and refer to each group by name. Specify input groups as a structure. In this structure, field names are the group names, and field values are the input channels belonging to each group. For example:

sys.InputGroup.controls = [1 2];
sys.InputGroup.noise = [3 5];

creates input groups named controls and noise that include input channels 1, 2 and 3, 5, respectively. You can then extract the subsystem from the controls inputs to all outputs using:

sys(:,'controls')

OutputName

Output channel names. Set OutputName to a string for single-output model. For a multi-output model, set OutputName to a cell array of strings.

Alternatively, use automatic vector expansion to assign output names for multi-output models. For example, if sys is a two-output model, enter:

sys.OutputName = 'measurements';

The output names to automatically expand to {'measurements(1)';'measurements(2)'}.

You can use the shorthand notation y to refer to the OutputName property. For example, sys.y is equivalent to sys.OutputName.

Output channel names have several uses, including:

  • Identifying channels on model display and plots

  • Extracting subsystems of MIMO systems

  • Specifying connection points when interconnecting models

OutputUnit

Output channel units. Use OutputUnit to keep track of output signal units. For a single-output model, set OutputUnit to a string. For a multi-output model, set OutputUnit to a cell array of strings. OutputUnit has no effect on system behavior.

OutputGroup

Output channel groups. The OutputGroup property lets you assign the output channels of MIMO systems into groups and refer to each group by name. Specify output groups as a structure. In this structure, field names are the group names, and field values are the output channels belonging to each group. For example:

sys.OutputGroup.temperature = [1];
sys.InputGroup.measurement = [3 5];

creates output groups named temperature and measurement that include output channels 1, and 3, 5, respectively. You can then extract the subsystem from all inputs to the measurement outputs using:

sys('measurement',:)

Name

System name. Set Name to a string to label the system.

Notes

Any text that you want to associate with the system. Set Notes to a string or a cell array of strings.

UserData

Any type of data you wish to associate with system. Set UserData to any MATLAB® data type.

SamplingGrid

Sampling grid for model arrays, specified as a data structure.

For model arrays that are derived by sampling one or more independent variables, this property tracks the variable values associated with each model in the array. This information appears when you display or plot the model array. Use this information to trace results back to the independent variables.

Set the field names of the data structure to the names of the sampling variables. Set the field values to the sampled variable values associated with each model in the array. All sampling variables should be numeric and scalar valued, and all arrays of sampled values should match the dimensions of the model array.

For example, suppose you create a 11-by-1 array of linear models, sysarr, by taking snapshots of a linear time-varying system at times t = 0:10. The following code stores the time samples with the linear models.

 sysarr.SamplingGrid = struct('time',0:10)

Similarly, suppose you create a 6-by-9 model array, M, by independently sampling two variables, zeta and w. The following code attaches the (zeta,w) values to M.

[zeta,w] = ndgrid(<6 values of zeta>,<9 values of w>)
M.SamplingGrid = struct('zeta',zeta,'w',w)

When you display M, each entry in the array includes the corresponding zeta and w values.

M
M(:,:,1,1) [zeta=0.3, w=5] =
 
        25
  --------------
  s^2 + 3 s + 25
 

M(:,:,2,1) [zeta=0.35, w=5] =
 
         25
  ----------------
  s^2 + 3.5 s + 25
 
...
</argumentlist>

Examples

Example 1

Discrete-Time State-Space Model

Create a state-space model with a sampling time of 0.25 s and the following state-space matrices:

To do this, enter the following commands:

A = [0 1;-5 -2];
B = [0;3];
C = [0 1];
D = 0;
sys = ss(A,B,C,D,0.25);

The last argument sets the sampling time.

Example 2

Discrete-Time State-Space Model with Custom State and Input Names

Create a discrete-time model with matrices A,B,C,D and sample time 0.05 second.

sys = ss(A,B,C,D,0.05,'statename',{'position' 'velocity'},...
                          'inputname','force',...
                          'notes','Created 01/16/11');

This model has two states labeled position and velocity, and one input labeled force (the dimensions of A,B,C,D should be consistent with these numbers of states and inputs). Finally, a note is attached with the date of creation of the model.

Example 3

Convert Transfer Function Model to State-Space Model

Convert a transfer function model to a state-space model.

by typing

H = [tf([1 1],[1 3 3 2]) ; tf([1 0 3],[1 1 1])];
sys = ss(H);
size(sys)
State-space model with 2 outputs, 1 input, and 5 states.

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

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

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

The resulting state-space model has order of three, which is the minimum number of states needed to represent H(s). You can see this number of states by factoring H(s) as the product of a first-order system with a second-order system.

Example 4

Descriptor State-Space Model

Create a descriptor state-space model.

a = [2 -4; 4 2];
b = [-1; 0.5];
c = [-0.5, -2];
d = [-1];
e = [1 0; -3 0.5];
% Create a descriptor state-space model.
sys1 = dss(a,b,c,d,e); 

% Compute an explicit realization.
sys2 = ss(sys1,'explicit')

These commands produce the result:

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 model.

The result is an explicit state-space model (E = I). A Bode plot shows that sys1 and sys2 are equivalent.

bode(sys1,sys2)

Example 5

Generalized State-Space Model

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

Create a state-space model having the following state-space matrices:

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

  1. Create the tunable parameters using realp.

     a = realp('a',-1);
     b = realp('b',3);
  2. 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 M = [1 2;0 -3], from the initial values of a and b.

  3. Create the fixed-value state-space matrices.

    B = [-3.0;1.5];
    C = [0.3 0];
    D = 0;
  4. Use ss to create the state-space model.

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

sys is a generalized LTI model (genss) with tunable parameters a and b.

Example 6

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.

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

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

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

More About

expand all

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.

See Also

| | | | | |

Tutorials

Was this topic helpful?