State Space Modeling (SSM) - P2prod/Filter-Modeling-Simulation GitHub Wiki

Introduction

A state space model (SSM) is a mathematical framework used to describe dynamic systems in terms of state variables. These models are particularly useful in fields such as control theory, I&C and engineering, where systems evolve over time. State space representation provides a comprehensive means of modelling the behaviour of complex systems by capturing their internal states and the relationships between them.

The fundamental components of a state-space model include state variables, input variables, output variables and parameters. State variables represent the internal state of the system at a given time, while input variables refer to the external influences affecting the system. The output variables are the measurable quantities resulting from the state of the system and the inputs. Parameters define the relationships and dynamics within the model, influencing how the state evolves over time. Of course, this approach allows several variables (inputs, outputs, state variables) to be processed simultaneously, which is the strength of this methodology.

The example given below illustrates this perfectly.

Mathematically, a state-space model is usually represented by a set of first-order differential or difference equations. The continuous-time representation is given by the following system of equations:

$$\displaystyle X'(t) = A.X(t) + B.U(t)$$ $$\displaystyle Y(t) = C.X(t) + D.U(t) $$

where $X(t)$ is the state vector, $U(t)$ is the input vector, $Y(t)$ is the output vector, and $A, B, C, D$ are matrices that define the dynamics of the system.

Besides, this system of equations can be represented in graphical form as follows: SSM standard block diagram Note: SimuLink offers this possibility from the outset, allowing you to work directly on a system according to its SSM diagram.

Example of a system described with differential equations

Let's take the serial RLC circuit as an example.

RLC series circuit

$\displaystyle R$ is the resistor of the circuit, $\displaystyle L$ is the self-inductance of the circuit and $\displaystyle C$ is the capacitor of the circuit.

$\displaystyle U$ is the input voltage of the system, $\displaystyle i(t)$ is the current flowing through the circuit, $\displaystyle v_c(t)$ is the voltage across the capacitor $\displaystyle C$ and also the output of the circuit, because we want to focus on the capacitor state.

Note: If we wanted to focus on the state of the inductor, the output of the system would have been the voltage at the terminals of the inductor, or why not its current. So the state matrices that follow would have been different.

Now, let's consider the state space variables :

  • The input of the system is the source voltage $U$,
  • The state variables of this circuit are : $i(t)$ and $v_c(t)$, beacuse these variables characterise the state of the system at each instant , considering we focuse on the capacitor (it is our choice). So, we can write:

$$\displaystyle X = \begin{bmatrix} i(t) \\ v_c(t) \end{bmatrix}$$

Therefore, we get:

$$\displaystyle X' = \begin{bmatrix} {di(t) \over dt} \\ {dv_v(t) \over dt} \end{bmatrix} $$

  • The parameters are $R$, $L$ and $C$,
  • The output is the voltage across the capacitor $v_c(t)$.

The differential equations governing this circuit are:

$\displaystyle (1) : U = R.i(t) + L{di(t) \over dt} + v_c(t)$

$\displaystyle (2) : v_c(t) = \int {\frac{i(t)}{C} }.dt$

From (1) we can write : $\displaystyle {di(t) \over dt} = -\frac{R}{L}.i(t) - \frac{v_c(t)}{L} + \frac{U}{L}$

From (2) we can write : $\displaystyle {dv_c(t) \over dt} = \frac{i(t)}{C}$

Then we get :

$$\displaystyle X' = \begin{bmatrix} -\frac{R}{L}.i(t) - \frac{v_c(t)}{L} + \frac{U}{L} \\ {i(t) \over C} \end{bmatrix}$$

By rearranging the equations of the matrix $X'$ as a function of $X$ and $U$, we obtain :

