Next: , Previous: fir2sys, Up: sysinterface


30.2.2 State space system interface functions

— Function File: outsys = ss (a, b, c, d, tsam, n, nz, stname, inname, outname, outlist)

Create system structure from state-space data. May be continuous, discrete, or mixed (sampled data)

Inputs

a
b
c
d
usual state space matrices.

default: d = zero matrix

tsam
sampling rate. Default: tsam = 0 (continuous system)
n
nz
number of continuous, discrete states in the system

If tsam is 0, n = rows(a), nz = 0.

If tsam is greater than zero, n = 0, nz = rows(a)

see below for system partitioning

stname
cell array of strings of state signal names

default (stname=[] on input): x_n for continuous states, xd_n for discrete states

inname
cell array of strings of input signal names

default (inname = [] on input): u_n

outname
cell array of strings of output signal names

default (outname = [] on input): y_n

outlist
list of indices of outputs y that are sampled

If tsam is 0, outlist = [].

If tsam is greater than 0, outlist = 1:rows(c).

Unlike states, discrete/continuous outputs may appear in any order.

sys2ss returns a vector yd where yd(outlist) = 1; all other entries of yd are 0.

Output

outsys
system data structure

System partitioning

Suppose for simplicity that outlist specified that the first several outputs were continuous and the remaining outputs were discrete. Then the system is partitioned as

          x = [ xc ]  (n x 1)
              [ xd ]  (nz x 1 discrete states)
          a = [ acc acd ]  b = [ bc ]
              [ adc add ]      [ bd ]
          c = [ ccc ccd ]  d = [ dc ]
              [ cdc cdd ]      [ dd ]
          
              (cdc = c(outlist,1:n), etc.)
     

with dynamic equations: d/dt xc(t) = acc*xc(t) + acd*xd(k*tsam) + bc*u(t)

xd((k+1)*tsam) = adc*xc(k*tsam) + add*xd(k*tsam) + bd*u(k*tsam)

yc(t) = ccc*xc(t) + ccd*xd(k*tsam) + dc*u(t)

yd(k*tsam) = cdc*xc(k*tsam) + cdd*xd(k*tsam) + dd*u(k*tsam)

Signal partitions

                  | continuous      | discrete               |
          ----------------------------------------------------
          states  | stname(1:n,:)   | stname((n+1):(n+nz),:) |
          ----------------------------------------------------
          outputs | outname(cout,:) | outname(outlist,:)     |
          ----------------------------------------------------
     

where cout is the list of in 1:rows(p) that are not contained in outlist. (Discrete/continuous outputs may be entered in any order desired by the user.)

Example

          octave:1> a = [1 2 3; 4 5 6; 7 8 10];
          octave:2> b = [0 0 ; 0 1 ; 1 0];
          octave:3> c = eye (3);
          octave:4> sys = ss (a, b, c, [], 0, 3, 0, ...
          >                   {"volts", "amps", "joules"});
          octave:5> sysout(sys);
          Input(s)
                  1: u_1
                  2: u_2
          
          Output(s):
                  1: y_1
                  2: y_2
                  3: y_3
          
          state-space form:
          3 continuous states, 0 discrete states
          State(s):
                  1: volts
                  2: amps
                  3: joules
          
          A matrix: 3 x 3
             1   2   3
             4   5   6
             7   8  10
          B matrix: 3 x 2
            0  0
            0  1
            1  0
          C matrix: 3 x 3
            1  0  0
            0  1  0
            0  0  1
          D matrix: 3 x 3
            0  0
            0  0
            0  0
     

Notice that the D matrix is constructed by default to the correct dimensions. Default input and output signals names were assigned since none were given.

— Function File: ss2sys (a, b, c, d, tsam, n, nz, stname, inname, outname, outlist)

Create system structure from state-space data. May be continuous, discrete, or mixed (sampled data)

Inputs

a
b
c
d
usual state space matrices.

default: d = zero matrix

tsam
sampling rate. Default: tsam = 0 (continuous system)
n
nz
number of continuous, discrete states in the system

If tsam is 0, n = rows(a), nz = 0.

