Anda di halaman 1dari 9

Version 1.

Department of Electrical Engineering

EE 322 – Analog and Digital Communication

Lab – 1

MATLAB Review – Basic Operations and Functions

Student Name Student ID Marks

Date: _______________________

Instructors: Zulaikha Kiran, Qaseem Sajjad

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.

Course Learning Outcomes


CLO2: Develop software simulations to observe the performance of digital communications
systems.
CLO3: Report desired results proofs and calculations.

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

Getting started with MATLAB


 Open MATLAB from either the desktop icon or by searching in the Start menu.
Menu Bar/Tool Bar
 The icons at the top of the window change with the change in tab selected. The bar at
the bottom of this menu shows the current directory.

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 output can be suppressed by writing a semicolon after the statement.

 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

 Addition +, Subtraction –, Multiplication *, Division /, and Power ^ are the basic


arithmetic operations that can be performed in MATLAB.
 A dot . is added to the operation symbol in order to perform element-wise operation.
i.e. * will result in matrix multiplication (for which the sizes of the matrices must be
compatible), while .* will result in multiplication of the elements of a matrix with
those of another (for which the sizes of the matrices must be equal). Both of these
operations can be performed with a scalar without any size constraints.

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

 Small computations can be performed directly in the command window, however a


command once entered cannot be changed. Longer codes are usually written in the
Editor, where they can be modified as well as saved as .m files. Go to New>Script or
click on the New script icon in the toolbar to open a new editable file. The file must
be saved before it can be run. MATLAB does not allow spaces in the file names,
however underscore can be used in both file names and variable names in MATLAB.
 If one instruction is too long, it can be divided into smaller parts by writing … at the
end of one line and continuing the instruction in the next.
 % sign is used for comments in MATLAB. You can choose Right click>Comment
and Right click>Uncomment in order to comment and uncomment large parts of code
as well.

6
Spring 2019 ADC Lab 1 Version 1.0

Task 1 – Classification of Signals


 Open a new .m file and save it as Lab1_yourUETno_yourname.m e.g.
Lab1_123_Xyz.m. For future reference, all your .m files must be saved with the same
name format.

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

 Use %%%%%%%%%%%%%% Exercise 2 %%%%%%%%%%%%%%%%%%%%%%%%%% as a separator


in the same .m file and type the code for exercise 2 below it. For future reference, all
your exercise parts for a given task must be separated in the same way.
 Using the above code as an example, write a code to display a Discrete Time –
Continuous Value sinusoidal signal b. Define a variable n instead of t, with value
going from 1 to 20 with a step size of 1. Use frequency 0.1 for this signal, amplitude
5, and phase 0.
 Use the subplot command to choose a different part of the same figure window.
 stem(___) is used instead of plot(___) to display a discrete time signal.
 Write appropriate title and labels and then run the program.

Exercise 3

 Similar to Exercise 2, display a Continuous Time – Discrete Value sinusoidal signal c,


with frequency 1, amplitude 5 and phase 0, in a different part of the same figure
window. Note that this time the x axis will stay continuous, so plot will be used, but
the values of c will have to be discretized, so that only integer values remain.

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

ADC Lab 1 Rubric

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.

Excellent Good Satisfactory Unsatisfactory 3-1 Poor Marks


10 9-7 6-4 0 Obtained
Task All tasks completed Most tasks Some tasks completed Most tasks incomplete All tasks
Completion correctly in given time completed correctly correctly in given time or incorrect by the end incomplete or
(CLO2) in given time of lab session incorrect by the end
of lab session
Code Correct code, easily Correct code but Slightly incorrect code with Incorrect code with Code not submitted
(CLO2) understandable with without proper proper comments improper format and
comments where indentation or no comments
necessary comments
Output Output correctly Most Some Output/Figures/Plots Most of the required Output/Figures/Plot
(CLO2) shown with all Output/Figures/Plots displayed with proper labels Output/Figures/Plots s not displayed
Figures/Plots displayed with OR Most not displayed
displayed as required proper labels Output/Figures/Plots
and properly labelled displayed but without proper
labels
Lab Report Required document Required document Some correct/ meaningful Answers not Report/Hand-out
(CLO3) filled-in neatly with filled-in neatly with answers and conclusions understandable/ not not submitted
meaningful answers to meaningful answers with some irrelevant ones. relevant to questions.
all questions, proper to most questions, Some parts of the document Conclusions not based
grammar and and proper not neat or some grammar on results. Illegible
punctuation with conclusions drawn mistakes writing with no proper
proper conclusions with some grammar grammar/punctuation
drawn mistakes
Total

9
Version 1.0 – Zulaikha Kiran – 16/01/2019

Anda mungkin juga menyukai