$$\displaystyle \boxed { X' = \begin{bmatrix} -\frac{R}{L} & - \frac{1}{L} \\ {1 \over C} & 0\end{bmatrix}\begin{bmatrix} i(t) \\ {v_c(t)} \end{bmatrix} + \begin{bmatrix} -\frac{1}{L} \\ {0} \end{bmatrix}[U]}$$

where

$$\displaystyle A = \begin{bmatrix} -\frac{R}{L} & - \frac{1}{L} \\ {1 \over C} & 0\end{bmatrix}$$
$$\displaystyle X = \begin{bmatrix} i(t) \\ {v_c(t)} \end{bmatrix}$$ $$\displaystyle B = \begin{bmatrix} -\frac{1}{L} \\ {0} \end{bmatrix}$$ $$\displaystyle u = [U]$$

Now let's consider ${\displaystyle Y}$:

we know that $\displaystyle Y(t) = C.X(t) + D.U(t)$. (Note that the matrix C is different from the capacitor C).

As we have $\displaystyle y(t) = v_c(t)$ , we can write that :

$$\displaystyle \boxed {Y = \begin{bmatrix} 0 & 1\ \end{bmatrix} \begin{bmatrix} i(t) \\ v_c(t) \end{bmatrix}}$$

regarding the state variables.

As a result, we have

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

and $$\displaystyle D = [0]$$

Summary


$$\displaystyle \boxed { A = \begin{bmatrix} -\frac{R}{L} & - \frac{1}{L} \\ {1 \over C} & 0\end{bmatrix} } $$

$$\displaystyle \boxed { B = \begin{bmatrix} -\frac{1}{L} \\ {0} \end{bmatrix} } $$

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

$$\displaystyle \boxed {D = [0]}$$


Remark: for a second order system, the dimension of the matricies are always:

$$\displaystyle A -> \begin{bmatrix} a_1 & a_2 \\ a_3 & a_4 \end{bmatrix}$$

$$\displaystyle B -> \begin{bmatrix} b_1 \\ b_2 \end{bmatrix}$$

$$\displaystyle C -> \begin{bmatrix} c_1 & c_2 \ \end{bmatrix}$$

$$\displaystyle D -> \begin{bmatrix} d_1 \ \end{bmatrix}$$

Example of a system described with a transfer function

Let's take the same serial RLC circuit as above. It can be depicted by the following diagram, where ${\displaystyle U(p)}$ is the input of the system and ${\displaystyle Y(p)}$ is the output of the system. The box represents the behavior of the system. It is the transfer function. This representation is universal and can be applied to any system.

image

$U(p)$ is the Laplace transform of $u(t)$, which is the supply voltage of the circuit.

$Y(p)$ is the Laplace transform of $v_c(t)$, which is the voltage across the capacitor.

Its tranfer function is the following one:

The transfer function of such a circuit is :

$\displaystyle {Y(p) \over U(p)}=\frac{1}{L.C.p^2.+R.C.p+1}=\frac{1}{(\tau.p)^2.+2.z.\tau.p+1}$ where :

  • $\tau$ is the time constant of the filter : $=\sqrt{L.C}$
  • $p$ is Laplace variable,
  • $z$ is the filter damping coefiicient $=\frac{1}{2}.R.\sqrt{{C \over L}}$

Let's develop the transfer function:

$\displaystyle (L.C.p^2.+R.C.p+1).Y(p)=U(p)$

$\displaystyle L.C.Y(p).p^2+R.C.Y(p).p+Y(p)=U(p)$

Inverse Laplace transform gives :

$\displaystyle (1) : L \cdot C \cdot y"(t) + R \cdot C \cdot y'(t) + y(t) = u(t)$

Now we have a second order differential equation. Let's transfom it into a first order differential equation system :

Let's do the following replacements :

  • $\displaystyle y(t)=x_1$
  • $\displaystyle y'(t)=x_2$
  • $\displaystyle u(t)=u$

By the way, we have got

$$\displaystyle X=\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}$$

then

$$\displaystyle X'=\begin{bmatrix} x'_1 \\ x'_2 \end{bmatrix} = \begin{bmatrix} ? \\ ? \end{bmatrix}$$

According to the previous changes in variables, we have : $x'_1=x_2$

In the same way,we can say that the differential equation (1) becomes : $\displaystyle L.C.x'_2+R.C.x_2+x_1=u$. From this équation, we can extract $\displaystyle x'_2 =-{1 \over L.C}x_1-{R \over L}x_2+{u \over L.C}$

That's it, we have $\displaystyle x'_1$ and $\displaystyle x'_2$.

Then :

$$\displaystyle X'= \begin{bmatrix} x'_1 \\ x'_2 \end{bmatrix}=\begin{bmatrix} x_2 \\ -{1 \over L.C}x_1-{R \over L}x_2+{u \over L.C} \end{bmatrix}=\begin{bmatrix} 0 & 1 \\ -{1 \over L.C} & -{R \over L} \end{bmatrix} \cdot \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + \begin{bmatrix} 0 \\ {1 \over L.C} \end{bmatrix} \cdot U$$

As we have $\displaystyle y(t)=x_1$, then :

$$\displaystyle Y=\begin{bmatrix} 1 & 0 \ \end{bmatrix}\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}$$

So we can express now the canonical matrices of the system :

$$\displaystyle A=\begin{bmatrix} 0 & 1 \\ -{1 \over L.C} & -{R \over L} \end{bmatrix}$$ $$\displaystyle B=\begin{bmatrix} 0 \\ {1 \over L.C} \end{bmatrix}$$ $$\displaystyle C=\begin{bmatrix} 1 & 0 \ \end{bmatrix}$$ $$\displaystyle D=[0]$$

Table of SSM equations

Below is a catalogue of the most common filters with their transfer function and the equations derived from the State Space Modelling approach in order to code them withn Modelica or other softwares: image