# Control Systems/Standard Forms

## Companion Form

A **companion form** contains the coefficients of a corresponding
characteristic polynomial along one of its far rows or columns. For
example, one companion form matrix is:

$$\begin{bmatrix} 0 & 0 & 0 & \cdots & 0 & -a_0 \\
                       1 & 0 & 0 & \cdots & 0 & -a_1 \\
                       0 & 1 & 0 & \cdots & 0 & -a_2 \\
                       0 & 0 & 1 & \cdots & 0 & -a_3 \\
                       \vdots & \vdots & \vdots &\ddots & \vdots & \vdots \\
                       0 & 0 & 0 & \cdots & 1 & -a_{n-1} 
       \end{bmatrix}$$

and another is:

$$\begin{bmatrix} -a_{n-1} & -a_{n-2} & -a_{n-3} & \cdots & -a_1 & -a_0 \\
                       1 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & 1 & 0 & \cdots & 0 & 0 \\
                       0 & 0 & 1 & \cdots & 0 & 0 \\
                       \vdots & \vdots & \vdots &\ddots & \vdots & \vdots \\
                       0 & 0 & 0 & \cdots & 1 & 0 
       \end{bmatrix}$$

Two companion forms are convenient to use in control theory, namely the
observable canonical form and the controllable canonical form. These two
forms are roughly transposes of each other (just as observability and
controllability are dual ideas). When placed in one of these forms, the
design of controllers or observers is simplified because the structure
of the system is made apparent (and is easily modified with the desired
control).

### Observable Canonical Form

**Observable-Canonical Form** is helpful in several cases, especially
for designing observers.

The observable-canonical form is as follows:

$$A = \begin{bmatrix} -a_1 &  1 & 0 & \cdots & 0 \\
                       -a_2 & 0 & 1 & \cdots & 0 \\
                       \vdots & \vdots &  \vdots & \ddots & \vdots \\
                       -a_{n-1} &  0 & 0 & \cdots & 1 \\
                       -a_n & 0 & 0 & \cdots & 0 
       \end{bmatrix}$$

$$B = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix}$$

$$C = \begin{bmatrix} 1 &  0 & \cdots & 0 \end{bmatrix}$$

### Controllable Canonical Form

**Controllable-Canonical Form** is helpful in many cases, especially for
designing controllers when the full state of the system is known.

The controllable-canonical form is as follows:

$$A = \begin{bmatrix} -a_1 & -a_2 & -a_3 & \cdots & -a_{n-1} & -a_n \\
                       1 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & 1 & 0 & \cdots & 0 & 0 \\
                       0 & 0 & 1 & \cdots & 0 & 0 \\
                       \vdots & \vdots & \vdots &\ddots & \vdots & \vdots \\
                       0 & 0 & 0 & \cdots & 1 & 0 
       \end{bmatrix}$$

$$B = \begin{bmatrix} 1 \\ 0 \\ \vdots \\ 0 \end{bmatrix}$$

$$C = \begin{bmatrix} b_1 & b_2 & b_3 & \cdots & b_n \end{bmatrix}$$

$$D = \begin{bmatrix} b_0 \end{bmatrix}$$

If we have two spaces, space *v* which is the original space of the
system (*A*, *B*, *C*, and *D*), then we can transform our system into
the *w* space which is in controllable-canonical form (*A~w~*, *B~w~*,
*C~w~*, *D~w~*) using a transformation matrix *T~w~*. We define this
transformation matrix as:

$$T = \zeta_v \zeta_w^{-1}$$

Where ζ is the controllability matrix.

Notice that we know beforehand *A~w~* and *B~w~*, since we know both the
form of the matrices and the coefficients of the equation (e.g. a linear
ODE with constant coefficients or a transfer function).

We can form ζ~w~ if we know these two matrices. We can then use this
matrix to create our transformation matrix.

We will discuss the controllable canonical form later when discussing
state feedback and closed-loop systems.

### Phase Variable Form

The **Phase Variable Form** is obtained simply by renumbering the phase
variables in the opposite order of the controllable canonical form.
Thus:

$$A_c = \begin{bmatrix} 
                           0 & 1 & \cdots & 0 & 0 & 0\\
                           \vdots & \vdots &\ddots & \vdots & \vdots & \vdots \\
                           0 & 0 & \cdots & 1 & 0 & 0\\
                           0 & 0 & \cdots & 0 & 1 & 0\\
                           0 & 0 & \cdots & 0 & 0 & 1\\
                        -a_n & -a_{n-1} & -a_{n-2} & \cdots & -a_2 & -a_1                                                                   
       \end{bmatrix}$$

