Lab – 1
Date: _______________________
1
Version 1.0 – Zulaikha Kiran – 16/01/2019
Spring 2019 ADC Lab 1 Version 1.0
Introduction
The purpose of this lab is to provide the student with a review of numerical computations
software, MATLAB, as well as provide revision for the basic signals and systems concepts,
which will be used in the coming labs.
Equipment
Software
o MATLAB
Instructions
This is an individual lab. You will perform the tasks individually and submit the
required files at the end of the lab.
There will be no concept of make-up labs. The lab if missed may be performed later
for practice and knowledge required for the coming labs, but it will not be graded.
There will be two submissions for this lab.
o A single .m file containing all tasks and exercises separated by a commented
line will have to be uploaded to LMS. The code should be executable, and
must display results of all tasks when run. The name of the file must be
Lab<labno>_<UETno>_<Name> e.g. Lab1_123_Xyz.
o A lab handout containing questions for different tasks will have to be filled
and handed in at the end of the lab.
Plagiarism or any hint thereof will be dealt with strictly. Any incident where
plagiarism is caught, both (or all) students involved will be given zero marks,
regardless of who copied whom. Multiple such incidents will result in disciplinary
action being taken.
2
Spring 2019 ADC Lab 1 Version 1.0
Command Window
Starting MATLAB should open Command window, in which simple commands can
be entered. Clear the Command window by typing clc and pressing enter.
To perform a simple computation, type the command and press enter. e.g.
The results of these computations are saved in variables, whose names are chosen by
the user. These names can be a character followed by characters or numbers. In
MATLAB, uppercase and lowercase letters are not the same, i.e. A and a are not
equivalent. In case a command is typed without a variable name, the result is stored in
ans.
3
Spring 2019 ADC Lab 1 Version 1.0
These variables can be accessed by typing the name of the variable in the command
window.
There are three types of numbers used in MATLAB
a. Integers: e.g. a = 10 without any decimal points will be an integer of value 10
b. Real numbers: e.g. b = 10.1 is a real number. Two variables; realmin and
realmax can be used in the command window to get the smallest and largest
positive real number in MATLAB.
c. Complex numbers: e.g. c = 1+2i is a complex number. Either i or j can be used
to denote the imaginary numbers.
Workspace
The variables of the current session are saved in the Workspace, and can be seen
either in the Workspace window, or by typing whos in the command window.
Help
One of the features that will be used a lot in the labs is the help command. The details
about any MATLAB function and its usage can be obtained by typing help followed
by the function name.
4
Spring 2019 ADC Lab 1 Version 1.0
Typing help without any function name results in a list of all the topics for which help
is available.
The above task can also be performed by clicking on the help icon in the toolbar,
which opens the help window, in which information about all MATLAB functions,
including the toolboxes is available.
Arithmetic Operations
Matrices
All the quantities in MATLAB are treated as matrices. A scalar can be considered as a
1 x 1 matrix. Matrices can be defined by different methods.
o m1 = [1 2 3; 4 5 6]; creates a matrix with row1 = 1 2 3 and row2 = 4 5 6.
o m2 = ones(1,4) creates a matrix of 1 row and 4 columns with all values equal
to 1.
o m3 = zeros(2,3) works in a similar way with all values equal to zero.
o Equating a variable to another creates a matrix of the same size and value e.g.
m4 = m3 will create m4 variable of 2x3 with all elements equal to zero.
The size and length of matrices and vectors can be obtained by using size(___) and
length(___) respectively. Use help to understand the working of these functions if
required.
5
Spring 2019 ADC Lab 1 Version 1.0
Editing Window
6
Spring 2019 ADC Lab 1 Version 1.0
Exercise 1
Type or copy the following code into the editor and run it.
close all;
clear all;
clc;
%%%%%%%%%%%%%% Exercise 1 %%%%%%%%%%%%%%%%%%%%%%%%%%
t = 0:0.001:2;
fa = 1; % frequency of a
Aa = 5; % amplitude of a
pa = 0; % phase of a
a = Aa*cos(2*pi*fa*t + pa);
figure(1)
subplot(2,2,1), plot(t,a)
title('Continuous Time - Continuous Value Signal');
xlabel('Time (sec)');
ylabel('Signal a');
Use help command wherever required to understand the functionality of given
statements.
Answer the questions in the given handout.
Exercise 2
Exercise 3
7
Spring 2019 ADC Lab 1 Version 1.0
Exercise 4
Display a Discrete Time – Discrete Value sinusoidal signal d, with frequency 0.1,
amplitude 5 and phase 0, in a different part of the same figure.
Task 2 – Convolution
As studied in the signals and systems course, convolution is basically a superposition
sum of two signals. Write a code taking the input signal and impulse response as input
from the user, and perform convolution using this definition. Note that the input
variables will need to be zero padded in order to make their lengths equal so that
arithmetic operations can be performed using them. The length of the output variable
should be calculated using this new length of input signal.
Input from user can be taken by:
x = input('Enter x: ');
h = input('Enter h: ');
Use figure(2) to open a new figure window and select it, so that the next plots will be
displayed in this new window, and will not be overwritten on Task 1 results.
Divide the figure window into four parts by using the subplot function. Use stem to
display the input signal, the impulse response and the convolution output obtained in
three sub plots. Label all plots properly.
Use MATLAB function conv(___) to obtain the convolution output of the same
signals. Plot this in the fourth subplot.
8
Version 1.0
Method of Evaluation: Executable code, Filled lab document, In-lab marking by instructors
Measured Learning Outcomes: CLO2: Develop software simulations to observe the performance of digital communications systems.
CLO3: Report desired results proofs and calculations.
9
Version 1.0 – Zulaikha Kiran – 16/01/2019