This is a great question about converting transfer functions to state space form. I'll provide a comprehensive explanation with multiple examples and methods.
The general approach involves:
Understanding the relationship between transfer functions and state space
Different canonical forms (controllable, observable, diagonal, etc.)
Working through concrete examples
Let me create a detailed response with clear examples.
Transfer Function to State Space Conversion
General Principles
State Space Form:
code
ẋ(t) = Ax(t) + Bu(t)
y(t) = Cx(t) + Du(t)
Transfer Function to State Space: Multiple valid representations exist (different A, B, C, D matrices).
Method 1: Controllable Canonical Form (Direct)
Example 1: First-Order System
Transfer Function:G(s)=s+32
State Space:
Define: x(t)=y(t)
From x˙+3x=2u:
A=[−3],B=[2],C=[1],D=
Example 2: Second-Order System
Transfer Function:G(s)=s2+4s+35s+2
Step 1: Rearrange the differential equation
y¨+4y˙+3y=5
Step 2: Define state variables
x1=y
x2=
Step 3: Write state equations
\dot{x}_1 &= x_2\\
\dot{x}_2 &= -3x_1 - 4x_2 + 5\dot{u} + 2u
\end{align}$$
**Problem:** Has $\dot{u}$ term. Use **feedthrough** or redefine states.
**Better approach (with D matrix):**
$$\dot{x}_2 = -3x_1 - 4x_2 + 5u'$$
where $u' = \dot{u}$, leaving:
$$A = \begin{bmatrix} 0 & 1 \\ -3 & -4 \end{bmatrix}, \quad B = \begin{bmatrix} 0 \\ 5 \end{bmatrix}, \quad C = \begin{bmatrix} 1 & 0 \end{bmatrix}, \quad D = [2]$$
---
## Method 2: Observable Canonical Form
Same system, different representation focused on observability.
**For:** $G(s) = \frac{b_1 s + b_0}{s^2 + a_1 s + a_0}$
$$A = \begin{bmatrix} 0 & 1 \\ -a_0 & -a_1 \end{bmatrix}, \quad B = \begin{bmatrix} b_0 \\ b_1 \end{bmatrix}, \quad C = \begin{bmatrix} 1 & 0 \end{bmatrix}, \quad D = [0]$$
**Example:** $G(s) = \frac{5s + 2}{s^2 + 4s + 3}$ (assuming no feedthrough)
$$A = \begin{bmatrix} 0 & 1 \\ -3 & -4 \end{bmatrix}, \quad B = \begin{bmatrix} 2 \\ 5 \end{bmatrix}, \quad C = \begin{bmatrix} 1 & 0 \end{bmatrix}, \quad D = [0]$$
---
## Method 3: Diagonal Form (Partial Fractions)
**Transfer Function:**
$$G(s) = \frac{5s + 2}{(s+1)(s+3)}$$
**Partial Fractions:**
$$G(s) = \frac{r_1}{s+1} + \frac{r_2}{s+3}$$
Using residue method: $r_1 = -1.5, \quad r_2 = 6.5$
**State Space (Diagonal):**
$$A = \begin{bmatrix} -1 & 0 \\ 0 & -3 \end{bmatrix}, \quad B = \begin{bmatrix} 1 \\ 1 \end{bmatrix}, \quad C = \begin{bmatrix} -1.5 & 6.5 \end{bmatrix}, \quad D = [0]$$
---
## Systematic Procedure: Controllable Canonical Form
**For:** $G(s) = \frac{b_n s^n + ... + b_1 s + b_0}{s^{n+m} + a_{n+m-1}s^{n+m-1} + ... + a_1 s + a_0}$
### General n-th Order System
**State equations:**
$$\dot{\mathbf{x}} = \begin{bmatrix} 0 & 1 & 0 & \cdots & 0 \\ 0 & 0 & 1 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 1 \\ -a_0 & -a_1 & -a_2 & \cdots & -a_{n-1} \end{bmatrix} \mathbf{x} + \begin{bmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{bmatrix} u$$
$$y = \begin{bmatrix} b_0 & b_1 & \cdots & b_{n-1} & b_n \end{bmatrix} \mathbf{x} + [d] u$$
---
## Example 3: Third-Order System
**Transfer Function:**
$$G(s) = \frac{2s^2 + 3s + 1}{s^3 + 6s^2 + 11s + 6}$$
**Coefficients (numerator):** $b_2=2, b_1=3, b_0=1$
**Coefficients (denominator):** $a_2=6, a_1=11, a_0=6$
**State Space:**
$$A = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ -6 & -11 & -6 \end{bmatrix}$$
$$B = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$$
$$C = \begin{bmatrix} 1 & 3 & 2 \end{bmatrix}$$
$$D = [0]$$
**Verification:** $(sI - A)^{-1}B \Rightarrow G(s)$ ✓
---
## MATLAB Implementation
```matlab
% Method 1: Direct conversion using tf2ss
num = [2 3 1]; % Numerator coefficients
den = [1 6 11 6]; % Denominator coefficients
[A, B, C, D] = tf2ss(num, den);
% Method 2: Using Control System Toolbox
sys_tf = tf(num, den);
sys_ss = ss(sys_tf);
A = sys_ss.A;
B = sys_ss.B;
C = sys_ss.C;
D = sys_ss.D;
% Verify conversion back to TF
sys_tf_check = tf(sys_ss);
% Method 3: Define state space directly
A = [0 1 0; 0 0 1; -6 -11 -6];
B = [0; 0; 1];
C = [1 3 2];
D = 0;
sys_ss_manual = ss(A, B, C, D);
```
---
## Verification Check
**Inverse Laplace Transform:**
$$G(s) = C(sI-A)^{-1}B + D$$
For your system, compute $(sI-A)^{-1}$ and verify it matches the original transfer function.
---
## Quick Reference Table
| Aspect | Controllable Form | Observable Form | Diagonal Form |
|--------|-------------------|-----------------|---------------|
| **Best for** | Control design | State estimation | Analysis |
| **A structure** | Companion matrix | Companion matrix | Diagonal |
| **Computation** | Simple | Simple | Via partial fractions |
| **Numerical** | Can be ill-conditioned | Better conditioned | Best |
Would you like me to work through a specific transfer function, or explain any particular canonical form in more detail?