Opening the book…
After completing this lab session, you will be able to:
- Simulate the 1st and 2nd order systems in MATLAB/Simulink.
- Tune the PID controller gains in MATLAB/Simulink.
Simulation of the 1st and 2nd Order Systems Using Matlab
We can use MATLAB to simulate a dynamic system directly utilizing MATLAB commands. This section describes the step-by-step process of simulating a given transfer function in MATLAB including the first and second order systems.
Responses of the 1st and 2nd order LTI systems. We can calculate the system step time response using the MATLAB commands in Figure B.7 in the form of a MATLAB executable “*.m” file.
MATLAB response analyzer. MATLAB provides a powerful graphical user interface (GUI) for analyzing LTI (linear time-invariant) systems that can be accessed using the syntax linearSystemAnalyzer(’step’,G). In the shown syntax, G is the given system plant model, and step specifies the excitation type. If you right-click on the step response graph and select Characteristics, you can choose to have several system measures overlaid on the response, including peak response, settling time, rise time, and steady-state. See Chapter 3 for their definitions.
Refer to the following second order systems in its standard form, introduced in Section 3.3.
\[G(s)=\dfrac{{K\omega }^2_n}{s^2+2\zeta {\omega }_ns+{\omega }^2_n} \label{B.1}\]
where \(K\) is the system DC gain, \({\omega }_n\) is the undamped natural frequency, and \(\zeta\) is the damping ratio. Simulate the second order system for \({\omega }_n=15\) and \(\zeta =0,\ 0.2,\ 1.0,\ \) and \(1.2\) separately. Then complete the following step list.
- State the category of the second order system in terms of its damping ratio undamped, underdamped, critically damped, or overdamped).
- Use the command linearSystemAnalyzer(’step’,G) in the MATLAB command window. Obtain the step response diagram for each simulated system.
- Then complete the chart below for the settling time, rise time, and overshoot for \(\zeta \mathrm{=0.2}\). Show both code and results.
| Damping ratio | Setting Time | Rise Time | Overshoot |
|---|---|---|---|
| 0.2 |
Hint: An example of code is shown below for \({\omega }_n=10\) and \(\zeta =0.2\).
Simulation with Simulink
To start Simulink, single click on the icon in the command window’s tool menu. You may also bring up this window by typing simulink in the command window. The Simulink start page will pop up (see Figure B.9). You may choose a Blank Model for your first trial, using the following steps.
- Single click on the icon
to show the Simulink library browser (see Figure B.10). You will see a collection of different block sets used to build a Simulink model.
- Build the first model of a second order system as shown in Figure B.11 by selecting Step from “Source,” Scope from “Sink,” and Transfer Fcn from “Continuous” in the library browser.
Figure B.11: The first Simulink model.- Double-click on the block Transfer Fcn to open the “Block Parameters” window. Configure the transfer function parameters shown in Figure B.12.
Figure B.12: Transfer function parameter configuration for the first Simulink model.- Connect these three blocks with the corresponding lines by dragging a line from its input port and dropping it (release the mouse button) to complete the Simulink model shown in Figure B.11.
- Single click the button
to run the Simulink model. After the simulation completes, double-click the Scope block, and the chart in Figure B.13 will open.
Use \(ω_n\mathrm{=15}\) and \(ζ\mathrm{=0.2}\) for the second order system defined in equation (B.1). Simulate the system step response. Show the code, model and results.
PID Controller Tuning
A PID (proportional-integral-derivative) controller can be tuned by either a MATLAB command or a Simulink block. The PID controller can be defined by its time-domain differential equation and Laplace transform in equations \ref{B.2} and \ref{B.3}.
\[u(t)=K_pe(t)+K_i\int^t_0{e\left(τ\right)dτ}+K_d\dfrac{de(t)}{dt} \label{B.2}\]
\[C\left(s\right)=K_p+\dfrac{K_i}{s}+K_ds \label{B.3}\]
where \(e(t)\) is the error input; \(u(t)\) is the PID control output; and \(K_p\), \(K_i\), and \(K_d\) are proportional, integral, and derivative gains of the PID controller, respectively. In addition, \(C\left(s\right)\) is the PID controller’s transfer function.
MATLAB PID tuning. MATLAB provides a tool for automatically optimizing (tuning) PID control gains to reduce the trial-and-error effort. You can access the tuning algorithm through a nice graphical user interface (GUI) using the command pidTuner. Let’s explore this automated tuning tool to generate a proportional controller by entering the command pidTuner(P,’PID’) in the Command window. In the shown syntax, P is the given system plant model, and PID specifies that the tuner employ a proportional-integral-derivative controller. The plant model can be generated using the following commands in the MATLAB command window or using the following code file (see Figure B.14).
We can now interactively tune the controller parameters on the tuning GUI; see the resulting response in the GUI window shown in Figure B.15. Single click on the icon Show Parameters
in the tool menu. The screen should be the same as Figure B.15.
Simulink PID Tuning. Based upon the Simulink model shown in Figure B.11, add the block PID Controller from the “Continuous” group and the block ADD from the “Math Operations” group in the Simulink Library browser. These will help you obtain the Simulink model shown in Figure B.16 to form a feedback control system.
Double-click on the ADD block and change its list of signs as shown in Figure B.17 to have correct parameters.
Use the pidTuner application to achieve PI control-gain tuning for the system defined in Figure B.16. Find \(K_P\) and \(K_i\) values for the closed-loop system with closed-loop system rise time close to \(0.1\) second. Then tune the PID control gains in the Simulink model for the system defined in Figure B.18. Using the five-step tuning process introduced in Section 3.4 to show the responses when you tuned \(K_p\), \(K_i\), and \(K_d\) in Steps 2 through 4 of the tuning process and the corresponding PID control parameters. Show the code/model and results.
This page titled 11.1: Simulation of the 1st and 2nd Order Systems in MATLAB/Simulink was last modified on Mon, 24 Aug 2026 21:38:58 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Guoming Zhu (Co-DREAM OER) .
The book could not be loaded just now.