11.1: Simulation of the 1st and 2nd Order Systems in MATLAB/Simulink

Mechatronics: Fundamentals, Design, Integration, and Validation · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.1: Simulation of the 1st and 2nd Order Systems in MATLAB/Simulink
    Lab B.1 Objectives

    After completing this lab session, you will be able to:

    1. Simulate the 1st and 2nd order systems in MATLAB/Simulink.
    2. 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 executable code used for calculating the system step response by forming a first- and second-order transfer functions and calculating associated step responses.
    Figure B.7: Code for calculating the system step response.

    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.

    Exercise B1.1

    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.

    1. State the category of the second order system in terms of its damping ratio undamped, underdamped, critically damped, or overdamped).
    2. Use the command linearSystemAnalyzer(’step’,G) in the MATLAB command window. Obtain the step response diagram for each simulated system.
    3. 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\).

    Sample MATLAB code for Exercise B2.1 used to form the second-order system transfer function and obtain step response.
    Figure B.8: Sample code for Exercise B2.1

    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.

    A screenshot of MATLAB window showing the Simulink start-page.
    Figure B.9: Simulink start page.
    1. Single click on the iconimage11.png 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.
    A screenshot MATLAB window showing the Simulink library with list on the left and icons on the right.
    Figure B.10: Simulink library.
    1. 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.
    A Simulink block diagram showing a second-order transfer function with a step input and its output to a scope.Figure B.11: The first Simulink model.
    1. Double-click on the block Transfer Fcn to open the “Block Parameters” window. Configure the transfer function parameters shown in Figure B.12.
    A screenshot of transfer function "block parameters" window used to configure transfer function parameters.Figure B.12: Transfer function parameter configuration for the first Simulink model.
    1. 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.
    2. Single click the button image15.png to run the Simulink model. After the simulation completes, double-click the Scope block, and the chart in Figure B.13 will open.
    A MATLB plot showing the simulation result of a second-order system model with step input.
    Figure B.13: Simulation result of the first second-order model.
    Exercise B1.2

    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).

    MATLAB code used to form a second-order plant model and launch the PID turning GUI (graphic user interface).
    Figure B.14: An example of forming a plant model and launching the PID turning GUI.

    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 image18.png in the tool menu. The screen should be the same as Figure B.15.

    A screenshot of MATLAB pidTuner GUI window showing the tuned PID control gains and the associated step response.
    Figure B.15: An example of using MATLAB pidTuner.

    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.

    A Simulink block diagram showing a negative feedback system of second-order system with a PID controller used for gain tuning.
    Figure B.16: Simulink model for PID control tuning.

    Double-click on the ADD block and change its list of signs as shown in Figure B.17 to have correct parameters.

    A screenshot of Simulink parameter window of the "ADD" block.
    Figure B.17: Simulink “ADD” block parameter window.
    Exercise B1.3

    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.

    A Simulink block diagram for Exercise B1.13 showing a negative feedback system with a second-order plant and a PID controller.
    Figure B.18: Simulink model for Exercise B1.3.

    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) .