This repository demonstrates the design, simulation, and analysis of Proportional (P), Proportional-Integral (PI), and Proportional-Integral-Derivative (PID) controllers for a third-order continuous-time system.
The project combines an automated MATLAB script for calculating parameters via the classic Ziegler-Nichols (Z-N) closed-loop tuning method with a Simulink model to verify the transient and steady-state performance.
The plant model used in this project is a third-order transfer function defined as:
The MATLAB script dynamically determines the system's stability margins to extract the Ultimate Gain (
The controller gains are calculated using traditional Z-N closed-loop tuning rules:
| Controller Type | |||
|---|---|---|---|
| Proportional (P) | |||
| Proportional-Integral (PI) | |||
| Proportional-Derivative-Integral (PID) |
- MATLAB & Simulink
- Control System Toolbox
- Clone this repository and ensure all files are in the same working directory.
- Run the MATLAB script by typing
PIDcontrollerin the Command Window, or press Run (F5). This calculates the controller variables ($K_p, K_i, K_d$ ) and loads them into your workspace. - Open the Simulink model file:
simulinkmodel.slx. - Run the Simulink simulation to feed the workspace parameters into the parallel PID blocks.
- Double-click the Scope block in Simulink to view the live behavioral graph.
The script outputs the critical frequency-domain metrics derived from the plant's uncompensated open-loop response:
-
Ultimate Gain (
$K_u$ ): The gain margin threshold where the system becomes marginally stable. -
Oscillation Frequency (
$\omega_u$ ): The phase crossover frequency in rad/s.
The step response behavior of each controller configuration is visualized through the Simulink Scope block:
- Proportional Only (P): Fast response but suffers from a significant steady-state offset.
- Proportional-Integral (PI): Eliminates the steady-state error entirely, but introduces heavy oscillations and high overshoot.
- Proportional-Integral-Derivative (PID): Provides the optimal balance—eliminating steady-state error, dampening the system to reduce overshoot, and drastically improving settling time.
PIDcontroller.m- Main MATLAB script containing the plant definition, Z-N tuning mathematical formulas, closed-loop feedback loops, and plotting routines.simulinkmodel.slx- Simulink block diagram layout containing the step input, parallel PID controller configurations, plant transfer function, and routing to the multi-input Scope.Scope.png- Exported screenshot from the Simulink Scope block illustrating the performance comparison of the P, PI, and PID controllers.README.md- Documentation of the project.
This project is open-source and available under the MIT License.
