How to Model State Space System in Simulink: Step-by-Step Guide
To model a state space system in Simulink, use the
State-Space block found in the Simulink library under Continuous systems. Enter the system matrices A, B, C, and D in the block parameters to define the system dynamics and outputs.Syntax
The State-Space block requires four matrices to define the system:
- A: State matrix defining system dynamics.
- B: Input matrix defining how inputs affect states.
- C: Output matrix defining how states affect outputs.
- D: Feedthrough matrix defining direct input to output effect.
These matrices are entered as MATLAB arrays in the block's parameters.
matlab
A = [0 1; -2 -3]; B = [0; 1]; C = [1 0]; D = [0];
Example
This example shows how to model a simple second-order system using the State-Space block in Simulink. The system matrices represent a system with two states, one input, and one output.
matlab
% Define system matrices A = [0 1; -2 -3]; B = [0; 1]; C = [1 0]; D = [0]; % Open Simulink model open_system(new_system('StateSpaceExample')); % Add State-Space block add_block('simulink/Continuous/State-Space','StateSpaceExample/State-Space'); % Set block parameters set_param('StateSpaceExample/State-Space','A',mat2str(A),'B',mat2str(B),'C',mat2str(C),'D',mat2str(D)); % Add Step input add_block('simulink/Sources/Step','StateSpaceExample/Step'); % Add Scope add_block('simulink/Sinks/Scope','StateSpaceExample/Scope'); % Connect blocks add_line('StateSpaceExample','Step/1','State-Space/1'); add_line('StateSpaceExample','State-Space/1','Scope/1'); % Run simulation sim('StateSpaceExample');
Output
A Simulink model named 'StateSpaceExample' opens with a State-Space block connected to a Step input and a Scope showing the system output response.
Common Pitfalls
- Entering matrices with incorrect dimensions causes errors; ensure
Ais square andB,C,Dhave compatible sizes. - For discrete systems, set the sample time parameter; otherwise, the system defaults to continuous time.
- Not connecting inputs or outputs properly in the Simulink model leads to simulation errors or no output.
matlab
% Wrong: A is not square A_wrong = [0 1 2; -2 -3 4]; B_wrong = [0; 1]; % Correct: A is square A_correct = [0 1; -2 -3]; B_correct = [0; 1];
Quick Reference
| Parameter | Description | Notes |
|---|---|---|
| A | State matrix | Must be square (n x n) |
| B | Input matrix | Size (n x m), where m = number of inputs |
| C | Output matrix | Size (p x n), where p = number of outputs |
| D | Feedthrough matrix | Size (p x m), often zero matrix |
| Sample time | System sample time | 0 for continuous, >0 for discrete |
Key Takeaways
Use the State-Space block in Simulink to model systems by entering matrices A, B, C, and D.
Ensure matrix dimensions are correct to avoid simulation errors.
Set sample time properly for continuous or discrete systems.
Connect inputs and outputs correctly in your Simulink model.
Use Step and Scope blocks to test and visualize system response.