Madina Higher Institute of Engineering and Technology
Department of Electronics & Communication Engineering
Waves and Transmission Lines Laboratory
Simulation Workbook
Academic Year: 2024 - 2025 Course
Code: COMM 362
Student Name:
Student ID:
Prepared by
Dr. Mahmoud Mohamed
Eng. Yasmine Ahmed
1. Introduction to MATLAB Simulink
Simulink is a simulation and model-based design environment for dynamic
and embedded systems, which are integrated with MATLAB. Simulink was
developed by a computer software company MathWorks. It is a data flow
graphical programming language tool for modelling, simulating and analyzing
multi-domain dynamic systems. It is basically a graphical block diagramming
tool with a customizable set of block libraries. Furthermore, it allows you to
incorporate MATLAB algorithms into models as well as export the simulation
results into MATLAB for further analysis.
Simulink supports the following:
• System-level design.
• Simulation.
• Automatic code generation.
• Testing and verification of embedded systems.
To get started with Simulink, type simulink in the command window as shown
below:
1
It will open the Simulink page as shown below:
You can also make use of Simulink icon present in MATLAB to get started
with Simulink:
2
When you start Simulink, you are navigated to the start page as shown below:
Here you can create your own model, and also make use of the existing
templates.
Click on the Blank Model and you will get a Simulink library browser that can
be used to create your own model. The screen for Blank model is as follows:
3
Click on Library and it will display you the Simulink library as shown below:
4
The Simulink library browsers is a collection of many libraries. It offers
Commonly Used Blocks, Continuous, Dashboard, Logic and Bit Operation,
Math Operations etc.
Besides that, you will get other library list like Control system toolbox, DSP
system toolbox etc.
5
Here is an example of Math operations library list:
It has Abs, Add, Algebraic Constraint, Assignment etc. that you can make use
in your model.
6
Given below is an example of Logic and Bit Operations:
7
2- MATLAB Simulink — Starting Simulink
As mention before, you can start Simulink by using simulink command in the
MATLAB command window as shown below:
Click on enter to open the Simulink startup page as shown below:
8
The startup page has a blank model, subsystem, library to start the model from
scratch. There are also some built-in templates that can help the users to start
with.
To create a model, the user can click on blank model and it will display a page
as shown below:
Click on Save to save your model. The blocks to build your model are available
inside the Simulink library browser. Click on library browser as shown below:
9
The library browser has a list of all types of libraries with different blocks as
shown below:
10
Libraries in Simulink
Let us understand some of the commonly used libraries in Simulink.
Continuous
A continuous blocks library gives you blocks related to derivatives and
integrations. The list of blocks are as follows:
Dashboard
With Dashboard, you will get controls and indicator blocks that help to interact
with simulations. The following screen will appear on your computer:
11
Discontinuities
Here, you will get a list of discontinuous functions blocks as displayed below:
12
Discrete
Here, you will get time relation function blocks as shown below:
13
Logic and Bit Operations
In this category, you will get all logical and relational type blocks as displayed
below:
Lookup Tables
You will all the sine, cosine function blocks as shown below:
14
Math Operations
All mathematical operations like Add, Absolute, divide, subtract are available.
The list is as follows:
15
Ports and Subsystems
You will get blocks like a subsystem, switch case, enable etc. The list is
displayed below:
16
Signal Attributes
Modify the signal attribute blocks such as Data Type Conversion. The
following screen will appear on your computer:
Signal Routing
The block in this category is used to route signal blocks such as bus creator,
switch etc. The following screen will appear on your computer:
17
Sinks
The blocks in this category help to display or export signal data blocks such as
Scope and To Workspace. The following screen will appear on your computer:
18
Sources
It helps to generate or import data blocks. For example, sine wave. The
following screen will appear on your computer:
19
20
3- MATLAB Simulink — Blocks
Blocks in Simulink helps to create models. You can make use of a Simulink
library browser that has different types of blocks for creating a model.
First, open a blank model. The display will be as shown below:
You can save your model by clicking on the Save button. Hence, your changes
will be saved successfully. Now, open the library browser to get the blocks
into your model canvas.
The two ways to select the blocks are as follows:
• Using Simulink browser library.
• Searching for block inside model canvas.
Simulink browser library
Open the Simulink library browser as shown below:
21
If you looking for a specific block and don’t know which library, you can
search for it inside the search block which is available as shown below:
22
Here, we got all the blocks related to Sine. You can also go inside the library
and pick your block.
Add block, Product block etc. The display will be as shown below:
To bring the block inside your model, you can select the block and drag it inside
your model, as shown below:
23
Another way is to right click the block and add to your current model. An
example for the same is given below:
We have not saved our model. Hence, it comes as untitled. Now, you can add
to the model untitled. The block will be seen inside your mode.
Searching for block inside model canvas
Another way to add blocks to your model is to click inside the model and type
the name of the block. It will search in the library browser and list all the
models as per what you have typed.
An example for the same is given below:
24
We have typed Sine, and it displays all the blocks related to sine.
25
4- MATLAB Simulink — Lines
Lines are used to connect the blocks with an arrow. Each block will have its
own input and output connector. The communication between the blocks will
take place with the help of lines.
Let us understand the same with an example. Select a blank model from
Simulink page as shown below:
It will open a blank model workspace as shown below:
26
Click on Simulink Library browser to drag some blocks in the model
workspace.
Consider that in the model, we want to add two given numbers. So let us pick
the Add block, the display block and the constant block.
The constant block has one output connector, the Add block has two input
connectors and the display block has one input connector respectively. You
can drag the link from one output to another input as shown below.
Here, we have two constants with values 10 and 20. They are connected to the
add block with lines. The add block is connected to display with a line.
27
When the lines are connected, the display is as follows:
Now click on Run to see the result in the display block. It will add 10 + 20 to
give the result as 30 in the display block.
28
29
• Sound generation using Simulink
To generate sound, connect the model as shown in the following figure
Click on the block of sine wave and change the parameters of this block as shown
in the following figure
30
Then, open the block of audio device writer and make sure that the sample
period is equal to the sample period in the block of sine wave as show in the
figure
31
Finally, run the simulation and listen to the generated sound by this system. You
will note that spectrum analyzer displays the signal of the generated sound with
the frequency as show in the figure
32
33
• Record Sound using Simulink
To record sound, connect the model as shown in the following figure
After running the simulation and record your sound, you can obtain the
following results from the spectrum analyzer and scope respectively.
34
35
36
• Display the signal by the scope block
We want to display the sine wave and here, we have taken four sign wave in
our model workspace as shown below:
Now we want to display the output of the signal, so let us use a Scope block
from sinks library as shown below:
37
Now select and drag the Scope block inside your model workspace.
38
The sine wave has one output and the scope block has one input. We have four
sine waves displayed. We have to change the parameters of scope block to take
four inputs.
Right click on scope block and click on Block Parameters and it will display the
screen as shown below:
Go to the settings icon and change the input parameter from 1 to 4 as shown below:
39
Click on Apply to save the changes. Let us now connect the sine wave to the scope block with
arrows as shown below:
40
We would like to change the frequency of each sine wave to a different one, so that we get a
signal graph of different frequencies. So right click on sine wave and open the Sine wave
block parameters as shown below:
We are going to keep the amplitude as 1 for all sine waves and the frequency of the first sine
wave is 1, second one is 3, third one is 6 and the last one is 10. Click on the Run button and
open the scope block parameters to see the sine wave as shown below:
41
42
• Signal processing
we will understand the signals generation in Simulink by using the signal
generator block.
The signal generator can show waveforms like sine, square, sawtooth, random.
We will select the square waveform. Let the amplitude and frequency be as 1.
Click on OK to update the changes made as show in the following figures.
43
Now click on the Run button to see the square waveform as shown below:
44
Right click signal generator or double click and change the waveform and obtain
the result with yourself.
Add the step signal block from source library to the previous model and connect
it as shown.
45
Now click on Run button to run the model.
46
• Adding delay to the signal
Let us take a blank model and add sine wave, transport delay and scope block
to it as shown below:
Now that we have the Transport delay in our model, right click on it and open
block parameters as shown below:
47
Let us change the time delay from 1 to 3. Make the changes and click on OK
button.
Now add one more input port to scope block. Right click on scope block and
select the signals and ports. Select 2 for number of input ports.
Run the simulation to see a delay of 3 seconds to the sign wave. Right click scope
block and select block parameters to see the display.
48
49
• Mathematical Library
Let us pick the block we want. Select chirp signal and sine wave from sources
library, add block from math operations, scope block from sinks library and
connect them as shown:
Note that a chirp is a signal in which the frequency increases (up-chirp) or
decreases (down-chirp) with time.
Double click chirp signal and change the initial frequency from 0.1 to 0.05
and click on Ok button.
50
The other blocks are kept as the default values. Now, click on run to see the
output in scope as shown below.
51
52
Problems
Problem 1: Design all logic gates [OR-AND-NOT-NOR-NAND-XOR-
NXOR] by using the logical operator block in Simulink.
Connect the model of each gate as shown below in example of OR gate
model and then verify the truth table of each gate.
Output simulation by student
TA. Evaluation:
Date:
Signature
53
Problem 2: Integrate and differentiate the sine wave by using the derivative
and integrator blocks in Matlab Simulink. Plot the three signals by the scope
block on the same graph (screen) and show the legend on the graph.
Output simulation by student
TA. Evaluation:
Date:
Signature
54
Problem 3: Solve the following mathematical equation by using Matlab
Simulink:
Output simulation by student
TA. Evaluation:
Date:
Signature
55
Problem 4: Solve the following mathematical equation by using Matlab
Simulink:
Note:
This equation can be solved by integrating dy/dt to the following:
Output simulation by student
TA. Evaluation:
Date:
Signature
56