Lab2 - Intro To Simulink - 200927

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

TITLE : Introduction to Simulink – II

DATE OF
: Fall 2023
EXPERIMENT

LAB NUMBER : 2

NAME :

ROLL NO :
COMMUNICATION SYSTEMS LAB (308202)

Instructions:
1. You are required to complete and submit ALL the tasks given at the end of each tutorial during
your lab timings strictly.
2. At the end of the lab manual, you will find some experiments which are required to be done as
home assignment and submitted before the next lab.
3. Please show your complete work, through Simulink models and results for both lab performance
(report submitted during lab timings) and lab report (report submitted as home assignment).
4. Save your models after performing each step to avoid loss of your work due to any reason.
Objective:
In this lab, you will learn to develop advanced models in Simulink. It is assumed that you have already got
basic knowledge of Simulink and MATLAB.
2.1 Tutorial #1: Importing/exporting data between MATLAB/Simulink:
In this tutorial, you will learn how to exchange data between MATLAB and Simulink.
i. In a new blank model, drag the From Workspace block from Sources Library. Also, drag Scope
block from Sinks Library to the model and connect the two blocks.
ii. In the MATLAB’s command window, write down the following code lines:
>> t = 0:0.1:10;
>> x = sin(t);
>> sig = [t’, x’];
(Note that the variables t and x are declared as column vectors in the variable sig.)
iii. In the model designing window, double click the From Workspace block and change Data from
simin to sig.
iv. Run simulation and afterwards double click the Scope to see the results.
v. Modify the code in Step ii by changing the variable t as t = 0:10; and re-run the simulation.
Observe the change in the displayed output on Scope by changing the sampling time.
vi. Now type the following code and understand the relationship between time samples and data
samples plotted through the From Workspace block:
>> t = 1 : 5;
>> x = [t-2; t+3; t.^2];
>> sig = [t’, x’];

Lab #2: Introduction to Simulink – II Page 2 of 5


COMMUNICATION SYSTEMS LAB (308202)

(Note that the variable t is a vector but variable x is a matrix so one complete row of data is read
at every time instant, instead of just one value as was the case in Steps ii and v above).
vii. Due to the default setting Form output after final data value by: Extrapolation in the From
Workspace block, data is extrapolated beyond t=5 in Scope. Change Form output after final
data value by: Setting to zero, and note the results after re-running the simulation. Further, run
your simulation on the setting Form output after final data value by: Holding final value
viii. Now, in a new blank model, drag the Uniform Random Number block from Sources Library.
Also, drag To Workspace block from Sinks Library to the model and connect these two blocks.
ix. Double click the To Workspace block. Change the Variable name: y and Save format: Array.
Run the simulation. Check the size of the variable “y” in MATLAB’s workspace. The size shall
be 101 x 1. Develop stem plot for y versus tout. Note that tout is the independent variable here.

x. Double click the Uniform Random Number block and change the sample time to 1 instead. Re-
run the simulation and observe the size of variable y. Now make a new stem plot (in a new
window) for y versus tout. Observe the difference between the two plots due to change in sample
time.
Task #1
Generate 10 uniformly distributed random numbers in the range −𝑋𝑋 to 𝑋𝑋, where 𝑋𝑋 refer to the last
two digits of your registration number. Store these numbers in a file named Data_File.mat by using the To
file block. You will be required to mention a Variable name and select Save format: Array. After
retrieving these random numbers, develop a stem plot in MATLAB.
2.2 Tutorial #2: Implementing equation in Simulink:
In this tutorial, you will learn to develop a model on Simulink that can implement a mathematical equation.
The expression to be implemented is:

2 − 𝑒−𝑡(2 cos(2𝑡) + sin(2𝑡))


𝑦= . (1)
10

i. Drag the Ramp and Constant blocks from the Sources library and place in an empty model
designing space.

Figure 2.1: An intermediate step for implementing equation (1)

Lab #2: Introduction to Simulink – II Page 3 of 5


COMMUNICATION SYSTEMS LAB (308202)

ii. Next, drag Product, Gain, Trigonometric Function, and Math Function blocks from the Math
Operations library to the window (where the Ramp and Constant blocks are already placed).
Join these blocks as shown in Figure 2.1.
iii. You will further need two Add blocks, a Product block, a Constant block, a Gain block and
finally the Scope block to finish the implementation of equation (1).
iv. Click on the run button on the panel of the model space.
v. After the simulation completes, double click on the Scope icon to view the waveform.
vi. Your waveform shall resemble the display as shown in Figure 2.2.

Figure 2.2: Final plot for equation (1)

Task #2
Implement the following equation in Simulink:
2 6
𝑦= (4 sin(3𝑡) − 3 cos(4𝑡)) + 𝑒−2𝑡. (2)
25 25

2.3 Tutorial #3: Reading audio signal in Simulink:


In this tutorial, you will learn to read an audio signal in Simulink and study the parameters of the read
signal in time and frequency.

i. Place the audio sample “AudioSample.mp3”, provided to you, on the current working path of
Simulink.
ii. In a new designing model, drag the From Multimedia File block from the Sources Library of
Computer Vision System Toolbox.
iii. Drag the Time Scope and Spectrum Analyzer blocks from DSP System Toolbox/Sinks.

Lab #2: Introduction to Simulink – II Page 4 of 5


COMMUNICATION SYSTEMS LAB (308202)

(“Time Scope” is used in this tutorial instead of “Scope” because Time Scope is optimized to display
data with a large sampling rate, whereas Scope usually shows one sample at a time and may take a
considerable amount of time to display multimedia signals which have high sampling rates.)
iv. Connect the From Multimedia File block to both the copied sinks.

v. Double click the From Multimedia File block and browse the “AudioSample.mp3” file. Also
change the Number of times to play File: 1.
vi. Run simulation to observe time and frequency information of the played audio sample. Change
simulation time to different values between 0 to 15 to make observations.
vii. Complete information on “AudioSample.mp3” can be obtained from MATLAB by using the
command:
>> info = audioinfo('AudioSample.mp3')

Task #3
Visit the following website and choose an audio sample of your choice.
https://file-examples.com/index.php/sample-audio-files/sample-mp3-download/
i. Display the time and frequency information of the chosen signal.
ii. At which frequency, you get the highest peak?
iii. Find two peaks on the time display of the signal. What is the time difference between them?
2.4 Experiments:
i. Declare a time vector (𝑡) in MATLAB and access it in Simulink. Implement the following
equation in Simulink:
𝜋 3
𝑠 = exp(−0.5𝑡) sin (𝑡 + )+
6 2
Plot s versus t in Simulink.
ii. Download any online available .mp3 file from the link mentioned in Task #3. Using this file as
“input signal” perform the following operations.
a. In a new designing model, read the “input signal” and display its time series and frequency
spectrum.
b. Add band limited white noise (from Sources) to the “input signal” in the same model
generating a “noisy signal”.
c. Send the “input signal” and the “noisy signal” to two different variables in MATLAB.
d. Plot the signals in MATLAB (in two rows of the same Figure) and state the difference that
you notice between them.

Lab #2: Introduction to Simulink – II Page 5 of 5

You might also like