Understanding Simulink using Matlab
In this tutorial, we will use the Simulink library browser to understand the blocks, waves, and functions that it has and perform a set of operations on a set of waves and plot each one of them on a scope. <!--more-->
Introduction
According to Wikipedia, Simulink is a MATLAB-based graphical programming environment for modeling, simulating, and analyzing multi-domain dynamical systems. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries.
It offers tight integration with the rest of the MATLAB environment and can either drive MATLAB or be scripted from it. Simulink is widely used in automatic control and digital signal processing for multi-domain simulation and model-based design.
Table of contents
To follow this article along - the reader will need the following:
- A basic understanding of the Simulink library browser.
- Be able to perform logical & arithmetic operations on waves.
- Plot singular & compounded waves.
Prerequisites
- A basic understanding of any programming language.
- Have Matlab installed on your system, you can download it from here.
You can also get a free Simulink trial from here.
If you are new to Matlab, you can check this tutorial which will help you understand the basic concepts of it.
Simulink library browser
The Simulink library browser will provide blocks, waves, functions, models, and other useful tools that would help you with your simulation.
To open the Library Browser, click on the Library Browser button in the toolbar of Simulink.
.
Let's simulate!
Let's start with a simple sine wave: Y = 2sin(4x)
.
In order to simulate a wave, you'll need to use the library browser to fetch the following:
- A Sin wave from Simulink > Sources > Sin wave.
- A Scope to implement the wave from Simulink > Commonly used blocks.
Drag & drop the blocks and double click on the sin wave to edit its properties.
Set the Amplitude to 2, the Frequency to 4 & the sample time to 0.001, finally connect the wave to the scope with your left courser.
.
Click on the run button from the Simulink toolbar then double click on the scope to display the wave.
.
Sum of 2 waves
In order to add 2 waves, you need to use the sum function from the library browser.
Let's simulate the following wave: Y = 2sin(4x) + 5sin(6x)
.
- 2 Sin waves from Simulink > Sources > Sin wave.
- A Scope to implement the wave from Simulink > Commonly used blocks.
- A sum function to add the waves from Simulink > Math operations > sum.
Drag & drop the blocks and double click on the sin waves to edit their properties.
.
Connect the sin waves to the sum block and connect the sum block to the scope.
.
Click on the run button from the Simulink toolbar, then double click on the scope to display the wave.
.
Compounded wave
We will simulate the following Compounded wave.
.
- 3 Sin waves from Simulink > Sources > Sin wave.
- A Scope to implement the wave from Simulink > Commonly used blocks.
- A sum function to add the waves from Simulink > Math operations > sum.
- A product function from Simulink > Commonly used blocks > product.
Drag & drop the blocks and double click on the sin waves to edit their properties.
Note that in Simulink you can't add cos wave, so to change that you need to add pi/2 to the phase of a sin wave to change it to a cos wave.
.
- Connect the first 2 sin waves to the product block, and from the product block connect the pipe to the first output of the scope & take another pipe to the sum block.
- Connect the cos wave to the second scope output & take another pipe to the sum block.
- Finally, connect the output of the sum to the third scope output.
This is how the waves should be connected:
.
Click on the run button from the Simulink toolbar, then double click on the scope to display the wave.
.
Conclusion
In this tutorial, we have learned how to fetch blocks & functions from the Simulink library browser. We have also learned how to use the sum & product blocks to connect multiple waves and display them on a scope. Don’t forget to test out the waves with different amplitudes & frequencies to fully understand how it works.
Happy simulation!
Further reading
- https://www.mathworks.com/help/simulink/
- https://ctms.engin.umich.edu/CTMS/index.php?aux=Basics_Simulink
- https://www.sciencedirect.com/topics/computer-science/simulink
Peer Review Contributions by: Ahmad Mardeni