State space equations, the important stuff


Both continuous and sampled time systems are considered in state space. The continuous time state space equations are usually given in the general form as \begin{eqnarray*} \vec{\dot{x}} &=& A(\vec{x}) + B(\vec{u})\cr \vec{y} &=& C(\vec{x}) + D(\vec{x}) \end{eqnarray*} (The sampled time variant should become obvious!). In the following we will consider only linear systems where $A$,$B$ and $C$ are matrices, and only strictly proper systems where $D=0$. (That is a system where all the gain of the system tends to zero as the frequency approaches infinity). We will only consider SISO systems so that $y$ and $u$ are scalars and the length of the vector $\vec{x}$ is the order of the system. Thus the equation will be of the form \begin{eqnarray*} \vec{\dot{x}} &=& A\vec{x} + Bu\cr y &=& C\vec{x} \end{eqnarray*}

The general solution to the first of the above equations is \begin{equation} x(t)=e^{At}x(0)+\int_0^t e^{A(t-\tau)}Bu(\tau)d\tau \label{eq:ss1} \end{equation}

Likewise in the sampled time domain we can describe systems as functions of the sample number $n$ so they are in the form \begin{eqnarray*} \vec{x}_{n+1} &=& \As \vec{x}_n + \Bs u_n\cr y_n &=& C \vec{x}_n \end{eqnarray*} \begin{minipage}[t]{100mm} Put into the s domain to get \begin{eqnarray*} s\vec{{x}} -\vec{x}(0) &=& A\vec{{x}} + B{u}\\ {y} &=& C\vec{{x}} \end{eqnarray*} and z domain we get \begin{eqnarray*} z\vec{x} -\vec{x}(0) &=& \As\vec{x} + \Bs u\\ y &=& C\vec{x} \end{eqnarray*} \end{minipage} \begin{minipage}[t]{50mm} Note: in most cases $x,y,z$, etc are implied from context as either $x(t)$ (continuous time), $x_n$ (sampled time), $x(s)$ (Laplace domain), $x(z)$ (z domain). Check the \TeX{} source for confirmation. \end{minipage}

We will consider some of the following continuous SISO (single input single output) transfer functions.

\begin{minipage}[t]{28mm} \underline{First order} \begin{equation} {y \over u} = {K \over {s+a}}\label{eq:fotf} \end{equation} \end{minipage}\hspace{10mm} \begin{minipage}[t]{42mm} \underline{Second order} \begin{equation} {y \over u} = {K \over {s^2+as +b}} \label{eq:sotfap} \end{equation} \begin{equation} {y \over u} = {K \over {(s+p_1)(s+p_2)}} \label{eq:sopzap} \end{equation} Second order with zero \begin{equation} {y \over u} = {K(s+r) \over {s^2+as +b}} \label{eq:sotfsz} \end{equation} \end{minipage}\hspace{10mm}\hfil \begin{minipage}[t]{57mm} \underline{Third order} \begin{equation}{y \over u} = {K(s+r) \over {s^3+as^2 +bs+c}}\label{eq:totfsz} \end{equation} \begin{equation}{y \over u} = {K(s^2+rs+q) \over {s^3+as^2 +bs+c}} \label{eq:totftz} \end{equation} or defined with poles as \begin{equation}{y \over u} = {K \over {(s+p_1)(s+p_2)(s+p_2)}}\label{eq:topzap}\end{equation} etc \end{minipage}

State space

We can put the above transfer functions into state space form. Trivially for first order ( eq \ref{eq:fotf}) that is \begin{align} \dot{x} =& [-a] x +Ku\\ y =& x \label{eq:foss} \end{align}

Controllable canonical form

For second and higher orders we can arrange the states in several ways, the first is the controllable canonical form.

