Digital Signal Processing Laboratory: Electronics & Telecommunication Engineering
Digital Signal Processing Laboratory: Electronics & Telecommunication Engineering
Laboratory
Day 4
Aim
Write MATLAB programs to plot the
following sequences
Group 3.4
Roll Number Name
001910701071 Shoaib Bhutia
001910701072 Adil Ahmed
001910701073 Asipi Praveen Rao
001910701074 Gaurav Nandy
1. Write a Matlab program to find the
autocorrelation of a sequence: x = [1,2,3,4]
x = [1 2 3 4];
n=0:3;
y=xcorr(x,x);
n1= 0:6;
subplot(211)
stem(n,x,'r');
xlabel('n');
ylabel('x');
title('Original Sequence');
subplot(212)
stem(n1,y,'g');
xlabel('n');
ylabel('y');
title('Autocorrelation Sequence');
1.b. Find the cross-correlation between the given
two sequences:
x1 = [2,-1,3,7,1,2,-3] ; -4<=n<=2
x2 = [1,-1,2,-2,4,1,-2,5] ; -4<=n<=3
x1 = [2 -1 3 7 1 2 -3];
x2 = [1 -1 2 -2 4 1 -2 5];
n1=-4:2;
n2=-4:3;
m1=length(x1);
m2=length(x2);
y=xcorr(x1,x2);
n= ceil(-(m1+m2-1)/2):floor((m1+m2-1)/2);
subplot(311)
stem(n1,x1,'r');
xlabel('n');
ylabel('x1');
title('Original Sequence 1');
subplot(312)
stem(n2,x2,'g');
xlabel('n');
ylabel('x2');
title('Original Sequence 2');
subplot(313)
stem(n,y,'b');
xlabel('n');
ylabel('y');
title('Cross-correlation Sequence');
2. Write a Matlab program to find the
autocorrelation of any periodic signal.
clear all;
close all;
clc;
nx=-10:10;
x=sin(nx*2*pi/20);
x2=fliplr(x);
y1=conv(x,x2);
ny1=0:length(y1)-1;
subplot(2,1,1);
stem(nx,x);
xlabel('n');
ylabel('x(n)');
title('Periodic signal');
subplot(2,1,2);
stem(ny1,y1);
xlabel('n');
ylabel('y1(n)');
title('Autocorrelation of Periodic Signal');
3. Write a Matlab program to find the
autocorrelation of any noise signal.
a=-1;%starting time
b=22;%ending time
t1=[a:b];
m=abs(a);
if a~=(-1)*b
if abs(a)>abs(b)
m=abs(a);
else
m=abs(b);
end
t1=[-m:m];
end
f=10;%f=10Hz
x=sin(2*pi*f*t1);
y=awgn(x,5,'measured');%SNR of 5dB comes here
noise1=flip(noise,2);%time_reversal of noise
autocorr_noise=conv(noise,noise1);
t2=[-2*m:2*m];%convoluted signal duration
subplot(2,1,1);
stem(t1,noise);
title"Noise Signal"
subplot(2,1,2);
stem(t2,autocorr_noise);
title"Autocorrelation of Noise Signal";
ii. Using the randn() function to add random noise.
clc;
clear all;
close all;
n=-10:10;
x=randn(size(n));
subplot(2,1,1)
stem(n,x,'g')
title('Noisy Signal')
xlabel('n')
ylabel('x(n)')
n1=-(length(n)-1):(length(n)-1);
y=conv(x,fliplr(x));
subplot(2,1,2)
stem(n1,y,'b')
title('Autocorrelated Sequence')
xlabel('n')
ylabel('y(n)')
4. Write a Matlab program to find autocorrelation
of a periodic signal corrupted by noise.
clc;
clear all;
close all;
n=-10:10;
x=sin(n);
subplot(2,2,1)
stem(n,x)
title('Periodic sequence')
xlabel('n')
ylabel('x(n)')
n1=-10:10;
x1=awgn(x,5);
subplot(2,2,2)
stem(n1,x1)
title('Periodic sequence with additive Gaussian noise')
xlabel('n')
ylabel('x1(n)')
n3=-(length(n1)-1):(length(n1)-1);
y=conv(x1,fliplr(x1));
subplot(2,2,3)
stem(n3,y)
title('Autocorrelated sequence')
xlabel('n')
ylabel('y(n)')
ii. Using the randn() function to add random noise.
clc;
clear all;
close all;
n=-10:10;
x=sin(n);
subplot(2,2,1)
stem(n,x,'r')
title('Periodic sequence')
xlabel('n')
ylabel('x(n)')
n1=-10:10;
x1=randn(size(x));
subplot(2,2,2)
stem(n1,x1,'g')
title('Periodic signal corrupted by Noise')
xlabel('n')
ylabel('x1(n)')
n3=-(length(n1)-1):(length(n1)-1);
y=conv(x1,fliplr(x1));
subplot(2,2,3)
stem(n3,y,'b')
title('Autocorrelated Sequence')
xlabel('n')
ylabel('y(n)')