DSP Lab Spring 25 Exp-01
DSP Lab Spring 25 Exp-01
(EL-3031)
LABORATORY MANUAL
____________________________________________________________________________________________________________________________________________________________
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
Lab # 01: QUICK REVIEW-SIGNAL & SYSTEMS (MATLAB)
Learning Objectives:
1. Introduction to Digital Signal Processing
2. Quick Review to MATLAB
3. Plots in Time and Frequency Domain
4. Basic Sequence Generation and Basic Operations on Basic Functions
5. Sequence Generation from Continuous Time Signals (Sampling)
Equipment Required:
1. PC
2. MATLAB
A signal is a physical quantity that is usually a function of time, position, pressure, etc. For
example, the voltage output from a microphone represents sound pressure as a function of time.
Signals that we encounter frequently in our daily life include speech, music, data, images, video
signals. The objective of signal processing is to transmit or store signals, to enhance desired signal
components, and to extract useful information carried by the signals.
Signal Processing is a method of extracting information from the signal which in turn depends on
the type of signal and the nature of information it carries.
_____________________________________________________________________________________________
Page 2 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
Digital signal processing is concerned with the digital representation of signals and use of digital
processors to analyze, modify or extract information from signals. Most signals in nature are
analog. Analog signals are varying with time, and represent the variations of physical quantities
such as sound waves. The signals used in most popular forms of DSP are derived from analog
signals which have been sampled at regular intervals and converted into digital form. The specific
mean for processing a digital signal may be, for example, to remove interference of noise from the
signal, to obtain the spectrum of the data or to transform the signal from the signal in to more
suitable form. DSP is now used in many areas where analog methods were previously used and in
entirely new applications which were difficult with analog methods. Basic building block of
digital signal processing is shown in Figure 1.
MATLAB Review:
_____________________________________________________________________________________________
Page 3 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
go forward in commands).
vii. MATLAB is case sensitive so “taxila” is not same as “TAXILA”
x. Transpose a vector W = w’
xiv. Zero matrix M = zeros(2,3) % 1st parameter is row, 2nd parameter is col.
xviii. Access a vector or matrix R(3) ans =0.6068 or R(1,2) ans =0.2311
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
else
commands (executed if all previous expressions evaluate to false)
end
Syntax of the switch-case construction is
switch expression (scalar or string)
case value1 (executes if expression evaluates to value1)
commands
_____________________________________________________________________________________________
Page 5 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
case value2 (executes if expression evaluates to value2)
commands
...
otherwise
statements
end
Note: use of the curly braces after the word case. This creates the so called cell array
rather than the one-dimensional array, which requires use of the square brackets.
xxiv. Some built in functions in MATLAB
abs magnitude of a number (absolute value for real
numbers)
angle angle of a complex number, in radians
b)
cos cosine function, assumes argument is in radians
sin sine function, assumes argument is in radians
exp exponential function
log logrithmic function, operates on each point of a column
round round off the decimal numbers
sum calculates the sum of a vector
mean calculates mean of the vector
std calculates standard deviation of the vector
max finds the maximum value in a vector
min finds the minimum value in a vector
_____________________________________________________________________________________________
Page 6 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
There are two kinds of m-files: the script files and the function files. Script files do not take the
input arguments or return the output arguments. The function files may take input arguments
or return output arguments. To make the m-file click on File next select New and click on M-
File from the pull-down menu. You will be presented with the MATLAB Editor/Debugger
screen. Here you will type your code, can make changes, etc. Once you are done with typing,
click on File, in the MATLAB Editor/Debugger screen and select Save As… . Chose a name
for your file, e.g., firstgraph.m and click on Save. Make sure that your file is saved in the
directory that is in MATLAB's search path. If you have at least two files with duplicated
names, then the one that occurs first in MATLAB's search path will be executed.
To open the m-file from within the Command Window type edit filename and then press Enter
or Return key.
Here is an example of a function file
function [b, j] = descsort(a)
This function call be called from command line as
descsort(X)
Plots in Time and Frequency Domain
• Type help to see the function of following commands
plot , stem , stair , xlabel , ylabel , title , axis , figure , subplot , legend
• Following are the commands for frequency domain poltting
freqz ‘finds the DTFT from the transfer function z-domain’
pzmap ‘plots poles and zeros of transfer function on x and y axis’
zpalne ‘plots poles and zeros of transfer function on zplane’
Basic Sequence Generation
1) Unit Sample Sequence
The unit sample is defined by
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
3) Exponential Sequence
An exponential sequence is defined by
n = [0:10]; x = (0.9).^n
n = [0:10]; x = exp((2+3j)*n)
5) Sinusoidal Sequence
A sinusoid sequence is defined by
n = [0:10]; x = 3*cos(0.1*pi*n+pi/3) ;
x1(n) and x2(n) must be the same. We can use the following function for addition
_____________________________________________________________________________________________
Page 8 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
% y(n) = x1(n) + x2(n)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = y1 + y2;
b. Signal multiplication
It is implemented in MATLAB by the array operator “.*”. To multiply sequences of
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y = y1 .* y2;
c. Shifting
In this operation each sample of x(n) is shifted by an amount k to obtain a shifted
sequence y(n)
Y(n) = {x(n-k)}
If we let m=n-k, then n=m+k and the above operation is given by
Y(m+k) = {x(m)}
For this we can use the following function
function [y,n] = sigshift(x,m,n0)
% y(n) = x(n-n0)
n = m+n0; y = x;
_____________________________________________________________________________________________
Page 9 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
d. Folding
In this operation each sample of x(n) is fipped around n=0 to obtain a folded sequence y(n)
Y(n) = {x(-n)}
For this the following function is shown function [y,n] = sigfold(x,n)
% y(n) = x(-n)
y = fliplr(x); n= -fliplr(n);
Exercise:
Task#1 :Write a generic Matlab code that generates delayed (shifted) Unit Impulse function.
Task#2: Write a generic Matlab code that generates delayed (shifted) Unit step function.
Task#3: Write a generic Matlab code that generate delayed (shifted) Unit ramp function.
Task#6:
a. Z(n) = 2δ(n+2) – δ(n-4), -5 ≤ n ≤ 5
b. X(n) = n[u(n)-u(n-10)] + 10 e-0.3(n-10)[u(n-10) – u(n-20)], 0 ≤ n ≤ 20
Task#7: Let x(n) = {1,2,3,4, 5, 6, 7, 6, 5, 4, 3, 2, 1}, Determine and plot the following
sequences.
a. x1(n) = 2x(n-5) – 3x(n+4)
b. x2(n) = x(3-n) + x(n)x(n-2)
_____________________________________________________________________________________________
Page 10 of 11
DSP - Lab National University Roll No: __________
01
Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________
Assessment Rubric
LLO Statement Assessment Exemplary Proficient Developing Beginning Worst
Method (20%) (20%) (20%) (20%) Performance
(20%)
1 Analysis of Practical Skill Able to attempt Able to attempt Able to attempt Able to attempt Able to attempt
discrete-time Observation complete lab with 80% of the lab 60% of the lab 40% of the lab 20% of the lab
signals and during proper tasks tasks tasks tasks
verifying their experimentati labeling/explanatio
properties i.e. on & Lab n of results and
Discrete Fourier Reports proper commenting
Transform of the code
(DFT), Discrete
Time Fourier
Transform
(DTFT) using
MATLAB.
_____________________________________________________________________________________________
Page 11 of 11