\begin{minipage}[t]{70mm} The all pole second order system of eq \ref{eq:sotfap} is thus expressed in controllable canonical form as \begin{eqnarray} \dot{\vec{x}} &=& {\begin{bmatrix} 0 & 1\cr -b & -a \cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} 0 \cr K \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} 1 & 0\cr \end{bmatrix}} \vec{x} \label{eq:sossap} \end{eqnarray} The single zero given in system \ref{eq:sotfsz} changes the output equation to $$y = {\begin{bmatrix} 1 & r\cr \end{bmatrix}} \vec{x}$$ \end{minipage}\hspace{10mm}\hfil \begin{minipage}[t]{75mm} Third order Controlable canonical form \begin{eqnarray} \vec{\dot{x}} &=& {\begin{bmatrix} 0 & 1 & 0 \cr 0 & 0 & 1 \cr -c & -b & -a \cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} 0 \cr 0 \cr K \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} 1 & 0 & 0\cr \end{bmatrix}} \vec{x} \end{eqnarray} The single zero shown in system \ref{eq:totfsz} changes the output equation to $$y = {\begin{bmatrix} 1 & r & 0\cr \end{bmatrix}} \vec{x}$$ \end{minipage}

Observable canonical form

Two examples of observable canonical form are\\ \begin{minipage}[t]{50mm} \underbar{Second order} (system \ref{eq:sotfap}) \begin{eqnarray*} \vec{\dot{x}} &=& {\begin{bmatrix} 0 & -b\cr 1 & -a \cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} K \cr 0 \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} 0 & 1\cr \end{bmatrix}} \vec{x} \end{eqnarray*} \end{minipage}\hspace{10mm}\hfil \begin{minipage}[t]{60mm} \underbar{Third order} (system \ref{eq:totftz}) \begin{eqnarray*} \vec{\dot{x}} &=& {\begin{bmatrix} 0 & 0 & -c\cr 1 & 0 & -b\cr 0 & 1 & -a \cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} K \cr Kr \cr Kq \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} 0 & 1\cr \end{bmatrix}} \vec{x} \end{eqnarray*} \end{minipage}

Diagonal form

This is based on pole zero form equations.

\begin{minipage}[t]{50mm} system \ref{eq:sopzap} \begin{eqnarray*} \vec{\dot{x}} &=& {\begin{bmatrix} -p_1 & 0\cr 0 & -p_2 \cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} K \cr K \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} p_1-r & -p_2+r\cr \end{bmatrix}} \vec{x} \end{eqnarray*} \end{minipage}\hspace{10mm}\hfill \begin{minipage}[t]{70mm} We can write system \ref{eq:totfsz},\ref{eq:totftz} or \ref{eq:topzap} in the form $${y \over u}={c_1\over{(s+p_1)}}+{c_1\over{(s+p_1)}}+{c_1\over{(s+p_1)}}$$ We can then put it into diagonal form as \begin{eqnarray*} \vec{\dot{x}} &=& {\begin{bmatrix} -p_1 & 0 & 0\cr 0 & -p_2 & 0\cr 0 & 0 & -p_3\cr \end{bmatrix}} \vec{x} + {\begin{bmatrix} K \cr K \cr \end{bmatrix}} u\cr y &=& {\begin{bmatrix} c_1 & c_2 & c_3\cr \end{bmatrix}} \vec{x} \end{eqnarray*} \end{minipage}

Where there are multiple repeated poles then a more general variant known as Jordan Canonical form is used.

Conversion to Sampled time system

We can use a zero order hold to find the equivalent sampled data system to a particular state space continuous time system.

Broadly the method uses the solution to $\dot{x}=Ax$ which is $x(t)=e^{At} x(0)$ (ignoring input for the moment) by setting $x(0)$ to $x_n$ and using a sampling time of $\Delta$ we can calculate $x_{n+1}=e^{A\Delta}x_n$ and hence see that $G=e^{At}$ . The more general conversion is via the equation in the form $P=e^{F\Delta}$

Where $F=\begin{bmatrix}A & B\\ 0& 0\end{bmatrix}$ and $P=\begin{bmatrix}\As & \Bs\\ 0 & 0 \end{bmatrix}$

The expansion of these equations leads to the individual solutions \[ \As=e^{A\Delta} \] and \[ \Bs=A^{-1}\left(e^{A\Delta}-I\right)B \] So the inverse solutions are \[ A=\frac1\Delta\log_e\As \] and \[ B=\left(\As-I\right)^{-1}A\Bs \]

We will use the obvious approximation for matrix exponent where $e^x=I+x+x^2/2!+x^3/3!...$. Alternatively a Pad\'e approximation might be considered. But any matrix exponent approximations need to keep the matrix norm small to avoid calculation errors (See Moler and Van Loan 2003).

