Practical 2
Modeling of Electrical and Mechanical Systems in MATLAB and Simulink.
Objective:
Learn the basics of modeling of different systems.
Modeling in Simulink.
Tools/Software Requirement
MATLAB
Symbolic Math Toolbox
Control Toolbox
Simulink
Recommended Books:
Feedback Control Systems by Charles L. Phillips & Royce D. Harbor
Control Systems by Norman Nise
Activity Time Boxing
Task No. Activity Name Activity Time
Lecture and overview by instructor
1 15 ~ 20 mins
2 Performing Experiment 120 ~140 mins
3 Results & Evaluation (signed by the instructor) 15 ~ 20 mins
Total Time: 180
Theory
Introduction to Control Systems
Suppose a slave who used to fan his master using some kind of a cloth and he does this all day long. To
make his life easy, fans were introduced. To this Modern day, different types of engineering techniques
are being put together to make the life easy for a normal man. Control system is just one and the most
important of these fields.
Whenever the name of Control systems is taken, it always comes with the name of Control Systems
Analysis. It basically analyses the system parameters like velocity, temperature, mass, damping ratio,
etc… which are necessary for its quality output. Using these parameters one can judge its real life state
and then implement it. WWII accelerated the development of classical control theory and practice. Heavy
guns had to be rapidly and accurately positioned. Precise navigation and target tracking were increasingly
important, and aircraft performance was improved greatly with the incorporation of complex control
systems to aid the pilot. Today, control systems are pervasive in industry and in our everyday lives. They
range from governmental regulation (such as that governing monetary policy) to automated and highly
flexible manufacturing plants to sophisticated automobiles, household appliances, and entertainment
systems. It is our purpose to learn to design control systems for a wide variety of applications.
Control systems in Human Body
Human body contains various control mechanisms like the balancing mechanism is carried out by gyros
in our ear, all the six senses are very good example of control systems as they are giving feedback
required by the body to function accurately, if any one of our senses gets disturbed we can our self-feel
the malfunctioning of our body like this example, just stand with your feet one in front of other and place
your hands on your back and make sure your eyes are open. After you are in the desired position close
your eyes, you will notice the importance of feedback control systems.
Transfer functions in MATLAB
A Transfer Function is the ratio of the output of a system to the input of a system, in the Laplace domain
considering its initial conditions and equilibrium point to be zero. This assumption is relaxed for systems
observing transience. If we have an input function of X(s), and an output function Y(s), we define the
transfer function H(s) to be:
𝐻(𝑆) = X (s)
Y ( s)
Lab Task 1:
Q1.a) Find the Laplace transform of the following differential equations using MATLAB:
˙ x
1) ÿ +3 ẏ +2 y= ẋ +3
2) ẍ +3 ẋ+2=4 ẏ+ 12 y
Attach the MATLAB codes and plots in the report
Introduction to Simulink
SIMULINK is a program for simulating dynamic systems. As an extension to MATLAB, SIMULINK
adds many features specific to dynamic systems while retaining all of MATLAB’s general-purpose
functionality. SIMULINK has two phases of use: model definition and model analysis. A typical session
starts by either defining a model or retrieving a previously defined model, and then proceeds to analysis
of that model. These two steps are often performed iteratively until the model achieves the desired
behavior. To facilitate model definition, SIMULINK adds a new class of windows called block diagram
windows. In these windows, models are created and edited principally by mouse driven commands. Part
of mastering SIMULINK is to become familiar with the manipulation of model components within these
windows. After you define a model, you can analyze it either by choosing options from the SIMULINK
menus or by entering commands in MATLAB’s command window.
Constructing a Simple Model:
At the MATLAB command window, type Simulink and press Enter. This command displays a new
window - Simulink Start Page – that have new templates and building models like feedback controller
and digital filter etc. These have already existing blocks however one can opt for blank Simulink model
also.
Figure 2.1 Simulink First Page
Figure 2.2 Blank Model in Simulink
The pop-up windows can be moved by users. Blocks can be copied from one window to another by
dragging them from the original location to the new location by holding down the left mouse button.
Assemble the following diagram in your working window. [e.g. Step Input -> Sources; Sum ->Math
operations, Transfer Fcn -> Continuous; Scope -> Sinks]
Figure 2.3 Different Simulink Blocks
Table 2.1 Location and icons of different important blocks :
Location Icons
Simulink > Continuous > Integrator
Simulink > Continuous > Transfer Function
Simulink > Continuous > Derivative
Simulink > Math Operations > Absolute
Simulink > Math Operations > Gain
Simulink > Math Operations > Slider Gain.
Simulink > Math Operations > Sum
Simulink > Sinks > Display
Simulink > Sinks > Scope
Simulink > Sources > Clock
Simulink > Sources > Pulse Generator
Simulink > Sources > Ramp
Simulink > Sources > Signal Generator
Simulink > Sources > Signal Builder
Simulink > Sources > Sine Wave
Simulink > Sources > Step Signal
Lab Task 2:
Q: Investigate the open loop step response of the integrator.
Figure 2.4 Implementation of Open loop Integrator in Simulink
Step 1: Open Simulink by typing Simulink on MATLAB command window
Step 2: A new window will appear .select the option to create new model.
Step 3: Select Simulink Library icon from the tool bar.
Step 4: A pop-up window of the library will appear. Select and drag the following icons to Simulink
window.
• Simulink > Continuous > Integrator
• Simulink > Math Operations > Gain.
• Simulink > Sources > Step Signal.
• Simulink > Sinks > Scope.
Step 5: Now connect these blocks as shown in Figure 3 and press play button
Step 7: Now click on scope block to visualize the graph. You can get the response as shown in the figure
below.
Figure 2.5 Output of Step Response of Integrator on Scope
Step 7: Now plot your own graph below and compare it with Figure 5.
Graph 2.1
Attach graph that you made using MATLAB here:
Compare Figure 2.5 and Graph 2.1 in the following table.
Lab Task 3:
Q: Investigate the closed loop step response of the integrator.
• Repeat the same steps as described above for the following figure.
Figure 2.6 Close loop Integrator with Negative feedback in Simulink
You can get the response as shown in the Figure 2.7:
Figure 2.7 Output of Close loop Integrator on Scope
Now plot your own graph below and compare it with Figure 2.7
Graph 2.2
Attach graph that you made using MATLAB here:
Compare Figure 2.7 and Graph 2.2 at the given place below
Mathematical Modeling:
Mathematical modeling is the mathematical representation of any system. System can belong to
any field of science. A mathematical model is the replica of the exact behavior of the system, it
represents the relations between the inputs and outputs and how the output corresponds by
changing the inputs.
1. Modeling of an Electrical Network
a. RC Circuit
Figure 2.8 RC Series Circuit
Where, V ¿ is the input voltage and V out is the output voltage.
1
−V ¿ + iR+
C
∫ i ( t ) dt=0
1
−V ¿ (s )+ I (s)R + I (s)=0
Cs
[
I ( s ) R+
1
Cs ]
=V ¿ ( s)
We get the following eq. (i)
V ¿ (s)
I ( s )=
[ R+
1
Cs ] Eq (i)
Also, Laplace transform for V out is
1
V out =I ( s )
Cs
I ( s )=Cs V out Eq (ii)
V ¿ (s)
=C (s)V out
[ R+
1
]
cs
c (s )V ¿ (s )
=C (s)V out
[ 1+ Rcs ]
V out 1
= Eq (iii)
V ¿ 1+ RCs
Eq-(iii) is showing the transfer function required.
Here, R = 1k Ω C=1µF
V out
Finding the transfer function
V¿
Step 1: Write the transfer function in MATLAB for the given values of R and C.
Step 2: Click on Run in the bar above and click on scope icon.
The graph will be displayed as shown below
Figure 2.9 Simulink Response for the System
Step 3: Now plot some more graphs by changing the value of R to 10 kΩ , 100 kΩ and 1000 kΩ
respectively while keeping C constant and observe the changes in the Graph. Paste the Graph below at the
space provided for Graph 3.
Step 4: Similarly plot some more graphs by changing the value of C to 10 µF, 100 µF and 1000 µF by
keeping R = 1 kΩ and observe the changes in the graph. Paste the graph below at the space provided for
Graph 4.
Note that 63 percentage of the final value as shown in graphs above is equal to T which is called circuits
time delay or time constant.
Graph 2.3:
Graph 2.4:
Observations
Write your observations for RC Circuit when C was constant and R varied. Did the system slow
down?
Yes, the system slows down as the resistance (R) increases in an RC circuit with constant
capacitance (C). This is evident from the increased charging and discharging times, larger time
constant, decreased peak values, and prolonged time to reach steady-state response.
Time Constant: The time constant of the RC circuit, τ=R×C, increases with higher
resistance (R). A larger time constant indicates a slower response of the circuit to changes
in input signals. Therefore, the system slows down as the resistance increases.
Steady-State Response: A higher resistance (R) results in a longer time for the circuit to
reach steady-state conditions. Steady state is reached when the capacitor is fully charged or
fully discharged, and the voltage or current across it remains constant. The slower response
due to higher resistance prolongs the time to reach this steady-state condition.
Write your observations for RC Circuit when C was constant and R varied. Mention the effect
observed:
In an RC circuit where the capacitance (C) is constant and the resistance (R) varies, several effects
can be observed:
Charging Time Constant: The time constant of the circuit τ=R×C, determines how
quickly the capacitor charges or discharges. When the resistance (R) increases, the charging
time constant also increases, resulting in a slower rate of charging and discharging.
Charging and Discharging Rates: With a higher resistance (R), the capacitor charges and
discharges at a slower rate. This means it takes longer for the capacitor to reach its
maximum voltage during charging and to discharge to a lower voltage during discharging.
Peak Voltage and Current: As the resistance (R) increases, the peak voltage across the
capacitor during charging decreases, and the peak current during discharging also decreases.
This is because a higher resistance limits the flow of current in the circuit, resulting in lower
peak values.
Time to Reach Steady State: A higher resistance (R) leads to a longer time for the circuit
to reach steady-state conditions. Steady state is reached when the capacitor is fully charged
or fully discharged, and the voltage or current across it remains constant.
Frequency Response: The RC circuit's frequency response, particularly in applications like
filtering, changes with variations in resistance. A higher resistance (R) can shift the cutoff
frequency of the circuit, affecting its frequency response characteristics.
Overall, varying the resistance (R) in an RC circuit with constant capacitance (C) affects the time
dynamics, peak values, and steady-state behavior of the circuit, ultimately influencing its
performance and applications.
Provide MATLAB code for the above equations in the given space
Design the Simulink model in the space given below
Figure 2.10 Simulink Model
b. RLC Circuit
Figure. 2.11 RLC Circuit Diagram
1
−V ¿ + iR+ L∫ i ( t ) dt+ ∫ i (t ) dt=0
c
1
−V ¿ ( s ) + I ( s ) R+ LsI ( s ) + I (s)=0
Cs
[
I ( s ) R+ Ls +
1
Cs]=V ¿ (s)
V ¿ (s)
I ( s )=
[ R+ Ls+
1
Cs ]
1
V out =I ( s )
Cs
I ( s )=Cs V out
V ¿ (s)
=C(s)V out
[ R+ Ls+
1
cs ]
C (s)V ¿ (s)
=C (s)V out
[ 1+ LC s 2 + RCs ]
V out 1
=
V ¿ 1+ LC s 2+ RCs
Finding the relation between the output voltage of capacitor to the input voltage applied. Use
RL= 1 kΩ, L= 1 mH, C= 1 µF.
Step 1: Write the transfer function in MATLAB for the given values of R, L and C.
Step 2: Click on Run in the bar above and click on scope icon.
Step 3: Now plot some more graphs by changing the value of L from 1 mH to 10mH, 100 mH and
1000mH while keeping RC values constant and observe the changes in the Graph. Paste the Graph below
at the space provided for Graph 2.5.
Step 4: Similarly plot some more graphs by changing the value of C to 10 µF and 100 µF by keeping R =
1k Ω and L = 1mH and observe the changes in the graph. Paste the Graph below at the space provided for
Graph 2.6.
Graph 2.5:
Graph 6:
Observations
Write your observations for RLC Circuit when R & C were constant and L varied.
Write your observations for RLC Circuit when C varied and R,L were kept constant. Mention the effect
observed:
Provide MATLAB code for the above equations in the given space
Design the Simulink model in the space given below
Figure 2.12 Simulink Model
Lab Task 2:
2. Modeling of a Mechanical Network
Cruise Control Model:
Following is the equation of motion for an automobile.
v̇+ ( mb ) v= mu
Using this differential equation, we can find the transfer function of this cruise control. Now implement
the transfer function using Simulink and analyze its output. Use the values of m = 1580 kg , and b = 26
N*sec/m period of time. Its output will be quite similar to a car whose driver accelerates it for instance
and then leaves the car to decelerate at its own speed. Also, use the differential equation to make a second
model of the same system using Simulink.
Compare the output of both the systems now. It should be same.
Figure 2.13 Mass moving on a surface
1. Find the relation between the input force (u) and the output velocity (v)
2. Simulate the system on MATLAB and Simulink.
3. Find the transfer function.
4. Compare results of step 1 and 3.
Write the equations in the space provided
Provide MATLAB code for the above equations in the given space and attach graph
Observations/Analysis:
Write your analysis in the given space.
Design the model in Simulink and sketch the model in the space given below
Figure 2.14 Simulink Model
Post Lab Activity
Task #1:
Q1. What is the difference between the open loop and closed loop systems?
Task #2:
Q2. Simulate the step response of the transfer functions given in question 1(a) in MATLAB and Simulink.
Evaluation Criteria:
Performance Exemplary Satisfactory Developing Unsatisfactory Marks
Criteria
(5) (3-4) (1-2) (0)
Procedure Steps of Steps of Steps of Procedure is
experiments are experiments are experiments are missing.
clear, sequential present but incomplete and
Conclusion is
and in complete lacking procedure is
missing.
sentences. completeness. lacking.
Pictures of Conclusion is
Result &
Responses are incomplete.
Analysis is
included. Result
written in
& Analysis is
Performance Exemplary Satisfactory Developing Unsatisfactory Marks
Criteria
(5) (3-4) (1-2) (0)
written in a incomplete
complete form. sentence.
Understanding Understands Understands Understands few Wasn’t able to
the Concept everything of majority of the things. understand
the topic. portion. anything.
Lab Instructor: