Speed control with PID in Simulink - Time & Space Complexity
We want to understand how the time to run a PID speed control system changes as the input size grows.
Specifically, how does the system's computation time grow when controlling speed with a PID controller?
Analyze the time complexity of the following Simulink PID control snippet.
// Simulink PID Speed Control Model
// 1. Read speed sensor input
// 2. Calculate error = desired speed - actual speed
// 3. PID block computes control signal
// 4. Apply control signal to motor
// 5. Loop repeats every time step
for each time step t {
error(t) = setpoint - speed(t);
control(t) = PID(error(t));
speed(t+1) = motor(control(t));
}
This code controls motor speed by repeatedly calculating error and adjusting control signals using a PID controller at each time step.
Look at what repeats as the system runs:
- Primary operation: The PID calculation and motor update happen once every time step.
- How many times: This repeats for each time step in the simulation or control period.
As the number of time steps increases, the total operations increase linearly.
| Input Size (n = time steps) | Approx. Operations |
|---|---|
| 10 | 10 PID calculations and motor updates |
| 100 | 100 PID calculations and motor updates |
| 1000 | 1000 PID calculations and motor updates |
Pattern observation: Doubling the time steps doubles the work because each step does a fixed amount of work.
Time Complexity: O(n)
This means the total time grows directly in proportion to the number of time steps.
[X] Wrong: "The PID calculation time grows faster than the number of time steps because it does complex math."
[OK] Correct: Each PID calculation is a fixed set of operations done once per step, so total time grows linearly with steps, not faster.
Understanding how control loops scale helps you explain system performance clearly and shows you can think about real-time system costs.
"What if the PID controller included nested loops for adaptive tuning at each step? How would the time complexity change?"