Documentation

# canon

Canonical state-space realization

## Syntax

``csys = canon(sys,type)``
``csys = canon(sys,'modal',condt)``
``````[csys,T]= canon(___)``````

## Description

example

````csys = canon(sys,type)` transforms the linear model `sys` into a canonical state-space model `csys`. `type` specifies whether `csys` is in modal or companion form.For information on controllable and observable canonical forms, see Canonical State-Space Realizations.```

example

````csys = canon(sys,'modal',condt)` specifies an upper bound `condt` on the condition number of the block-diagonalizing transformation. Use `condt` if you have close lying eigenvalues in `csys`.```

example

``````[csys,T]= canon(___)``` also returns the state-coordinate transformation matrix `T` that relates the states of the state-space model `sys` to the states of `csys`.```

## Examples

collapse all

`aircraftPitchModel.mat` contains the state-space matrices of an aircraft where the input is elevator deflection angle $\delta$ and the output is the aircraft pitch angle $\theta$.

`$\begin{array}{l}\left[\begin{array}{c}\underset{}{\overset{˙}{\alpha }}\\ \underset{}{\overset{˙}{q}}\\ \underset{}{\overset{˙}{\theta }}\end{array}\right]\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{ccc}-0.313& 56.7& 0\\ -0.0139& -0.426& 0\\ 0& 56.7& 0\end{array}\right]\left[\begin{array}{c}\alpha \\ q\\ \theta \end{array}\right]+\left[\begin{array}{c}0.232\\ 0.0203\\ 0\end{array}\right]\left[\delta \right]\\ \phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}y\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{ccc}0& 0& 1\end{array}\right]\left[\begin{array}{c}\alpha \\ q\\ \theta \end{array}\right]+\left[0\right]\left[\delta \right]\end{array}$`

Load the model data to the workspace and create the state-space model `sys`.

```load('aircraftPitchModel.mat'); sys = ss(A,B,C,D)```
```sys = A = x1 x2 x3 x1 -0.313 56.7 0 x2 -0.0139 -0.426 0 x3 0 56.7 0 B = u1 x1 0.232 x2 0.0203 x3 0 C = x1 x2 x3 y1 0 0 1 D = u1 y1 0 Continuous-time state-space model. ```

Convert the resultant state-space model `sys` to companion canonical form.

`csys = canon(sys,'companion')`
```csys = A = x1 x2 x3 x1 0 0 -1.709e-16 x2 1 0 -0.9215 x3 0 1 -0.739 B = u1 x1 1 x2 0 x3 0 C = x1 x2 x3 y1 0 1.151 -0.6732 D = u1 y1 0 Continuous-time state-space model. ```

`csys` is the companion canonical form of `sys`.

`pendulumModelCart.mat` contains the state-space model of an inverted pendulum on a cart where the outputs are the cart displacement `x` and the pendulum angle $\theta$. The control input `u` is the horizontal force on the cart.

`$\begin{array}{l}\left[\begin{array}{c}\underset{}{\overset{˙}{x}}\\ \underset{}{\overset{¨}{x}}\\ \underset{}{\overset{˙}{\theta }}\\ \underset{}{\overset{¨}{\theta }}\end{array}\right]\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{cccc}0& 1& 0& 0\\ 0& -0.1& 3& 0\\ 0& 0& 0& 1\\ 0& -0.5& 30& 0\end{array}\right]\left[\begin{array}{c}x\\ \underset{}{\overset{˙}{x}}\\ \theta \\ \underset{}{\overset{˙}{\theta }}\end{array}\right]+\left[\begin{array}{c}0\\ 2\\ 0\\ 5\end{array}\right]u\\ \phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}y\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 0& 1& 0\end{array}\right]\left[\begin{array}{c}x\\ \underset{}{\overset{˙}{x}}\\ \theta \\ \underset{}{\overset{˙}{\theta }}\end{array}\right]+\left[\begin{array}{c}0\\ 0\end{array}\right]u\end{array}$`

First, load the state-space model `sys` to the workspace.

`load('pendulumCartModel.mat','sys');`

Convert `sys` to modal canonical form and extract the transformation matrix.

`[csys,T] = canon(sys,'modal')`
```csys = A = x1 x2 x3 x4 x1 0 0 0 0 x2 0 5.453 0 0 x3 0 0 -5.503 0 x4 0 0 0 -0.05 B = u1 x1 1.875 x2 -6.009 x3 6.386 x4 -2.409 C = x1 x2 x3 x4 y1 16 -0.007321 -0.007411 12.45 y2 0 -0.07388 -0.07344 -0.01038 D = u1 y1 0 y2 0 Continuous-time state-space model. ```
```T = 4×4 0.0625 1.2500 -0.0000 -0.1250 0 0.1123 -6.7981 -1.2468 0 0.1140 -6.7768 1.2316 0 -1.6061 -0.0080 0.1606 ```

`csys` is the modal canonical form of `sys`, while `T` represents the transformation between the state vectors of `sys` and `csys`.

For this example, consider the following system with doubled poles and clusters of close poles:

`$sys\left(s\right)=100\frac{\left(s-1\right)\left(s+1\right)}{s\left(s+10\right)\left(s+10.0001\right){\left(s-\left(1+i\right)\right)}^{2}{\left(s-\left(1-i\right)\right)}^{2}}$`

Create a `zpk` model of this system and convert it to modal canonical form using the string `'modal'`.