For this the approximation is $e^x=I+x$ so the digital system becomes very simple

Since $\As=\begin{bmatrix}e^{-\Delta P_1} & 0 \cr 0 & e^{-\Delta P_2}\end{bmatrix}$ and $\Bs=\Delta K \begin{bmatrix}e^{-P_1 K}\cr e^{-P_2 K}\end{bmatrix}$

Solutions to continuous time state space equations

Given the linear state space equations in the form \begin{eqnarray*} \dot{\bf x}&=&{\bf Ax + Bu}\\ {\bf y}&=&{\bf Cx + Du}\\ \end{eqnarray*}

The continuous solution can be written in the Laplace domain as $$Y=C(sI-A)^{-1}\left(Bu+x(0)\right)$$ which in the time domain becomes $$x(t)=\Phi(t)x(0) + \int_0^t\Phi(t-\tau)Bu(\tau)d\tau$$ for time invariance $$\Phi(t)=e^{At}$$ so the response to an arbitrary input can be calculated.

Changing the states

Let $\J$ be any square invertable matrix. We can use J to change the states around (scaling, mixing and swapping). let $x=\J x'$ so $ \J\dot{x}'=A\J x'+Bu$, $y=C\J x'$. The equivalent state space equation is then $\dot{x}=\J^{-1}AJ x + J^{-1}Bu$, $y=C\J x$.

Now if we know the Eigenvectors and values ($D$,diag($\lambda_n$) and $V$) for $A$ we can use J=V (provided V is invertable and A is diagonisable) to transform the system into $\dot{x}=diag(\lambda_i)x+V^{-1}u$, $y=CV x$.

Eigenvalues and vectors

