How can I implement a PID controller in MATLAB and Simulink?

T
tyresp · Jul 16, 2025 · 330 views
Question
How can I implement a PID controller in MATLAB and Simulink?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 20, 2026

To implement a PID controller in MATLAB:

Using MATLAB Code:

  1. Define your system transfer function:

    s = tf('s'); G = 1 / (s + 2); % Example plant
  2. Create the PID controller:

     
    Kp = 2; Ki = 1; Kd = 0.5; C = pid(Kp, Ki, Kd);
  3. Connect controller and plant:

    T = feedback(C * G, 1); % Closed-loop system
  4. Plot step response:

    step(T); title('Step Response with PID Controller');

Using Simulink:

  1. Open Simulink → New Model

  2. Add blocks: Step InputPID ControllerTransfer FunctionScope

  3. Set parameters in PID block (Kp, Ki, Kd)

  4. Run the simulation and observe results in the Scope

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!