# How to model state space for complex valued system correctly in SIMULINK (MATLAB)?

When trying to use the default state-space model block, if there is a complex number valued in the matrices, there will be an error

To resolve that, firstly I need to look at pseudo reference model of state space on the internet

Then, create my own state-space block as a new subsystem

u is for input
y is for output
x is the state variable as an output (for sensing use, such as full state feedback)

And here is the inside

Now the problem is that,

1. The IC (Initial Condition) block cannot simulate what lsim can done in matlab code, there must be an exponential decay expected result for the unforced solution, but what I've got is that the initial condition only happened at the exact t=0 and there is no exponential decay.
How do I solve it?
2. The Integrator and IC block cannot operate with complex valued number, the input and must be separated manually into real and imaginary part or magnitude and phase part and then joined together again. Is there any better way to operate them with complex valued number in simulink?
3. The gain block of A, B, C, and D matrix look ugly, I haven't been able to change it in the shape of rectangle box as my reference model above. Is there any way to change it?

Finally, if there is any better solution for my problem, such as pre-builtin complex valued state-space model, or better subsystem, I would be happy to know it

• What do the modal_in blocks do? – fibonatic Nov 22 '18 at 19:13
• @fibonatic sorry for messy writing, it's stands for canonic_modal_initial. I forgot to rename it, it's a vector for initial codition x(0) for – Unknown123 Nov 22 '18 at 23:41
• doesn't the integrator block have initial conditions as well? – fibonatic Nov 22 '18 at 23:44
• I've also been thinking about that, but I'm confused whether it will be initial condition for input or for output of the integrator, xdot(0) or x(0). What we want obviously the x(0) – Unknown123 Nov 22 '18 at 23:47
• x(0), see documentation. – fibonatic Nov 22 '18 at 23:50

You can split up the real and imaginary part of the state into their own seperate states. Namely by defining $$x_r=\mathrm{Re}(x)$$, $$x_i=\mathrm{Im}(x)$$, $$A_r=\mathrm{Re}(A)$$, $$A_i=\mathrm{Im}(A)$$, $$u_r=\mathrm{Re}(u)$$, $$u_i=\mathrm{Im}(u)$$, $$B_r=\mathrm{Re}(B)$$ and $$B_i=\mathrm{Im}(B)$$ then the differential equation can also be written as

$$\dot{x}_r+i\,\dot{x}_i=(A_r+i\,A_i)(x_r+i\,x_i)+(B_r+i\,B_i)(u_r+i\,u_i)$$

which when split into their real and imaginary part gives

$$\begin{bmatrix} \dot{x}_r \\ \dot{x}_i \end{bmatrix}= \begin{bmatrix} A_r & -A_i \\ A_i & A_r \end{bmatrix} \begin{bmatrix} x_r \\ x_i \end{bmatrix}+ \begin{bmatrix} B_r & -B_i \\ B_i & B_r \end{bmatrix} \begin{bmatrix} u_r \\ u_i \end{bmatrix}.$$

The output can be expressed using

$$y=C\begin{bmatrix} I & i\,I \end{bmatrix} \begin{bmatrix} x_r \\ x_i \end{bmatrix} + D\begin{bmatrix} I & i\,I \end{bmatrix} \begin{bmatrix} u_r \\ u_i \end{bmatrix}.$$

• The u or input is located inside of Re and Im function. How do you separate it? – Unknown123 Dec 16 '18 at 19:22
• @Unknown123 I have updated my answer. – fibonatic Dec 16 '18 at 19:33