Recall that Eigenvalues and Eigenvectors for any matrix $A$ are those vectors for which the equation $\lambda v=Av$ is true. This can be written in matrix form as $AV=VD$ e.g. for a 2x2 matrix this would be $A\begin{bmatrix}v_1 & v_2\end{bmatrix}=[\begin{bmatrix}v_1& v_2\end{bmatrix} \begin{bmatrix}\lambda_1 & 0 \cr 0 & \lambda_2\end{bmatrix} $

From which it is obvious that the poles are $\begin{bmatrix}e^{-p_1\Delta} & 0 \cr 0 & e^{-p_2\Delta}\end{bmatrix} $

General solution

given state space solution \[ \dot{x}=A(t)x(t)+B(t)u(t) \] The general solution is of the form \[ x=\Phi(t,t_0)x(t_0)+\int_{t_0}^t\Phi(t,t')B(t')u(t')dt' \]

Which simplifies for LTI systems to (see eq~\ref{eq:ss1}) \[ x=e^{A(t-t_0)}x(t_0)+\int_{t_0}^te^{A(t-t')}B(t')u(t')dt' \]

Computing matrix exponentials is a bit tricky but if we assume that the system has independent Eigenvalues we can use the relationship \[ S^{-1}AS=D \] where S is a matrix of Eigenvectors, and D is diagonal. The matrix exponent of a diagonal matrix is then just the exponent of the diagonal members.

So the impulse response of a system is then \[ x(t)=Se^{At}S^{-1}B \] provided it has non repeated Eigenvectors (a biproduct is that this enables $S^{-1}$ to be computed) and the initial conditions are all zero.

Concatenation of systems

Given two state space systems in series it is relatively easy to show that the state space of the combined system is

\begin{equation} \begin{bmatrix}\dot x_2\cr \dot x_1\end{bmatrix}= \begin{bmatrix}A_2 & B_2 C_1 \cr 0 & A_1\end{bmatrix} \begin{bmatrix} x_2\cr x_1\end{bmatrix} + \begin{bmatrix}0 \cr B_1\end{bmatrix} u_1 \end{equation}

\begin{equation} y_2= \begin{bmatrix} C_2 & 0 \end{bmatrix} \begin{bmatrix} x_2\cr x_1\end{bmatrix} \end{equation}

Other techniques

Still to come - perhaps, controlability, observability, state feedback controllers. Non-linear state space. Awesome picture of controlability structure (Statespace Notes 24 Oct 2017)


A mass spring damper system

Two forms are discussed, the first is typified by a piano string in that a force (e.g. from a hammer, drumstick, bow, finger ) is used to impart a force (often impulse like) to the system. This is shown in figure \ref{fig:piano}, but note that the force shown is the force the system imparts on the world! In this category are highly oscillatory systems such as any musical instrument that can be hit, plucked, tooted or bowed; as well as damped systems such as thermal heat dissipation.

\begin{figure}[h] \centering \includegraphics[height=40mm]{piano} \caption{mass-spring-damper (Piano string)} \label{fig:piano} \end{figure}

The second is the shock absorber where a displacement at one end of the system (ie the road) results in displacement at the other (ie the driver and passengers), and is shown in figure \ref{fig:shock}.

State space of a 2nd order system

For the piano string model, the upward forces on mass $m$ are $-K_{spring} x_a -B_{damp} \dot x_a + f$ so from Newton we get $$ -K_{spring} x_a -B_{damp} \dot x_a + f = m\ddot{x} $$ This we can put into CCF by writing $\dot x_2 =\ddot x_a $ ie $x_2=\dot x_a $ thus emphasising the vector nature of $\vec{x}$ \begin{eqnarray*} \begin{bmatrix}\dot x_1 \cr\dot x_2 \end{bmatrix} & = & \begin{bmatrix}0 & 1\cr-{K_{spring}\over m} & -{B_{damp}\over m}\end{bmatrix} \begin{bmatrix}x_1\cr x_2\end{bmatrix}+ \begin{bmatrix}0 \cr {1\over m}\end{bmatrix}f \\ y &=& [1 \ 0] \begin{bmatrix}\dot x_1 \cr\dot x_2 \end{bmatrix} \\ \end{eqnarray*} or by substituting $$\omega=\sqrt{{K_{spring}\over m}}$$ $$\varsigma={B_{damp}\over{2m\omega}}$$ we can see it is equivalent to \ref{eq:sosswz}

\begin{figure}[h] \centering \includegraphics[height=40mm]{shock} \caption{mass-spring-damper (Shock absorber)} \label{fig:shock} \end{figure}

\begin{eqnarray*} \dot{\bf x}&=& \left[ \begin{array}{cc} 0 & 1\\ -\omega^2_n & -2\varsigma \omega_n \end{array} \right]{\bf x} + \left[ \begin{array}{c} 0\\ \omega^2_n \end{array} \right]u\end{eqnarray*}

For the shock absorber model, the upward forces on mass $m$ are $K_{spring}(x_b-x_a)+B_{damp} (\dot x_b - \dot{x_a})$ so from Newton we get $$ K_{spring}(x_b- x_a) +B_{damp}(\dot x_b - \dot x_a) = m\ddot{x} $$

Hence the state space equations are \begin{eqnarray*} \begin{bmatrix}\dot x_1 \cr\dot x_2 \end{bmatrix} & = & \begin{bmatrix}0 & 1\cr-{K_{spring}\over m} & -{B_{damp}\over m}\end{bmatrix} \begin{bmatrix}x_1\cr x_2\end{bmatrix}+ \begin{bmatrix}0 \cr {B_{damp}\over m}\end{bmatrix}f \\ y &=& \begin{bmatrix}1 & K_{spring}/B_{damp}\end{bmatrix} \begin{bmatrix}\dot x_1 \cr\dot x_2 \end{bmatrix} \\ \end{eqnarray*}

state space of a 2nd order system (B)

\begin{eqnarray*} \small \dot{\bf x}&=& \left[ \begin{array}{cc} 0 & 1\\ -\omega^2_n & -2\varsigma \omega_n \end{array} \right]{\bf x} + \left[ \begin{array}{c} 0\\ \omega^2_n \end{array} \right]u\\ y &=& [1 \ 0]{\bf x} + [0] u\\ \end{eqnarray*}

$$\omega=\sqrt{{K\over M}}$$ $$\varsigma=\sqrt{{B^2\over 4KM}}$$

{\bf NTS:} Specify this as a sampled system $$\Phi=e^{A\triangle}$$

The Harris and Wolpert Human model 1998

The transfer function used by Harris and Wolpert is probably of the form $1/s(Js+b)(sT_1+1)(sT_2+1)$ In state space this would be

Putting the control canonical form into state space with a two term expansion gives.

\begin{equation} A=\begin{bmatrix}1 & \Delta & 0& 0 \\ 0& 1& \Delta& 0\\ 0& 0& 1& \Delta\\ 0 &-{{\Delta b} \over{T_1 T_2 J}} & {-\Delta \over {T_1 T_2}} \left({1+{b(T_1+T_2)} \over J} \right)& -\Delta( {1+ {{T_1+T_2}\over {T_1 T_2}}} + {b \over J}) \end{bmatrix} \end{equation}

\begin{equation} B=\begin{bmatrix} 0 \\ 0 \\ 0 \\ \Delta + {(1+ {{T_1+T_2}\over {T_1 T_2}} + {b \over J} )} \Delta^2 \end{bmatrix} \end{equation}

H and W give the following values for the arm $J=.25 Kgm^2$ $b= .2 Nms rad^{-1}$ $T1=0.04s$ $T_2=0.03s$

Fly fishing rod

As can be seen from Figure \ref{fig:fly_fishing} we can string mass spring damper systems together. We can form the state vector as $\vec{x}=\begin{bmatrix}x_1&\dots&x_n&\dot{x}_1&\dots&\dot{x}_n\end{bmatrix}^T$. The general equation then becomes $\ddot{x}_i=(k_ix_{i-1}+b_i\dot{x}_{i-1} -(k_i+k_{i+1})x_i -(b_i+b_{i+1})\dot{x}i +k{i+1}x_{i+1} + b_{i+1}\dot{x}_{i+1} )/m_i$ and so an example of a 4 node system would be

$$\tiny A=\begin{bmatrix} 0&0&0&0&1&0&0&0 \cr 0&0&0&0&0&1&0&0 \cr 0&0&0&0&0&0&1&0 \cr 0&0&0&0&0&0&0&1 \cr -(K{spring}_1+K{spring}_2)/m_1&K{spring}_2/m_1 & 0 & 0& -(B{damp}_1+B{damp}_2)/m_1 & B{damp}_2/m_1 & 0 & 0\cr K{spring}_2/m_2 & -(K{spring}_2+K{spring}_3)/m_2 & K{spring}_3/m_2 & 0& B{damp}_2/m_2 & -(B{damp}_2+B{damp}_3)/m_2 & B{damp}_3/m_2 & 0\cr 0 & K{spring}_3/m_3 & -(K{spring}_3+K{spring}_4)/m_3 & K{spring}_4/m_3 & 0 & B{damp}_3/m_3 & -(B{damp}_3+B{damp}_4)/m_3 & B{damp}_4/m_3 \cr 0 & 0 & K{spring}_4/m_4 & -K{spring}_4/m_4 & 0 & 0 & B{damp}_4/m_4 & -B{damp}_4/m_4 \cr \end{bmatrix} $$

\begin{figure}[h] \centering \includegraphics[height=40mm]{fly_fishing} \caption{mass-spring-damper: Fly fishing rod} \label{fig:fly_fishing} \end{figure}

While casting we can ignore gravity!

We can use Matlab or octave to generate graphics of frequency response, step response etc.

The end

Available on the Internet as URL= \url{}. Comments and corrections to W.S.~Harwin, (pick up the address or email from the web page). You are free to make as many copies as needed and use this material in any way you see fit as long as it is not illegal, immoral, or likely to endanger life or property. Notes are currently used in mechatronics and state space modules of the U.Reading Engineering degree.


K. Ogata "Modern Control Engineering" 9 {\it } Prentice-Hall , isbn 0-13-598731-8 pp. 712-719 (1990)

\noindent C.B. Moler and C. F. Van Loan "Nineteen dubious ways to compute the exponential of a matrix, Twenty-Five Years Later" {\it SIAM REVIEW} Society for Industrial and Applied Mathematics {\bf 45 } (1 ) pp. 3-000 (2003)

\noindent W. Harwin "notebook 196" {\it } pp. 198-199 (22 April 2004)

\noindent C. M. Harris and D. M. Wolpert "Signal-dependent noise determines motor planning" {\it Nature} pp. 780-784 (1998)

\vfill W.S.Harwin Digital Notebook \copyright{} October 2006 - \today