# Convert a linear difference equation into a controllable state-space model

I have the following linear difference equation (which is an discrete-time SISO ARX model):

$y(k)+\sum_{i=1}^{n}a_iy(k-i)=\sum_{i=1}^{n}b_iu(k-i)$

and I need to transform it in an equivalent state-space model in controllable canonical form, that is:

$\begin{pmatrix}x_1(k+1)\\ x_2(k+1)\\ \vdots\\ x_{n-1}(k+1)\\ x_n(k+1)\end{pmatrix} = \begin{pmatrix}0 & 1 & 0 & \ldots & 0 \\ 0 & 0 & 1 & \ldots & 0 \\ \vdots & \vdots & \vdots & \ldots & \vdots \\ 0 & 0 & 0 & \ldots & 1 \\ -a_n & -a_{n-1} & -a_{n-2} & \ldots & -a_1\end{pmatrix}\begin{pmatrix}x_1(k)\\ x_2(k)\\ \vdots\\ x_{n-1}(k)\\ x_n(k)\end{pmatrix}+\begin{pmatrix}0\\ 0\\ \vdots\\ 0\\ 1\end{pmatrix}u(k),$ $y(k) = \begin{pmatrix}b_n & b_{n-1} & \ldots & b_2 & b_1\end{pmatrix}\begin{pmatrix}x_1(k)\\ x_2(k)\\ \vdots\\ x_{n-1}(k)\\ x_n(k)\end{pmatrix}$

I am unable to find a connection between $y(\cdot)$ and $x_i(\cdot)$ variables, so that if I have data representing $y$ values I can find the related $x_i$ values. I need this because I want to use state-feedback control (e.g., LQR).

Can someone help me?

Any hint for the MIMO case?

Thank you very much!!

-

$y(k) = -\sum_{i=1}^n a_i y(k-i) + \sum_{i=1}^n b_i u(k-i)$
Now, let's define $\mathbf{x_k} = \left(\begin{array}{c} y(k-1) \\ y(k-2) \\ \vdots \\ y(k-n) \end{array}\right)$, and $\mathbf{u_k} = \left(\begin{array}{c} u(k-1) \\ u(k-2) \\ \vdots \\ u(k-n) \end{array}\right)$.
Then, $\mathbf{x_{k+1}} = \mathbf{Ax_k}+\mathbf{Bu_k}$, where $\mathbf{A} = \rm{diag}(-a_1,-a_2,\ldots,-a_n)$, and $\mathbf{B} = \rm{diag}(b_1,b_2,\ldots,b_n)$.
Finally, $y(k) = \left(1\ 1\ \cdots\ 1\right)\mathbf{x_k}$.