a comprehensive guide to state-space modeling and control of Multi-Input Multi-Output (MIMO) systems using MATLAB

Here’s a comprehensive guide to state-space modeling and control of Multi-Input Multi-Output (MIMO) systems using MATLAB, including code examples, controller design, and simulation:


1. State-Space Representation for MIMO Systems

A MIMO system with n statesm inputs, and p outputs is represented as:

{x˙=Ax+Buy=Cx+Du

  • A (n×n): State matrix
  • B (n×m): Input matrix
  • C (p×n): Output matrix
  • D (p×m): Feedforward matrix

2. Modeling MIMO Systems in MATLAB

Example System: 2-input, 2-output system with 3 states.

Define matrices:

matlab
Copy
A = [-1  0  2;
      0 -2  1;
      3  1 -3];
B = [1  0;
      0  2;
      1  1];
C = [1  0  0;
      0  1  0];
D = [0  0;
      0  0];

sys = ss(A, B, C, D); % Create state-space object

Convert Transfer Function to State-Space:

matlab
Copy
num = {[1 2], [0.5]; [3], [1 1]}; % Numerators for 2x2 system
den = {[1 3 2], [1 2]; [1 4], [1 5 6]};
G = tf(num, den);
sys_tf2ss = ss(G); % Convert TF to state-space

3. Control Design for MIMO Systems

a. Controllability & Observability

Check if the system is controllable and observable:

matlab
Copy
Co = ctrb(sys); % Controllability matrix
Ob = obsv(sys); % Observability matrix
rank_Co = rank(Co); % Should equal n (3)
rank_Ob = rank(Ob); % Should equal n (3)

b. Linear Quadratic Regulator (LQR)

Design an optimal state-feedback controller u=−Kx:

matlab
Copy
Q = diag([10, 10, 10]); % State weighting matrix
R = diag([1, 1]);       % Input weighting matrix
K = lqr(A, B, Q, R);    % Compute LQR gain

% Closed-loop system
A_cl = A - B*K;
sys_cl = ss(A_cl, B, C, D);

c. Pole Placement

Assign desired poles (e.g., at [-2, -3, -4]):

matlab
Copy
desired_poles = [-2, -3, -4];
K_place = place(A, B, desired_poles); % Requires controllability

4. Simulating Closed-Loop Responses

Step Response:

matlab
Copy
t = 0:0.01:10;
u = [ones(size(t)); ones(size(t))]; % Step input for both channels
[y_open, t_open, x_open] = lsim(sys, u, t);
[y_cl, t_cl, x_cl] = lsim(sys_cl, u, t);

% Plot results
figure;
subplot(2,1,1);
plot(t_open, y_open(:,1), 'r--', t_cl, y_cl(:,1), 'b');
title('Output 1: Open-Loop vs Closed-Loop');
legend('Open', 'Closed');

subplot(2,1,2);
plot(t_open, y_open(:,2), 'r--', t_cl, y_cl(:,2), 'b');
title('Output 2: Open-Loop vs Closed-Loop');

Output Comparison:

Step Response


5. Advanced Topics

a. Observers (State Estimation)

Design a Kalman filter or Luenberger observer:

matlab
Copy
L = place(A', C', [-5, -6, -7])'; % Observer gain

b. Robust Control (H-Infinity)

Use hinfsyn for robust MIMO controller synthesis:

matlab
Copy
P = augw(sys, W1, W2, W3); % Augmented plant
[K_robust, ~, gamma] = hinfsyn(P, ny, nu); % ny: # of measurements, nu: # of inputs

6. Example: Aircraft Pitch Control (2×2 MIMO)

States: Pitch angle, pitch rate, altitude
Inputs: Elevator deflection, thrust
Outputs: Pitch angle, altitude

matlab
Copy
% Define system matrices
A = [-0.5  0.2  0;
      0   -1.0  0;
      0.3  0.1 -0.2];
B = [0.1  0;
      0.5  0.2;
      0    0.1];
C = [1 0 0;
     0 0 1];
D = zeros(2,2);

% Design LQR controller
Q = diag([10, 10, 10]);
R = eye(2);
K = lqr(A, B, Q, R);

% Simulate
sys_cl = ss(A - B*K, B, C, D);
step(sys_cl);

7. Key MATLAB Functions

Function Purpose
ss(A,B,C,D) Create state-space model.
ctrbobsv Check controllability/observability.
lqrplace State-feedback control design.
lsimstep Simulate time responses.
hinfsyn Robust H-infinity control.

8. References

  1. MATLAB Documentation: State-Space Control Design.
  2. Skogestad, S. (2005). Multivariable Feedback Control: Analysis and Design.

Let me know if you need help with a specific MIMO system or debugging! 🚀