This document discusses using MATLAB and Simulink to model, analyze, and simulate dynamic systems and control techniques. It begins by explaining how to use MATLAB to obtain transfer functions from mathematical models and analyze stability. Next, it describes using Simulink to build models with blocks and implement PID controllers. Finally, it provides examples of simulating an open-loop and closed-loop spring-mass-damper system in MATLAB and Simulink to analyze the system response.
Modeling and Simulation of Dynamic Systems Using MATLAB and SIMULINK
1. MODELING, ANALYSIS AND
SIMULATION OF DYNAMIC
SYSTEMS USINGCONTROL
TECHNIQUES IN MATLAB AND
RESPONSES OF A PID
CONTROLLER IN SIMULINK.
2. 1
Table of Contents:
1. Abstract…………………………………………………………………………………3
2. Introduction……………………………………………………………………………..4
3. MATLAB for control systems………………………………………………………….5
3.1. Mathematical model and transfer function………………………………………...5
3.2. Performance analysis of the S-M-D control system…………………….................6
3.3. Stability of a control system in MATLAB…………………………...…………....7
3.4. Most common techniques in control using MATLAB………………………….....8
4. SIMULINK for control systems………………………………………………………..9
4.1. Building a simple system using Simulink…………………………………………9
4.2. PID controller using Simulink……………………………………………………..9
5. Simulations……………………………………………………………………………..11
5.1 Using MATLAB…………………………………………………………………....11
5.2 Using SIMULINK.............................................................................................…....15
6. Conclusions……………………………………………………………………………..17
7. References………………………………………………………………………………18
3. 2
ABSTRACT
Our project on “Modeling, analysis and simulation of dynamic systems using control techniques
in MATLAB and responses of a PID controller in SIMULINK” gives an insight on the diverse
usage of MATLAB and its functions. Starting with the importance of MATLAB, we will cover
the basic concepts required to understand its usage. Further we will understand how to
implement mathematical model of a control system along with its transfer function. All this
application of transfer function will be made clear through a sample S-M-D (Spring Mass
Damper) system. We will realize that this system is a second-order system by determining the
order of its characteristic equation. Further it will be shown how MATLAB helps in determining
the stability of a system using Root-locus and Bode plot method. These two techniques are
already mentioned in the Mechatronics subject, here we will do there analysis and will be able to
understand there actual application with a real world example. Later in this report we will know
about SIMULINK and PID (Proportional, Integral and Differential) controllers. These controllers
will be implemented in SIMULINK from which we will get to know how PID is an important
tool for determining the response (open and closed loop) of a system. In this case also our system
would be the previously mentioned S-M-D system. All this will result in understanding the open
and closed loop response through the plot formed by SIMULINK.
We would like to inform that this report just gives the overview and theoretical aspects to our
research project till where we have completed. The reader won’t be able to see any modelling
and simulation results as the project is being carried out. We have tried to give a brief idea of our
approach and the things which will be done in this project. The final modelling, simulation and
results will be presented in the final review later in this semester.
4. 3
INTRODUCTION
MATLAB is a multi-paradigm programming language and numerical computing environment,
which has been developed through the years for scientific and engineering calculations.
MATLAB provides matrix manipulation, plotting of any function as well as data, implementing
algorithms and interfacing with programs written in other languages. It combines mathematical
computing and visualization along with powerful language providing an efficient and flexible
environment for technical computing. It has various built-in functions which can be used to solve
specific problems. It is also possible to create and add any function to suit any scientific or
engineering application. Since MATLAB is a programming tool in nature, it is possible to
interact with other programming languages such as C++ by an external interface to run those
programs within MATLAB. It provides the flexibility to accept data to be analyzed and produce
the necessary output. MATLAB has several toolboxes to support different applications. Apart
from MATLAB, Simulink is an interactive tool for modeling, simulating, and analyzing dynamic
systems. It enables engineers to create graphical block diagrams, evaluate system performance,
and analyze multi-domain dynamical systems. Simulink integrates effortlessly with MATLAB
and tightly integrates with the Stateflow for modeling event-driven behavior.
Simulink is the perfect tool for control systems, Digital Signal Processing and communication
system related design and other simulations. Analyzing and simulating the behavior of a system
is important to be able to understand its dynamics and therefore be able to design an appropriate
controller to attain the desired response. Some control design techniques will be presented to
show how to design a controller and implement them in both MATLAB and SIMULINK.
5. 4
MATLAB FOR CONTROL SYSTEMS
MATLAB provides a toolbox that can assist drastically in design and analysis of control systems
based on the mathematical models of physical systems. On obtaining the mathematical model of
system, the transfer function of this system can be determined easily.
Mathematical model and transfer function
We will consider a typical spring- mass-damper system for analysis with the assistance of
MATLAB. Mathematical equation expressing the motion of the mass in system is:
M x (t) + fv x(t) + kx(t) = f (t) (1)
Where, M is the mass, x·t is the linear acceleration of the mass, fv is the coefficient of viscous
friction, x·t is the linear velocity, k is the spring constant, x t is the displacement and f t the
applied force. Assuming all initial conditions are zeros and taking the Laplace transform of
Equation (1) yields:
Ms2 Xx(s) + fvs X (s) + ks X (s) = F (s) (2)
Transfer function of the system is given as:
G(s) = X (s)/F (s) =1/ (Ms2 + f s + k) (3)
Once we get the transfer function, the analysis of the system can be carried out in MATLAB.
First step is to assign values to the parameters M, fv and k then the transfer function can be
entered as polynomial of the numerator and denominator and hence the transfer function can be
produced as follows:
6. 5
>; M = 1, fv = 2, k = 2;
>> num = [1];den = [M fv k];
>> TF = tf (num,den)
Transfer function:
1/ (S2 + 2 s + 2)
The poles and zeros of the system will be:
>> p = pole (TF); z = zero (TF)
p = -1.0000 + 1.0000i
-1.0000 +1.0000i
z = Empty matrix: 0 by 1
It can be seen that the z is an empty matrix because the system only has two poles but no zeros.
The output response of the system for a step input is determined and plotted using the following
lines:
>> step (TF)
>> xlabel ('Time (sec)')
>> ylabel ('The output x(t) (m)')
>> title ('The step response of S-M-D
system')
The output response can be obtained for different values of any of the parameters.
Performance analysis of the S-M-D control system
Feedback systems are the most successful control systems which can be found in many
applications everywhere. This success is due to the following reasons:
They reject the effect of the disturbance in the system.
They reduce and in some cases eliminate the steady-state errors.
They allow the adjustment of the transient response of the system.
They decrease the sensitivity of the system to the variation in the process parameters.
7. 6
We will consider the transfer function of the S-M-D system obtained above to study and analyze
the performance along with the characteristics of the system. The transfer function is rewritten in
terms of the characteristic equation of a second order system as:
The characteristic parameters of the second-order system such as the steady-state error, ess,
maximum overshoot, pos, the rise time, Tr, the peak time, Tp, the settling time, Ts, and the
damping ratio, can be attained by executing a MATLAB function stored in MATLAB file called
gsos.m. On executing gsos.m, the user have to enter the system polynomial (i.e. the numerator
and denominator of the system), then it will produce the values of all the mentioned parameters
along with a plot of the output response.
Stability of a control system in MATLAB
Stability is a fundamental very important in control engineering. An unstable system is neither
useful nor practical when a precise response is needed. A stable system is a system which
produces a bounded output for every bounded input. Furthermore, all poles of the transfer
function of a stable system must have a negative real part (i.e. all poles must lay on the left half
of the plane). Routh-Hurwitz method is one of the most simple and easy tests to determine the
stability of a system. The method is based on analyzing the characteristic equation to determine
the stability of the system as well as number of poles in the unstable region (i.e. the right-half
plane). MATLAB has the ability to assist the user by providing a simple and accurate method to
determine the stability as well as the range of the gain that makes the system stable.
8. 7
Most common techniques in control using MATLAB
Now we will explore some common techniques to study and analyze the relative stability of
control systems. These techniques are Root Locus and Bode Diagram. The root locus is a method
that provides a graphical representation of the closed-loop poles as one parameter is varied.
Secondly, Bode diagram is a graphical method based on the frequency response of the system.
Bode diagram consists of two graphs out of which one is for the magnitude and the other is for
the phase angle of the system. The system is tested by a sinusoidal input signal where the
frequency varies. MATLAB has the ability to provide the graphical output of both methods by
entering simple commands. Considering a simple second order system which is represented by a
transfer function of:
The root locus and the Bode diagram of the system can be obtained from MATLAB.
>> num = [1 2];
>> den = [1 3 6];
>> TF = tf(num,den)
>> rlocus (TF), grid, figure;
>> bode (TF)
>> grid
By clicking on the root locus graph thus produced, we will be able to determine the gain of the
system, position of the poles, damping ratio, percentage overshoot and frequency of the system.
In the Bode diagram, we will be able to determine the gain margin and phase margin of the
system as well as the gain and phase crossover frequencies.
9. 8
SIMULINK FOR CONTROL SYSTEMS
Simulink is a dynamic system which is used as a complement with MATLAB environment to
simulate systems using the built-in blocks rather than writing codes. It is extremely user-friendly
due to the block-driven interface and has the ability to interact with the MATLAB workspace.
We can open a new file in SIMULINK to construct our system and then chose the right block
from any of the toolbox's library along with the Simulink Extra library to build the required
model for application. Once the model is constructed, we have to enter the parameters for each
block. We will be able to change the parameters interactively during a simulation. Simulation
results are observed during the simulation process and then exported to the MATLAB workspace
for subsequent analysis.
Building a simple system using Simulink
S-M-D control system is considered for demonstrating the use of Simulink in the control system.
The system parameters are set as follows:
PID controller using Simulink
The term PID stands for Proportional, Integral and Derivative controller. This type of controller
is very popular and widely used in various applications. The combination of the three types gives
the controller various advantages over other conventional controllers. Each term has its function
and effect on the system. The proportional term, Kp, has the property to reduce the rise time of
10. 9
the output response whereas the integral term, Ki, is used to eliminate the steady-state error but it
may affect the transient response. The derivative term, Kd, improves the stability of the system,
reducing the overshoot and improving the transient response. The transfer function of the PID
controllers is:
The closed-loop transfer function of the S-M-D system with PID controller is obtained as:
The closed-loop system with PID controller will be modelled in Simulink. We can apply any
combination of the three terms of the PID controller by setting the unwanted term equal to zero.
It is important to mention that it is not necessary to implement all three terms if any simple
combination provides a good and accepted output response.
12. 11
Step Response of a sample Control System, using its transfer function can be calculated as
below:
BlockDiagram of a Control System
13. 12
Now to determine the stability of any control system the following code may be used.
Using the Root-Locus diagram and Bode plot, it is possible to determine the system stability
using poles and zeroes of the transfer function.
15. 14
2. Using SIMULINK:
The open-loop S-M-D system using Simulink.
The open-loopresponse usingSimulink
16. 15
Closed loop simple SMD system using PID controller in SIMULINK:
PID controllerforS-M-DsystemusingSimulink
The closed-loopresponse withPIDcontrollerusingSimulink
17. 16
CONCLUSION
In this project the use of MATLAB and Simulink software package was shown to familiarize
with the advancement of the software in studying and analyzing control systems. First, we
introduced some basic topics about MATLAB, then the mathematical modeling of a physical
system (which is a SMD system in our case) is done and output response with different system
parameters for a step input. Some control techniques to study and analyze control systems such
as root locus and Bode diagrams have also been explained and obtained for the S-M-D system.
Finally, the Simulink is introduced to show the ability to explore its advantages and construct
systems with some basic knowledge about control systems. Simulink provides with the ability to
investigate control systems and design controllers even one does not acquire much knowledge
about control systems design techniques just by experimenting with the controller parameters
and adjusting them to achieve the desired performance.
In general, this project presents the use of MATLAB and Simulink in an effective and direct way
to study, analyze and design control systems.
18. 17
REFERENCES
1. Using MATLAB, Mathworks, Inc., MA.
2. Using SIMULINK, Mathworks, Inc., MA.
3. R. D. Dorf, Modern Control Systems, Prentice-Hall.
4. K. Ogata, Solving Control Engineering Problems with MATLAB, Prentice-Hall.
5. Norman S. Nise, Control Systems Engineering, John Wiley & Sons.