$$B_c = \begin{bmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{bmatrix}$$

$$C_c = \begin{bmatrix} b_n & b_{n-1} & \cdots & b_2 & b_1 \end{bmatrix}$$

$$D_c = \begin{bmatrix} b_0 \end{bmatrix}$$

## Modal Form

In this form, the state matrix is a diagonal matrix of its
(non-repeated) eigenvalues. The control has a unitary influence on each
eigenspace, and the output is a linear combination of the contributions
from the eigenspaces (where the weights are the complex residuals at
each pole).

$$A_m = \begin{bmatrix} -p_1 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & -p_2 & 0 & \cdots & 0 & 0 \\
                       0 & 0 & -p_3 & \cdots & 0 & 0 \\
                       \vdots & \vdots & \vdots &\ddots & \vdots & \vdots \\
                       0 & 0 & 0 & \cdots & 0 & -p_n
       \end{bmatrix}$$

$$B_m = \begin{bmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{bmatrix}$$

$$C_m = \begin{bmatrix} c_1 & c_2  & \cdots & c_n \end{bmatrix}$$

$$D_m = \begin{bmatrix} D_c \end{bmatrix}$$

### Jordan Form

This \"almost diagonal\" form handles the case where eigenvalues are
repeated. The repeated eigenvalues represent a multi-dimensional
eigenspace, and so the control only enters the eigenspace once and it\'s
integrated through the other states of that small subsystem.

$$A = \begin{bmatrix} 
                    -p_1 & 1 & 0 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & -p_1 & 1 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & 0 & -p_1 & 0 & 0 & \cdots & 0 & 0 \\
                       0 & 0 & 0 & -p_4 & 0 &\cdots & 0 & 0 \\
                       \vdots & \vdots & \vdots & \vdots & \vdots &\ddots & \vdots & \vdots \\
                       0 & 0 & 0 & 0 & 0 & \cdots & 0 & -p_n
       \end{bmatrix}$$

$$B = \begin{bmatrix} 0 \\ 0 \\ 1 \\ 1 \\ \vdots \\ 1 \end{bmatrix}$$

$$C = \begin{bmatrix} c_1 & c_2 & \cdots  & c_n \end{bmatrix}$$

## Computing Standard Forms in MATLAB

MATLAB can convert a transfer function into a control canonical form by
using the command tf2ss.

`tf2ss(num, den);`\
`% num and den on the form: [x_0*s^n, x_1*s^n-1,..., x_n*s^n-n].`

MATLAB contains a function for automatically transforming a state-space
equation into a companion

(e.g., controllable or observable canonical form) form.

`[Ap, Bp, Cp, Dp, P] = canon(A, B, C, D, 'companion');`

Moving from one companion form to the other usually involves elementary
operations on matrices and vectors (e.g., transposes or interchanging
rows). Given a vector with the coefficients of a characteristic
polynomial, MATLAB can compute a companion form with the coefficients in
the top row (there are other 3 possible companion forms not generated by
that function)

`compan(P)`

Given another vector with the coefficients of a transfer function\'s
numerator polynomial, the `canon` command can do the same.

`[Ap, Bp, Cp, Dp, P] = canon(tf(Pnum,Pden), 'companion');`

The same command can be used to transform a state-space equation into a
modal (e.g., diagonal) form.

`[Ap, Bp, Cp, Dp, P] = canon(A, B, C, D, 'modal');`

However, MATLAB also includes a command to compute the Jordan form of a
matrix, a modified modal form suited for matrices with repeated
eigenvalues.

`jordan(A);`

## Computing Standard Forms by Hand

### Control Canonical Form

We are given a system that is described by the transfer function:

$$\frac{Y(s)}{U(s)} = \frac{s^2+6s+8}{s^3+9s^2+23s+15}$$

and are now tasked to obtain the state-space matrixes in control
canonical form. We first note that the order of the numerator is 2,
while the corresponding order is 3 in the denominator. This means that
we will not have any feed-forward and thus, the scalar D is 0.

We now split the transfer function into two factors:

$$\frac{Y(s)}{x_1(s)} \times \frac{x_1(s)}{U(s)} = \frac{s^2+6s+8}{1} \times \frac{1}{s^3+9s^2+23s+15}.$$

We then retrieve the time-domain description,

$$Y(s) = (s^2+6s+8)x_1.$$

$$Y(s) = s^{2} x_1+6s x_1 +8 x_1.$$

$$y(t) = \ddot{x_1} + 6\dot{x_1} +8x_1.$$

We now create two new states that describe all these derivatives. Since
the highest order of the system is 3 (in the denominator of TF), we must
create 2 new states, so that we have 3 states in total.

$$\dot{x_1} = x_2, \dot{x_2} = x_3 = \ddot{x_1}.$$

We substitute the new states into the equation above:

$$y(t) = x_3 + 6x_2 + 8x_1.$$

Now we evaluate the input of the system in a similar manner:

$$U(s) = (s^3+9s^2+23s+15)x_1.$$

$$U(s) = s^3x_1+9s^2x_1+23sx_1+15x_1.$$

$$u(t) = x_1^{(3)}+9\ddot{x_1}+23\dot{x_1}+15x_1.$$

Note that the first term is a third derivative. We can now insert our
new states into the above equation:

$$u(t) = \dot{x_3}+9x_3+23x_2+15x_1.$$

We move the derivative of the third state to the left side and get:

$$\dot{x_3} = -15x_1 - 23x_2 -9x_3 + u.$$

We are now ready to rewrite these equations in the state-space form. We
start by moving the input to the right side of the equation so that we
have an expression for each state.

$\begin{bmatrix}
         \dot{x_1} \\
         \dot{x_2} \\
         \dot{x_3} \\
\end{bmatrix}
=
\begin{bmatrix}
         0 & 1 & 0 \\
         0 & 0 & 1 \\
         -15 & 0-23 & -9 \\
\end{bmatrix}
\times
\begin{bmatrix}
         x_1 \\
         x_2 \\
         x_3 \\
\end{bmatrix}
+
\begin{bmatrix}
         0 \\
         0 \\
         1 \\
\end{bmatrix}
u$

$y =
\begin{bmatrix}
         8 & 6 & 1 \\
\end{bmatrix}
\times
\begin{bmatrix}
         x_1 \\
         x_2 \\
         x_3 \\
\end{bmatrix}
+
\begin{bmatrix}
         0 \\
\end{bmatrix}
u$

