0% found this document useful (0 votes)
10 views

DSP Lab Spring 25 Exp-01

The document is a laboratory manual for a Digital Signal Processing (DSP) lab course at the National University of Computer and Emerging Sciences, Islamabad. It covers learning objectives related to MATLAB, signal processing concepts, and basic operations on sequences, along with exercises for practical application. The manual includes detailed instructions on MATLAB commands, functions, and examples for generating and manipulating digital signals.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

DSP Lab Spring 25 Exp-01

The document is a laboratory manual for a Digital Signal Processing (DSP) lab course at the National University of Computer and Emerging Sciences, Islamabad. It covers learning objectives related to MATLAB, signal processing concepts, and basic operations on sequences, along with exercises for practical application. The manual includes detailed instructions on MATLAB commands, functions, and examples for generating and manipulating digital signals.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

DIGITAL SIGNAL PROCESSING LAB

(EL-3031)
LABORATORY MANUAL

QUICK REVIEW-SIGNALS & SYSTEMS(MATLAB)


(LAB # 01)
Student Name: ______________________________________________

Roll No: ________________ Section: ____

Date performed: _____________, 2025

____________________________________________________________________________________________________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Muhammad Asim


Last Edited by: Engr. Muhammad Asim, Jan 12, 2016
Verified by: Dr. Shahzad Saleem, Dr. Farhan Khalid Updated: Spring 2023
DSP - Lab National University Roll No: __________
01

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

Digital Signal Processing:

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.

Figure 1 : Block Diagram of Signal Processing

_____________________________________________________________________________________________
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:

MATLAB is a powerful high-level programming language for scientific computations. It is very


easy to learn and use in solving numerically complex engineering problems.
MATLAB consists of functions that are either built into the interpreter or available as M-files,
with each containing a sequence of program statements that execute a certain algorithm. A
completely new algorithm can be written as a program containing only a few of these functions
and can be saved as another M-file.
MATLAB works with three types of windows on your computer screen. These are the Command
window, the Figure window and the Editor window. The Command window has the heading
Command, the Figure window has the heading Figure No. 1, and the Editor window has the
heading showing the name of an opened existing M-file or Untitled if it is a new M-file under
construction. The Command window also shows the prompt >> indicating it is ready to execute
MATLAB commands. Results of most printing commands are displayed in the Command
window. This window can also be used to run small programs and saved M-files. All plots
generated by the plotting commands appear in a Figure window.
Either new M-files or old M-files are run from the Command window. Existing M-files can also be
run from the Command window by typing the name of the file. In addition to these windows there
are also workspace and history windows. Workspace
Basic Commands and Functions in Matlab:
i. To add comment, use "%" symbol.
ii. Help is provided by typing “help” or if you know the topic then “help
function_name”.
iii. If you don't know the exact name of the topic or command you are looking for,
type "lookfor keyword" (e.g., "lookfor regression")
iv. Three dots “...” are used to continue a statement to next line (row).
v. If after a statement “;” is entered then MATLAB will not display the result of the
statement entered otherwise result would be displayed.
vi. Use the up-arrow to recall commands without retyping them (and down arrow to

_____________________________________________________________________________________________
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”

viii. Defining Column vector v = [1;2;3]

ix. Defining a row vector w = [1 0 1]

x. Transpose a vector W = w’

xi. Defining a range for a vector X = 1:.5:5

xii. Empty vector Y = []

xiii. Defining a matrix M = [1 2 3; 3 2 1]

xiv. Zero matrix M = zeros(2,3) % 1st parameter is row, 2nd parameter is col.

xv. Ones matrix m = ones(2,3)

xvi. The identity matrix I = eye(3)

xvii. Define a random matrix or vector R = rand(1,3)

xviii. Access a vector or matrix R(3) ans =0.6068 or R(1,2) ans =0.2311

xix. Access a row or column of matrix

I(2,:) %2nd row


I(:,2) %2nd col
I(1:2,1:2)

xx. Size and Length size(I) , length(I)


xxi. Already defined variable by a user who
xxii. MATLAB utilizes the following arithmetic operatops;
+ Addition
- Subtraction
* Multiplication
/ Division
./ , .* Point by Point Mult. & Div.
^ Power Operator
‘ Transpose
xxiii. To control the flow of commands, the makers of MATLAB supplied four devices a
programmer can use while writing his/her computer code
_____________________________________________________________________________________________
Page 4 of 11
DSP - Lab National University Roll No: __________
01

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________

• the while loops


• the for loops
• the if-else-end constructions
• the switch-case constructions

Syntax of the for loop is


for k = array
commands
end
The commands between the for and end statements are executed for all values stored in
the array. The for loops can be nested
Syntax of the while loop is
while expression statements
end
This loop is used when the programmer does not know the number of repetitions a priori.

Syntax of the construction is


if expression1
commands (evaluated if expression 1 is true)
elseif expression 2
commands (evaluated if expression 2 is true) elseif

...

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

Creating functions using m-files

_____________________________________________________________________________________________
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

function [x,n] = imseq(n0,n1,n2)


n = [n1:n2]; x = [(n-n0) == 0];

2) Unit Step Sequence


The unit step, denoted by u(n), is defined by
_____________________________________________________________________________________________
Page 7 of 11
DSP - Lab National University Roll No: __________
01

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2025
_____________________________________________________________________________________

function [x,n] = stepseq(n0,n1,n2)

n = [n1: n2]; x = [(n-n0) >= 0];

3) Exponential Sequence
An exponential sequence is defined by

n = [0:10]; x = (0.9).^n

4) Complex Exponential Sequence


A complex exponential sequence is defined by

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) ;

Basic Operations on Sequences


a. Signal addition
It is implemented in MATLAB by the arithmetic operator “+”. However the lengths of

x1(n) and x2(n) must be the same. We can use the following function for addition

function [y,n] = sigadd(x1,n1,x2,n2)

_____________________________________________________________________________________________
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

different lengths we can use the following function

function [y,n] = sigmult(x1,n1,x2,n2) %

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;

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#4: Write a Matlab code that generate Exponential Function.

Task#5: Write a Matlab code that generate sinusoidal 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

You might also like