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

DSP Lab Spring 24 Exp-02

The document is a laboratory manual for a Digital Signal Processing course, detailing Lab #02 which covers basic concepts such as relative error, circular shift, sampling, and sampling rate alteration. It includes learning objectives, required equipment, tasks for students to complete using MATLAB, and a feedback section for student evaluation. The manual is prepared and verified by faculty members at the National University of Computer and Emerging Sciences, Islamabad.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DSP Lab Spring 24 Exp-02

The document is a laboratory manual for a Digital Signal Processing course, detailing Lab #02 which covers basic concepts such as relative error, circular shift, sampling, and sampling rate alteration. It includes learning objectives, required equipment, tasks for students to complete using MATLAB, and a feedback section for student evaluation. The manual is prepared and verified by faculty members at the National University of Computer and Emerging Sciences, Islamabad.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DIGITAL SIGNAL PROCESSING LAB

(EL-3031)
LABORATORY MANUAL

BASIC CONCEPTS OF DIGITAL SIGNAL PROCESSING

(LAB # 02)
Student Name: ______________________________________________

Roll No: ________________ Section: ____

Date performed: _____________, 2024

____________________________________________________________________________________________________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Muhammad Asim


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

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2024
_____________________________________________________________________________________
Lab # 02: BASIC CONCEPTS OF DIGITAL SIGNAL PROCESSING
Learning Objectives
A. Relative Error
B. Circular Shift and Circular Time Reversal
C. Sequence Generation from Continuous Time Signals (Sampling)
D. Sampling Rate Alteration

Equipment Required
1. PC
2. MATLAB

Relative Error
Whenever a signal/sequence is corrupted by some noise then it is important to find the
difference between the original signal and the corrupted signal and this normalized
difference is called relative error. Relative error is defined as the ratio of the L2−norm of
the difference signal and the L2−norm of original signal {x [n]}.
Erel =¿ ¿
Where { y [n ]} is the corrupted sequence and {x [n]} is the original sequence.

Task 01:
1. Generate a sinusoidal sequence x [ n ] =sin ⁡(0.5∗pi∗n) −10< n≤ 10
2. Add noise to the above signal using command “awgn” to generate a signal y [ n ] . You can
use ‘help awgn’.
3. Find Relative error Erel using the above given formula.
4. Plot in time domain using ‘stem’.

Task 02:
1. Find frequency response of x [ n ] ∧ y [ n ] of Task 01 and plot these response with
respect to normalized digital angular frequency ω .
2. Use the ‘freqz’ command to find the frequency response.

Circular Shift and Time Reversal


Circular shift is different form linear shift. In case of infinite length sequence, linear shift
can be used bcause our samples are infinite and appended zeros istead of a samples may
not effect the operations. But in case of finite length sequences, it is mandatory to use such
a shifting operation such that our samples are not lost. To do this we use modulo operation.

Modulo Operation:
_____________________________________________________________________________________________
Page 2 of 7
DSP - Lab National University Roll No: __________
02

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2024
_____________________________________________________________________________________
Let 0,1,………. N-1 be a set of N positive integers and let m be any integer. The integer r
obtained by evaluating m modulo N is called the residue. The residue r is an integer with a
value between 0 and N-1.
Circular Time Reversal:
The circular time-reversal version {y[n]} of a length-N sequence {x[n]} defined for
N−1 ≤ n ≤ 0 is given by { y [ n ] }={ x [ ⟨−n ⟩N ]} .
Circular Shift:
Let x[n] be a length-N sequence defined for N−1 ≤ n ≤ 0. Its circularly shifted version
x c [n] shifted by n0 samples is given by
{ x c [ n ] }={x [ ⟨ n−n0 ⟩ N ]}
Task 03:
1. Generate and plot the following exponential sequence
x [ n ] =0.5 ,−3< n ≤10
n

2. Find and plot the following


 x 1 [ n ]= x [n+ 2]
 x 2 [ n ] =x [ ⟨ n+2 ⟩ N ]
 x 3 [ n ] =x [−n]
 x 4 [ n ] =x [ ⟨−n ⟩ N ]
Task 04:
1. Write a generic matlab function for circular shift
2. Write a generic matlab function for circular time reversal.

Sequence Generation from Continuous Time Signals (Sampling)


In signal processing, sampling is the reduction of a continuous signal to a discrete
signal. A common example is the conversion of a sound wave (a continuous signal) to a
sequence of samples (a discrete-time signal). A sample is a value or set of values at a point
in time and/or space. A sampler is a subsystem or operation that extracts samples from
a continuous signal.

clc, clear;
f=1/4; % Frequency in Hz
Dt=0.01;
t=0:Dt:12; % sec
y_t = sin(2*pi*f*t);

%% Oversampling
%y_n=y_t(1:1/((2*f/Fs)*Dt):end);
fs=4*f;Ts1=1/fs;
n1=t(1)/Ts1:1:t(end)/Ts1;
y_n1=sin(2*pi*f*n1*Ts1);

_____________________________________________________________________________________________
Page 3 of 7
DSP - Lab National University Roll No: __________
02

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2024
_____________________________________________________________________________________
%% Under sampling
fs=1.5*f;Ts2=1/fs;
n2=t(1)/Ts2:1:t(end)/Ts2;
y_n2=sin(2*pi*f*n2*Ts2);
%n=0:1/(2*f/Fs):12;

%% plotting in time domain %%%%%%%%%%


subplot(2,3,1)
plot (t,y_t)
title('CT Plot of Sinusoidal signal');
xlabel('Time t');ylabel('CT Signal y(t)');grid on;
subplot(2,3,2)
stem (n1*Ts1,y_n1); hold on
plot (t,y_t,'g')
title('DT PlotT Oversampled');
xlabel('Time t');ylabel('DT Signal');grid on;
subplot(2,3,3)
stem (n2*Ts2,y_n2); hold on
plot (t,y_t,'g')
title('DT PlotT Undersampled');
xlabel('Time t');ylabel('DT Signal');grid on;

%% Computing frequency response of y_n and plotting %%%%%%%%%%


subplot(2,3,4)
[Y_n,omega_n] = freqz(y_n1);
plot(omega_n,(abs(Y_n))), xlim([0 pi])
title('Oversampled sinusoidal signal in frequency domain')
xlabel('Normalized Angular Frequency, \omega (rad/sample)')
ylabel('Magnitude Spectrum |Y(\omega)|')
grid on
subplot(2,3,5)
[Y_n,omega_n] = freqz(y_n2);
plot(omega_n,(abs(Y_n))), xlim([0 pi])
title('Undersampled sinusoidal signal in frequency domain')
xlabel('Normalized Angular Frequency, \omega (rad/sample)')
ylabel('Magnitude Spectrum |Y(\omega)|')
grid on

Task 05:
Generate a multi-tone sinusoidal signal with f 1=2000Hz and f2=4000Hz, then by sampling
generate the Oversampled and Undersampled version of it and display the frequency
response also.

Sampling Rate Altertaion


If we want to generate a new sequence from x [ n ] with a different sampling rate F’T higher
or lower than the samling rate FT of original sequence x [ n ] then sampling alteration ratio is
'
FT
given by R= . Now If R>1 then it is called interpolation (Upsampling) and if R<1 then
FT
it is called decimation or downsampling. Generally we mostly append zeros in case of up
sampling.
_____________________________________________________________________________________________
Page 4 of 7
DSP - Lab National University Roll No: __________
02

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

Task 06:
1. Generate and plot the follwing sinusoidal sequence
x [ n ] =sin ⁡(2∗pi∗0.25∗n) −15< n≤ 20
2. Generate and plot x 1 [ n ] by upsampling the above sequence x [ n ] by 3.
3. Generate and plot x 2 [ n ] by downsampling the above sequence x [ n ] by 3.
4. Help: Use ‘upsample’ and ‘downsample ’commands
5. Now, generate and plot x 3 [ n ] by upsampling x 2 [ n ] by 3.
6. Now, generate and plot x 4 [ n ] by downsampling x 1 [ n ] by 3.
Question
Are x 3 [ n ] and x [ n ] similar? If Yes/No then Why?
Question
Are x 4 [ n ] and x [ n ] similar? If Yes/No the Why?

Task 07 (Bonus Task):


1. Write your own matlab function for upsampling and downsampling.

_____________________________________________________________________________________________
Page 5 of 7
DSP - Lab National University Roll No: __________
02

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2024
_____________________________________________________________________________________
Student's feedback: Purpose of feedback is to know the strengths and weaknesses of the system
for future improvements. This feedback is for the 'current lab session'. Circle your choice:

[-3 = Extremely Poor, -2 = Very Poor, -1 = Poor, 0 = Average, 1 = Good, 2 = Very Good, 3 = Excellent]:
The following table should describe your experience with:
S# Field Rating Describe in words if required
1 Overall Session -
-2 -1 0 1 2 3
3
2 Lab Instructor -
-2 -1 0 1 2 3
3
3 Lab Staff -
-2 -1 0 1 2 3
3
4 Equipment -
-2 -1 0 1 2 3
3
5 Atmosphere -
-2 -1 0 1 2 3
3

Any other valuable feedback: ______________________________________________________


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Student's Signature: _________________________________


AWARDED

Correctness

Conclusion
Originality
of results

Initiative
Neatness
MARKS

Attitude

TOTAL

TOTAL 10 10 10 20 20 30 100

EARNED

Lab Instructor's Comments:________________________________________________________


______________________________________________________________________________

_____________________________________________________________________________________________
Page 6 of 7
DSP - Lab National University Roll No: __________
02

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

Lab Instructor's Signature: _________________________________

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 7 of 7

You might also like