```sys = zpk([1 -1],[0 -10 -10.0001 1+1i 1-1i 1+1i 1-1i],100); csys1 = canon(sys,'modal'); csys1.A```
```ans = 7×7 0 0 0 0 0 0 0 0 1.0000 1.0000 0 0 0 0 0 -1.0000 1.0000 2.0548 0 0 0 0 0 0 1.0000 1.0000 0 0 0 0 0 -1.0000 1.0000 0 0 0 0 0 0 0 -10.0000 8.0573 0 0 0 0 0 0 -10.0001 ```
`csys1.B`
```ans = 7×1 0.3200 -0.0066 0.0540 -0.1950 1.0637 0 4.0378 ```

`sys` has a pair of poles at `s` `=` `-10` and `s` `=` `-10.0001,` and two complex poles of multiplicity 2 at `s` `=` `1+i` and `s` `=` `1-i`. As a result, the modal form `csys1` is a state-space model with a block of size 2 for the two poles near `s` `=` `-10`, and a block of size 4 for the complex eigenvalues.

Now, separate the two poles near `s` `=` `-10` by increasing the value of the condition number of the block-diagonalizing transformation. Use a value of `1e10` for this example.

```csys2 = canon(sys,'modal',1e10); csys2.A```
```ans = 7×7 0 0 0 0 0 0 0 0 1.0000 1.0000 0 0 0 0 0 -1.0000 1.0000 2.0548 0 0 0 0 0 0 1.0000 1.0000 0 0 0 0 0 -1.0000 1.0000 0 0 0 0 0 0 0 -10.0000 0 0 0 0 0 0 0 -10.0001 ```
```format shortE csys2.B```
```ans = 7×1 3.2000e-01 -6.5691e-03 5.4046e-02 -1.9502e-01 1.0637e+00 3.2533e+05 3.2533e+05 ```

The `A` matrix of `csys2` includes separate diagonal elements for the poles near `s` `=` `-10`. Increasing the condition number results in some very large values in the `B` matrix.

The file `icEngine.mat` contains one data set with 1500 input-output samples collected at the a sampling rate of 0.04 seconds. The input `u(t)` is the voltage (V) controlling the By-Pass Idle Air Valve (BPAV), and the output `y(t)` is the engine speed (RPM/100).

Use the data in `icEngine.mat` to create a state-space model with identifiable parameters.

```load icEngine.mat z = iddata(y,u,0.04); sys = n4sid(z,4,'InputDelay',2);```

Convert the identified state-space model `sys` to companion canonical form.

`csys = canon(sys,'companion');`

Obtain the covariance of the resulting form by running a zero-iteration update to model parameters.

```opt = ssestOptions; opt.SearchOptions.MaxIterations = 0; csys = ssest(z,csys,opt);```

Compare frequency response confidence bounds of `sys` to `csys`.

```h = bodeplot(sys,csys,'r.'); showConfidence(h)```

The frequency response confidence bounds are identical.

## Input Arguments

collapse all

Dynamic system, specified as a SISO, or MIMO dynamic system model. Dynamic systems that you can use include:

You cannot use frequency-response data models such as `frd` models.

Transformation type, specified as either `'modal'` or `'companion'`. If `type` is unspecified, then `canon` converts the specified dynamic system model to modal canonical form by default.

The companion canonical form is the same as the observable canonical form. For information on controllable and observable canonical forms, see Canonical State-Space Realizations.

• Modal Form

In modal form, A is a block-diagonal matrix. The block size is typically 1-by-1 for real eigenvalues and 2-by-2 for complex eigenvalues. However, if there are repeated eigenvalues or clusters of nearby eigenvalues, the block size can be larger.

For example, for a system with eigenvalues $\left({\lambda }_{1},\sigma ±j\omega ,{\lambda }_{2}\right)$, the modal A matrix is of the form

`$\left[\begin{array}{cccc}{\lambda }_{1}& 0& 0& 0\\ 0& \sigma & \omega & 0\\ 0& -\omega & \sigma & 0\\ 0& 0& 0& {\lambda }_{2}\end{array}\right]$`
• Companion Form

In the companion realization, the characteristic polynomial of the system appears explicitly in the rightmost column of the A matrix. For a system with characteristic polynomial

`$P\left(s\right)={s}^{n}+{\alpha }_{1}{s}^{n-1}+\dots +{\alpha }_{n-1}s+{\alpha }_{n}$`

the corresponding companion A matrix is

The companion transformation requires that the system is controllable from the first input. The transformation to companion form is based on the controllability matrix which is almost always numerically singular for mid-range orders. Hence, avoid using it when possible.

The companion canonical form is the same as the observable canonical form. For more information on observable and controllable canonical forms, see Canonical State-Space Realizations.

Upper bound on the condition number of the block-diagonalizing transformation, specified as a positive scalar. This argument is available only when `type` is set to `'modal'`.

Increase `condt` to reduce the size of the eigenvalue clusters in the A matrix of `csys`. Setting ```condt = Inf``` diagonalizes matrix A.

## Output Arguments

collapse all

Canonical state-space form of the dynamic model, returned as an `ss` model object. `csys` is a state-space realization of `sys` in the canonical form specified by `type`.

Transformation matrix, returned as an n-by-n matrix, where n is the number of states. `T` is the transformation between the state vector x of the state-space model `sys` and the state vector xc of `csys`:

xc = Tx

.

This argument is available only when `sys` is an `ss` model object.

## Limitations

• You cannot use frequency-response data models to convert to canonical state-space form.

• The companion form is poorly conditioned for most state-space computations, that is, the transformation to companion form is based on the controllability matrix which is almost always numerically singular for mid-range orders. Hence, avoid using it when possible.

## Algorithms

The `canon` command uses the `bdschur` command to convert `sys` into modal form and to compute the transformation `T`. If `sys` is not a state-space model, `canon` first converts it to state space using `ss`.

The reduction to companion form uses a state similarity transformation based on the controllability matrix [1].

## References

[1] Kailath, T. Linear Systems, Prentice-Hall, 1980.