If tsam is greater than zero, n = 0, nz = rows(a)

see below for system partitioning

stname
cell array of strings of state signal names

default (stname=[] on input): x_n for continuous states, xd_n for discrete states

inname
cell array of strings of input signal names

default (inname = [] on input): u_n

outname
cell array of strings of input signal names

default (outname = [] on input): y_n

outlist
list of indices of outputs y that are sampled

If tsam is 0, outlist = [].

If tsam is greater than 0, outlist = 1:rows(c).

Unlike states, discrete/continuous outputs may appear in any order.

sys2ss returns a vector yd where yd(outlist) = 1; all other entries of yd are 0.

Outputs outsys = system data structure

System partitioning

Suppose for simplicity that outlist specified that the first several outputs were continuous and the remaining outputs were discrete. Then the system is partitioned as

          x = [ xc ]  (n x 1)
              [ xd ]  (nz x 1 discrete states)
          a = [ acc acd ]  b = [ bc ]
              [ adc add ]      [ bd ]
          c = [ ccc ccd ]  d = [ dc ]
              [ cdc cdd ]      [ dd ]
          
              (cdc = c(outlist,1:n), etc.)
     

with dynamic equations: d/dt xc(t) = acc*xc(t) + acd*xd(k*tsam) + bc*u(t)

xd((k+1)*tsam) = adc*xc(k*tsam) + add*xd(k*tsam) + bd*u(k*tsam)

yc(t) = ccc*xc(t) + ccd*xd(k*tsam) + dc*u(t)

yd(k*tsam) = cdc*xc(k*tsam) + cdd*xd(k*tsam) + dd*u(k*tsam)

Signal partitions

                  | continuous      | discrete               |
          ----------------------------------------------------
          states  | stname(1:n,:)   | stname((n+1):(n+nz),:) |
          ----------------------------------------------------
          outputs | outname(cout,:) | outname(outlist,:)     |
          ----------------------------------------------------
     

where cout is the list of in 1:rows(p) that are not contained in outlist. (Discrete/continuous outputs may be entered in any order desired by the user.)

Example

          octave:1> a = [1 2 3; 4 5 6; 7 8 10];
          octave:2> b = [0 0 ; 0 1 ; 1 0];
          octave:3> c = eye (3);
          octave:4> sys = ss (a, b, c, [], 0, 3, 0,
          >                   {"volts", "amps", "joules"});
          octave:5> sysout(sys);
          Input(s)
                  1: u_1
                  2: u_2
          
          Output(s):
                  1: y_1
                  2: y_2
                  3: y_3
          
          state-space form:
          3 continuous states, 0 discrete states
          State(s):
                  1: volts
                  2: amps
                  3: joules
          
          A matrix: 3 x 3
             1   2   3
             4   5   6
             7   8  10
          B matrix: 3 x 2
            0  0
            0  1
            1  0
          C matrix: 3 x 3
            1  0  0
            0  1  0
            0  0  1
          D matrix: 3 x 3
            0  0
            0  0
            0  0
     

Notice that the D matrix is constructed by default to the correct dimensions. Default input and output signals names were assigned since none were given.

— Function File: [a, b, c, d, tsam, n, nz, stname, inname, outname, yd] = sys2ss (sys)

Extract state space representation from system data structure.

Input

sys
System data structure.

Outputs

a
b
c
d
State space matrices for sys.
tsam
Sampling time of sys (0 if continuous).
n
nz
Number of continuous, discrete states (discrete states come last in state vector x).
stname
inname
outname
Signal names (lists of strings); names of states, inputs, and outputs, respectively.
yd
Binary vector; yd(ii) is 1 if output y(ii) is discrete (sampled); otherwise yd(ii) is 0.
A warning massage is printed if the system is a mixed continuous and discrete system.

Example

          octave:1> sys=tf2sys([1 2],[3 4 5]);
          octave:2> [a,b,c,d] = sys2ss(sys)
          a =
             0.00000   1.00000
            -1.66667  -1.33333
          b =
            0
            1
          c = 0.66667  0.33333
          d = 0