You are on page 1of 3

ELCE 402 Digital Signal Processing Laboratory Introduction

Page 1

LABORATORY INSTRUCTION

ELCE 402: Digital Signal Processing Laboratory (DSPL)

Introduction to Matlab and DSPL

OBJECTIVES
To perform an overview of the Matlab tools and commands commonly used in the DSPL.
To perform an overview of the course (attendance, evaluation, reports, office hours, etc.)
NOTE: More preliminary information about Matlab can be found in Matlab_introduction.pdf file (it is
uploaded to Moodle).

MATLAB FOR SIGNAL PROCESSING OVERVIEW
The following summarises briefly some of the commonly used Matlab commands.

Help and utilities
Explanation of the utiility and usage of a Matlab function can be accessed by typing
help <name_of_function> (for example help size)
doc <name_of_function>, or
edit <name_of_function>
If everything fails, you can use why command to get instantaneous answer to your questions
Before proceeding with the exercises, create a script called myscript.m and type your code
therein.

Data generation and representation
An example of a real and complex number
x = 2.1; y = 2.1 + j*3.3;
Row vector (X) versus column vector (Y)
X = [1 4 6]; Y = X.;
An example of 2x3 matrix declaration
Y = [1 4 6; 5 6 9];
Indexing in Matlab starts from 1 (not from 0!) so, for example, in the matrix above Y(2,1) = 5.
Exemplary sinusoid generation
x = -pi:0.01:pi;
y = cos(x);
Other useful functions: real, imag, size, length, colon operator (:), ones,
zeros, eye, randn, clear, whos.
ELCE 402 Digital Signal Processing Laboratory Introduction
Page 2

Exercise: For a few selected functions above do the following: (1) find out how to use it; (2) Write an
exemplary application and examine the results. Use the example signals above as the argument of the
functions.
Example - function real: Type help real, read the documentation, generate a complex number
y (see above) and execute a command real(y). Comment on the result.

Arithmetic matrix operations
If X and Y are matrices of the same size addition, subtraction and element-by-element multiplication
or division can be performed as follows
X+Y, XY, X.*Y, X./Y
Matrix multiplication, X * Y requires that number of columns of X and rows of Y are the same
whereas matrix left division X\Y is used in Gaussian elimination.
Other useful operations: sum, *, ^, &, ||, <, >, ==

Exercise: Practice the use of the operations above in the same way as in the previous exercise, using
the vectors and matrices defined previously. Demonstrate the working examples to the lab instructor.

Graphics
Typically the signals processed in the laboratory will be 1-D or 2-D (images) and can be visualized in a
following way
figure, plot(x, y)
title(my plot), xlabel(x), ylabel(y),
or (in case of images)
figure, imagesc(Y)
Other useful functions: stem, bar, stairs, axis, subplot, grid, legend,
close all

Exercise: Plot any of the vectors and sinusoids from the previous exercises on the same figure. Attach
titles, labels and a legend explaining the plot contents. Make sure the plot is self-explanatory!

Functions* (Optional)
M-file can also contain a user defined function. In this case it has to begin with a function declaration
in a first line, for example
function y = arraymean(x)
% Computes the scalar mean of an array x
y = mean(x(:));
end


ELCE 402 Digital Signal Processing Laboratory Introduction
Page 3

Other useful commands: if, else, for, case, while, end

Exercise: Write a function that computes the energy of the signal. Test it on the signals defined
previously.

Publishing
Command publish provides a convenient way of documenting the experiments or simulations in
Matlab.
Exercise: Run command publish('myscript.m') and examine the results in the current
directory).

REFERENCES
[1] S.K. Mitra, Matlab Introduction (uploaded to Moodle)
[2] MATLAB online help http://www.mathworks.com/help/matlab/index.html

You might also like