DSP Lab Manual
DSP Lab Manual
DSP Lab Manual
COMMUNICATION ENGINGEERING
COURSE FILE
LAB MANUAL
V SEM ECE
SESSION: 2021-22
PREPARED BY:-
POOJA KUMARI
Asst. Professor
ACEIT, Jaipur
LIST OF EXPERIMENTS
5EC4-22: Digital Signal Processing Lab
MM 75
S.no NAME OF EXPERIMENT Mapping
. with CO
2. Introduction to MATLAB CO 1
COURSE OBJECTIVE
1 . To understand MATLAB
COURSE OUTCOMES
After completion of this course, students will be able to –
CO 2 Sketch the magnitude and phase response of DFT, Inverse DFT and FFT
of discrete time signals.
Calculate linear and circular convolution of discrete sequences and
CO 3
generate random sequences.
INTERNAL: 45 Marks
EXTERNAL: 30 Marks
For assessment of work done during mid semester the Internal marks (60% component) is to
be distributed under the following heads:
ALWAYS
Enter the lab on time and leave at proper time.
Wait for the previous class to leave before the next class enters.
Keep the bag outside in the respective racks.
Utilize lab hours in the corresponding.
Turn off the machine before leaving the lab unless a member of lab staff has
specifically told you not to do so.
Leave the labs at least as nice as you found them.
If you notice a problem with a piece of equipment (e.g. a computer doesn't respond)
or the room in general (e.g. cooling, heating, lighting) please report it to lab staff
immediately. Do not attempt to fix the problem yourself.
NEVER
Don't abuse the equipment.
Do not adjust the heat or air conditioners. If you feel the temperature is not properly
set, inform lab staff; we will attempt to maintain a balance that is healthy for people
and machines.
Do not attempt to reboot a computer. Report problems to lab staff.
Do not remove or modify any software or file without permission.
Do not remove printers and machines from the network without being explicitly told
to do so by lab staff.
Don't monopolize equipment. If you're going to be away from your machine for more
than 10 or 15 minutes, log out before leaving. This is both for the security of your
account, and to ensure that others are able to use the lab resources while you are not.
Don’t use internet, internet chat of any kind in your regular lab schedule.
Do not download or upload of MP3, JPG or MPEG files.
No games are allowed in the lab sessions.
No hardware including USB drives can be connected or disconnected in the labs
without prior permission of the lab in-charge.
No food or drink is allowed in the lab or near any of the equipment. Aside from the
fact that it leaves a mess and attracts pests, spilling anything on a keyboard or other
piece of computer equipment could cause permanent, irreparable, and costly damage.
(and in fact has) If you need to eat or drink, take a break and do so in the canteen.
Don’t bring any external material in the lab, except your lab record, copy and books.
Don’t bring the mobile phones in the lab. If necessary then keep them in silence
mode.
Please be considerate of those around you, especially in terms of noise level. While
labs are a natural place for conversations of all types, kindly keep the volume turned
down.
If you are having problems or questions, please go to either the faculty, lab in-charge or the
lab supporting staff. They will help you. We need your full support and cooperation for
smooth functioning of the lab.
All the students are supposed to prepare the theory regarding the next experiment.
Students are supposed to bring the practical file and the lab copy.
Previous programs should be written in the practical file.
All the students must follow the instructions, failing which he/she may not be allowed
in the lab.
WHILE WORKING IN THE LAB
REQUIREMENTS:-
SOFTWARE: MATLAB (Version: 7.7.0 R2008b)
MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. It allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program
in a scalar non-interactive language such as C or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the
state of the art in software for matrix computation.
MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses in
mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-
productivity research, development, and analysis.
This part of MATLAB is the set of tools and facilities that help you use and become more
productive with MATLAB functions and files. Many of these tools are graphical user
interfaces. It includes: the MATLAB desktop and Command Window, an editor and
debugger, a code analyzer, browsers for viewing help, the workspace, and files, and other
tools.
3. The Language
The MATLAB language is a high-level matrix/array language with control flow statements,
functions, data structures, input/output, and object-oriented programming features. It allows
both "programming in the small" to rapidly create quick programs you do not intend to reuse.
You can also do "programming in the large" to create complex application programs intended
for reuse.
4. Graphics
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics.
It also includes low-level functions that allow you to fully customize the appearance of
graphics as well as to build complete graphical user interfaces on your MATLAB
applications.
5. External Interfaces
The external interfaces library allows you to write C and Fortran programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), for
calling MATLAB as a computational engine, and for reading and writing MAT-files.
How to Start MATLAB?
MATLAB ICON
Current
Directory Command Window Workspace
Command
History
REQUIREMENTS:-
PROGRAM:
(a) Code for plotting of Continuous periodic Sinusoidal function -
x=0:0.05:7
y= sin(x)
plot(x,y)
Title ('Graph of Continuous Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
x=0:0.05:7
y= sin(x)
stem(x,y)
Title ('Graph of Discrete Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
x=0:0.05:7
y= log(x)
plot(x,y)
Title('Graph of Continuous Log Function ')
xlabel('Time')
ylabel('Amplitude')
x=0:0.05:7
y= log(x)
stem(x,y)
Title ('Graph of Discrete Log Function ')
xlabel ('Time')
ylabel ('Amplitude')
OUTPUT RESULTS:
Graph of Continuous Sin Function
1
0.8
0.6
0.4
0.2
Amplitude
0
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
Time
0.8
0.6
0.4
0.2
A m plitude
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
Time
1.5
0.5
A m p lit u d e
-0.5
-1
-1.5
-2
-2.5
-3
0 1 2 3 4 5 6 7
Time
1.5
0.5
0
A m p litu d e
-0.5
-1
-1.5
-2
-2.5
-3
0 1 2 3 4 5 6 7
VIVA-QUESTIONS:
PROGRAM:
(A) Code for plotting of Continuous Unit Step signal-
x= -3:1:3
y= [zeros(1,3), ones(1,4)]
plot(x,y)
Title(‘Plot of Continuous Unit Step Siganl’)
xlabel(‘Time’)
ylabel(‘Amplitude’)
x= -3:1:3
y= [zeros(1,3), ones(1,4)]
stem(x,y)
title(‘Plot of Discrete Unit Step Siganl’)
xlabel(‘Time’)
ylabel(‘Amplitude’)
OUTPUT RESULTS :
Plot of Continuous Unit Step Siganl Plot of Discrete Unit Step Siganl
1 1
0.9 0.9
0.8 0.8
0.7 0.7
0.6 0.6
Amplitude
Amplitude
0.5 0.5
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
-3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3
Time Time
(a) Plot of Continuous Unit Step Signal (b) Plot of Continuous Unit Step Signal
RESULT: we have successfully generated Continuous and Discrete Unit Step Signal.
VIVA-QUESTIONS:
PROGRAM:
x=-3:0.1:3
y= exp(x)
plot(x,y)
Title ('Graph of Continuous Exponential Function')
xlabel ('Time')
ylabel ('Amplitude')
x=-3:0.1:3
y= exp(x)
stem(x,y)
Title ('Graph of Discrete Exponential Function')
xlabel ('Time')
ylabel ('Amplitude')
x=0:0.05:10
y= (x)
plot(x,y)
Title ('Graph of Continuous Ramp Function ')
xlabel ('Time')
ylabel ('Amplitude')
x=0:0.05:10
y= (x)
stem(x,y)
Title ('Graph of Discrete Ramp Function ')
xlabel ('Time')
ylabel ('Amplitude')
OUTPUT RESULTS : 25
Graph of Discrete Exponential Function
20
20
15
Amplitude
15
Amplitude
10
10
0
-3 -2 -1 0 1 2 3
0 Time
-3 -2 -1 0 1 2 3
Time
9
8
8
7
7
6
Amplitude
6
5
Amplitude
5
4
4
3
3
2
2
1
(b)
1
0
0 1 2 3 4 5 6 7 8 9 10
Time
0
0 1 2 3 4 5 6 7 8 9 10
Time
RESULT: we have successfully generated Continuous and Discrete Exponential and Ramp
signals.
VIVA-QUESTIONS:
1. Define Ramp signal.
2. How can you obtain ramp signal from unit step signal?
PROGRAM:
Code for plotting of Addition of two Continuous signals -
t=0:0.05:10
x= sin(t)
y= cos(t)
a= x+y
s= x-y
subplot(4,1,1)
plot(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,2)
plot(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,3)
plot(a)
Title ('Graph of Addition between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,4)
plot(s)
Title ('Graph of Subtraction between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')
# Code for plotting of Addition of two Discrete signals - Just replace plot command with
Stem command in above program
OUTPUT RESULTS:
-1
0 50 100 150 200 250
Time
Graph of Cos Function
1
Amplitude
-1
0 50 100 150 200 250
Time
Graph of Addition between Sin and Cos
2
Amplitude
-2
0 50 100 150 200 250
Time
Graph of Subtraction between Sin and Cos
2
Amplitude
-2
0 50 100 150 200 250
Time
VIVA-QUESTIONS:
1. What is signal?
2. What is system?
PROGRAM:
Code for plotting of Continuous Convolution -
t=0:0.05:10
x= sin(t)
y= cos(t)
z= conv(x,y)
subplot(3,1,1)
plot(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,2)
plot(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,3)
plot(z)
Title ('Graph of Convolution between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')
t=0:0.05:10
x= sin(t)
y= cos(t)
z= conv(x,y)
subplot(3,1,1)
stem(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,2)
stem(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,3)
stem(z)
Title ('Graph of Convolution between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')
OUTPUT RESULTS:
0.5
Amplitude
-0.5
-1
0 50 100 150 200 250
Time
Graph of Cos Function
1
0.5
Amplitude
-0.5
-1
0 50 100 150 200 250
Time
Graph of Convolution between Sin and Cos
100
50
Amplitude
-50
-100
0 50 100 150 200 250 300 350 400 450
Time
0.5
Amplitude
-0.5
-1
0 50 100 150 200 250
Time
Graph of Cos Function
1
0.5
Amplitude
-0.5
-1
0 50 100 150 200 250
Time
Graph of Convolution between Sin and Cos
100
50
Amplitude
-50
-100
0 50 100 150 200 250 300 350 400 450
Time
VIVA-QUESTIONS:
PROGRAM:
Code to generate uniform random numbers -
m= input(‘m=’)
n= input(‘n=’)
rand(m,n)
OUTPUT RESULT:
m= 2 (press enter)
n= 2 (press enter)
ans =
0.8147 0.1270
0.9058 0.9134
A 2*2 Matrix containing random nos. between 0 and 1 will be displayed as output.
VIVA-QUESTIONS:
1. Explain different properties of system.
2.What do you mean by statement subplot (3,3,1).
3.What is the difference between linear and circular convolution?
EXPERIMENT NO. 8
AIM: To generate random sequences with arbitrary distributions, means and variances for
following :
PROGRAM:
Code #
(A) B= input(‘B=’)
m= input(‘m=’)
n= input(‘n=’)
R = raylrnd(B,m,n)
sigma= input(‘sigma=’)
m= input(‘m=’)
n= input(‘n=’)
R = normrnd(mu,sigma,m,n)
(D) m= input(‘m=’)
n= input(‘n=’)
rand(m,n)
OUTPUT RESULT:
When code is RUN, on command window we will see-
B=
100
m= 5
n=? (After entering 5)
n=
5
mu =
0
sigma =
1
m=
5
n=
5
m= 2 (press enter)
n= 2 (press enter)
ans =
0.8147 0.1270
0.9058 0.9134
VIVA-QUESTIONS:
6. What do you mean aliasing? What is the condition to avoid aliasing for sampling?
EXPERIMENT NO. 9
AIM : To develop program for computing discrete Fourier Transform (DFT) and inverse
discrete Fourier Transform (IDFT).
PROGRAM :
DFT :
%prog for computing discrete Fourier Transform
clc;clear all;close all;
x =input('Enter the sequence '); %x =[0 1 2 3 4 5 6 7]
n = input('Enter the length of Fourier Transform ') %n =8 has to be same as
%the length of sequence
x =fft(x,n);
stem(x);
ylabel('imaginary axis------>');
xlabel('(real axis------>');
title('Exponential sequence');
disp('DFT is');x
IDFT :
% prog for inverse discrete Fourier Transform (IDFT)
clc;clear all;close all;
x =input('Enter length of DFT '); % for best results in power of 2
t = 0:pi/x:pi;
num =[0.05 0.033 0.008];
den =[0.06 4 1];
trans = tf(num,den);
[freq,w] =freqz(num,den,x); grid on;
subplot(2,1,1);plot(abs(freq),'k');
disp(abs(freq));
ylabel('Magnitude');
xlabel('Frequency index');
title('magnitude response');
OUTPUT :
DFT :
IDFT :
GRAPH:
DFT :
Discrete Fourier Transform
10
6
Im a gina ry ax is ------>
-2
-4
-6
-8
-10
1 2 3 4 5 6 7 8
Real axis------>
IDFT:
Magnitude Response
0.02
M a g n it u d e
0.015
0.01
0.005
1 1.5 2 2.5 3 3.5 4
Frequency index
RESULT: We have successfully computed discrete Fourier Transform (DFT) and inverse
discrete Fourier Transform (IDFT).
EXPERIMENT NO. 10
AIM : To develop program for computing circular convolution.
PROGRAM :
%prog for computing circular convolution of sequence
% g =[1 -3 4 2 0 -2] and h =[3 0 1 -1 2 1]
clc;clear all;close all;
g =[1 -3 4 2 0 -2];
h =[3 0 1 -1 2 1];
for i = 1:6,
y(i) =0;
for k = 1:6,
z =mod(6-k+i,6)+1;
y(i)=y(i)+g(z)*h(k);
end
end
disp('The resultant Signal is ');y
stem(y);
ylabel('Amplitude------>');
xlabel('n------>');
title('Circular Convolution');
OUTPUT :
The resultant Signal is y = 6 -3 17 -2 7 -13
GRAPH:
Circular Convolution
20
15
10
A m p litu d e ------>
-5
-10
-15
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n------>
z tranform of 1+n
z/(z - 1) + z/(z - 1)^2
Output :
R = 0.2500
0.5000
0.2500
p = 0.9000
0.9000
-0.9000
C = []
delta = 1 0 0 0 0 0 0 0
n= 0 1 2 3 4 5 6 7
PROGRAM :
%prog for designing of FIR low pass
% filters using rectangular window
clc;clear all;close all;
rp =input('Enter the pass band ripple ');
rs =input('Enter the stop band ripple ');
fp =input('Enter the pass band freq ');
fs =input('Enter the stop band freq ');
f =input('Enter the sampling freq ');
wp = 2*fp/f;
ws = 2*fs/f;
num = -20*log10(sqrt(rp*rs))-13;
dem = 14.6*(fs-fp)/f;
n = ceil(num/dem);
n1 = n+1;
if (rem(n,2)~=0)
n1 =n;
n = n-1;
end
y = boxcar(n1);
% low pass filter
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256);
m = 20*log(abs(h));
subplot(2,2,1);plot(o/pi,m);
ylabel('Gain in dB ------>');
xlabel('(a) Normalised freq ---->');
OUTPUT :
Enter the pass band ripple 0.05
Enter the stop band ripple 0.04
Enter the pass band freq 1500
Enter the stop band freq 2000
Enter the sampling freq 9000
GRAPH:
G a in in d B ------>
100
-100
-200
0 0.5 1
(a) Normalised freq ---->
PROGRAM :
OUTPUT :
Enter the pass band ripple 0.5
Enter the stop band ripple 50
Enter the pass band freq 1200
Enter the stop band freq 2400
Enter the sampling freq 10000
GRAPH:
-500
-1000
0 0.5 1
(a) Normalised freq ---->
4
Phase in Radians ------>
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised freq ---->