JAYPEE UNIVERSITY OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
A PRACTICAL WORK BOOK
of
Digital Signal Processing Lab
(18B17EC473)
SUBMITTED
TO
Dr. Deepak Sharma
SUBMITTED
BY
SHOURAY SONI (221A021)
BATCH: - 2022-2026
SESSION: - 2024
I hereby declare that the contents of this practical book are my own work.
These are not taken from any other sources.
SHOURAY SONI (221A021)
EXPERIMENT 1
Exercise#1
(a) Generate a matrix of size 5x5 of normally distributed random numbers.
(b) Change the value of the 3rd row to [8 7 3 2 4].
(c) Delete the 2nd column
clc;
clear all;
% (a) Generate a matrix of size 5x5 of normally distributed random numbers
A = randn(5, 5);
% (b) Change the value of the 3rd row to [8 7 3 2 4]
A(3, :) = [8 7 3 2 4];
% (c) Delete the 2nd column
A(:, 2) = [];
% Display the resulting matrix
disp(A);
OUTPUT: -
(A)
-0.8494 0.2208 1.1588 -0.4247 0.2456
-0.8225 0.0610 1.0064 -1.2339 -0.3610
-1.3559 0.0254 -0.1951 0.8440 0.0375
-0.2126 -0.8056 -0.3244 -0.4661 -0.0508
-1.9061 1.3094 -1.5168 0.8603 1.1850 (C)
-1.1176 1.5270 -1.0298 0.2614
1.2607 0.4669 0.9492 -0.9415
8.0000 3.0000 2.0000 4.0000
-0.0679 0.6252 0.1352 -0.1461
(B)
-0.1952 0.1832 0.5152 -0.5320
-1.1176 -0.2176 1.5270 -1.0298
1.2607 -0.3031 0.4669 0.9492
8.0000 7.0000 3.0000 2.0000
-0.0679 0.0513 0.6252 0.1352
-0.1952 0.8261 0.1832 0.5152
Exercise-2
Start with the 4-by-4 square, A. (b) Then form B = [A A+32; A+48 A+16] (c) What’s the size of B? Also
find the size of B without semicolon (;).
clc;
clear all;
% (a) Start with the 4-by-4 square matrix A (using a magic square as an
example)
A = magic(4);
% (b) Form the matrix B = [A A+32; A+48 A+16]
B = [A A+32; A+48 A+16];
% (c) Find the size of B
size_of_B = size(B);
% Display the results
disp('Matrix B:');
disp(B);
disp('Size of B:');
disp(size_of_B);
A=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
B=
16 2 3 13 48 34 35 45
5 11 10 8 37 43 42 40
9 7 6 12 41 39 38 44
4 14 15 1 36 46 47 33
64 50 51 61 32 18 19 29
53 59 58 56 21 27 26 24
57 55 54 60 25 23 22 28
52 62 63 49 20 30 31 17
size_of_B =
8 8
clc;
clear all;
n1 = 0:9
x1 = 0.8+n1*0
n2 = 10:19
x2 = 0+n2*0
n3 = 20:30
x3 = n3.^0.2
n = [n1 n2 n3]
x = [x1 x2 x3]
stem (n,x)
grid on
xlabel ('time')
ylabel ('amplitude')
title ('discrete signal generation')
Exercise#4
Generate and plot 100 samples of the following signals using ‘linspace function. Label the axis’s
suitably. Give suitable title to the plots. Use grid on function in plots. Plot real and imaginary parts of
signal (ܾ) and use legend function to identify them. Also show 3-D plot of signal (ܾ). Show all three
plots on same figure using subplot function
clc;
clear all;
n = linspace(1,1.99,100)
t = linspace(1,1.99,100)
w = linspace(-5,5,100)
x3 = 4*cos(0.1*n*pi)
x4 = 2*sin(0.2*n*pi)
y = x3+x4
x = 10*exp(-j.*w.*t)
x1 = real(x)
x2 = imag(x)
subplot(2,2,1)
stem(n,x)
xlabel('time')
ylabel('amplitude')
subplot(2,2,2)
plot(t,x1,t,x2)
grid on
legend('real','imag')
subplot (2,2,3)
plot3(t,x,w)
xlabel('time')
ylabel('amplitude')
subplot(2,2,4)
stem(n,y)
grid on
xlabel('time')
ylabel('amplitude')
title('signal generation using linspace')
clc
clear all
t=linspace(-1,5,610)
f=cos(8*pi*t).*exp(-2*t)
subplot(1,2,1)
plot(t,f,'r','LineWidth',2)
grid on
xlabel('t in sec')
ylabel('amplitide in volts')
title('plot of analog signal')
axis([-3,12,-10,10])
subplot(1,2,2)
stem(t,f,'c','LineWidth',2)
xlabel('time')
ylabel('amplitide')
title('diff btw plot and stem')
axis([-3,12,-10,10])
grid on
Experiment 2
Exercise#1
(a) Generate and plot a continuous time sinusoid signal of 64 samples ranging from 0 to 1, 1 kHz
frequency, 2v amplitude and zero phase.(b) Sample the above signal with sampling frequency of 8
kHz and plot its discrete version.(c) Calculate the sampling interval, total record time, period of one
cycle and count total number of cycles of the discrete signal.
clc
clear all
close all
t=0:1/63:1
f=1000
x=2*sin(2.*pi.*f.*t)
subplot(2,1,1)
plot(t,x,'m','LineWidth',2)
xlabel('time')
ylabel('amplitide')
title('continuous time sinusoid signal')
grid on
fs=8000
h=0:63
y=2*sin(2.*pi.*(f/fs).*h)
subplot(2,1,2)
stem(h,y,'r','LineWidth',1)
xlabel('time')
ylabel('amplitide')
title('discrete version')
grid on
ts=1/fs
rt=64*ts
tp=1/f
cy=fs/f
clc
clear all
close all
N=40
n=(-N/2):(N/2)
x=zeros(1,41)
x((N/2)+11)=2
subplot(1,2,1)
stem(n,x,'r','LineWidth',2)
xlabel('sample number')
ylabel('amplitide')
title('continous time unit step signal')
grid on
y=zeros(1,41)
y((N/2)-9)=5
y((N/2)+21)=2.5
subplot(1,2,2)
stem(n,y,'c','LineWidth',2)
title('A discrete time Unit Step Signal')
xlabel('Sample Number')
ylabel('Amplitude')
grid on
axis([-22,22,-1,6]
(a) clc
clear all
close all
N=40
n=-9:30
x=[zeros(1,(N-22)/2),ones(1,5),zeros(1,(N/2)+6)]
subplot(1,2,1)
stem(n,x,'r','LineWidth',2)
grid on
title('Folded Signal y(n)')
xlabel('discrete time n')
ylabel('Amplitude')
(b) clc
clear all
close all
N=40
n=-9:30
x=[zeros(1,(N-22)/2),ones(1,5),zeros(1,(N/2)+6)]
subplot(1,2,1)
stem(n,x,'r','LineWidth',2)
grid on
title('Folded Signal y(n)')
xlabel('discrete time n')
ylabel('Amplitude')
n1=-5:19 %(b)
x1=5*(n1+5).*ones(1,25)
n2=20:30
x2=5*(n2+5).*ones(1,11)-2.5*(n2-20).*ones(1,11)
y=[zeros(1((N-22)/2)-5),x1,x2]
stem(n,y)
title('Shifted Signal y(n)')
xlabel('discrete time n')
ylabel('Amplitude')
grid on
clc;
clear all;
close all;
n=-4:8;
x=[1 2 3 4 5 6 7 6 5 4 3 2 1]
subplot(3,1,1)
stem(n,x,'linewidth',1.5)
grid on;
xlabel('n');
ylabel('x(n)')
title('plot of x(n)')
[x1,n1]=sigshift(2*x,n,5)
[x2,n2]=sigshift(-3*x,n,-4)
[a,m]=sigadd(x1,n1,x2,n2)
subplot(3,1,2)
stem(m,a,'linewidth',1.5)
grid on;
xlabel('n');
ylabel('x(n)')
[y3,m3]=sigfold(x,n) %(b)part
[y4,m4]=sigshift(y3,m3,-3)
[y5,m5]=sigshift(x,n,2)
[y6,m6]=sigmult(x,n,y5,m5)
subplot(3,1,3)
stem(m6,y6,'linewidth',1.5)
grid on;
xlabel('n');
ylabel('x(n)')
title('plot of y(n)')
[y7,m7]=sigadd(y4,m4,y6,m6)
subplot(3,1,3)
stem(m7,y7,'linewidth',1.5)
grid on;
xlabel('n');
ylabel('x(n)')
title('plot of y(n)b')
clc;
clear all;
close all;
N=41
n=-20:20
x=[zeros(1,20),ones(1,10),zeros(1,11)]
subplot(2,2,1)
stem(n,x,'r','linewidth',1.5)
grid on
title('experiment 2.5')
grid on; xlabel('n');ylabel('x(n)')
[y1,m1]=sigfold(x,n)
subplot(2,2,2)
stem(m1,y1,'c','linewidth',1.5);
title('folding of the signbal')
grid on; xlabel('n');ylabel('x(n)')
%even part of the signal
[y2,m2]=sigadd(x,n,y1,m1);
y3=y2/2;
subplot(2,2,3)
stem(m2,y3,'r','linewidth',1.5);
title('even part od the signal')
grid on; xlabel('n');ylabel('x(n)')
% odd part of the signal
[y4,m4]=sigfold(-1*x,n)
[y5,m5]=sigadd(y4,m4,x,n)
y6=y5/2;
subplot(2,2,4)
stem(m5,y6,'linewidth',1.5);
title('odd part od the signal')
grid on; xlabel('n');ylabel('x(n)')