0% found this document useful (0 votes)
48 views17 pages

Lab 05 DSIP

The document provides an overview of correlation, specifically focusing on cross-correlation and auto-correlation of signals. It includes examples demonstrating how to compute the correlation between sequences using MATLAB, along with visual outputs of the results. Additionally, it outlines lab tasks related to finding correlations between given sequences.

Uploaded by

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

Lab 05 DSIP

The document provides an overview of correlation, specifically focusing on cross-correlation and auto-correlation of signals. It includes examples demonstrating how to compute the correlation between sequences using MATLAB, along with visual outputs of the results. Additionally, it outlines lab tasks related to finding correlations between given sequences.

Uploaded by

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

To perform cross-

correlation and
auto-correlation
LAB # 5
Correlation
Correlation is the measure of similarity or degree of similarity
between two signals or a signal with itself.

Cross correlation
Correlation of two signals is the convolution between one signal with the
functional inverse version of the other signal. The resultant signal is called the
cross-correlation of the two input signals. The amplitude of cross-correlation
signal is a measure of how much the received signal resembles the target signal.
Example #01
•Find the correlation b/w the two sequences x[n] and h[n] given by,
x=[3 1 2];
nx=0:length(x)-1;
subplot(2,2,1);stem(nx,x); 3
x[n]
3
h[n]
title('x[n]');grid on
h=[3 2 1]; 2 2

nh=0:length(h)-1;
1 1
subplot(2,2,2);stem(nh,h);
title('h[n]');grid on 0 0
y1=xcorr(x,h) 0 0.5 1 1.5 2 0 0.5 1 1.5 2

ny=0:length(y1)-1; xh hx
15 15
subplot(2,2,3);stem(ny-2,y1);
title('xh');grid on 10 10
y2=xcorr(h,x)
ny=0:length(y2)-1; 5 5

subplot(2,2,4);stem(ny-2,y2);
0 0
title('hx');grid on -2 -1 0 1 2 -2 -1 0 1 2
Example #
%Correlation as a similarity measure
clc
clear all
close all
n=-50:50;
x=((n.*(n>=0))+((n<=0).*n))/10;
nx=0:length(x)-1;
subplot(3,1,1);stem(nx-50,x);title('x'); grid on
y=((n.*(n>=0))+((n<=0).*n))/10;
ny=0:length(y)-1;
subplot(3,1,2);stem(ny-50,y);title('y');grid on
z=9*(1-exp(-0.4*abs(n)));
nz=0:length(z)-1;
subplot(3,1,3);stem(nz-50,z);title('z'); grid on
Output
x
5

-5
-50 -40 -30 -20 -10 0 10 20 30 40 50
y
5

-5
-50 -40 -30 -20 -10 0 10 20 30 40 50
z
10

0
-50 -40 -30 -20 -10 0 10 20 30 40 50
% correlation
figure;
y1=xcorr(x,y)
ny=0:length(y1)-1;
subplot(2,1,1);stem(ny,y1);
title('xy');grid on
y2=xcorr(x,z)
ny2=0:length(y2)-1;
subplot(2,1,2);stem(ny2,y2);
title('xz');grid on
Output
xy
1000

500

-500
0 20 40 60 80 100 120 140 160 180 200

xz
2000

1000

-1000

-2000
0 20 40 60 80 100 120 140 160 180 200
%Correlation as a similarity measure
clc
clear all
close all
n=-50:50;
x=((n.*(n>=0))+((n<=0).*n))/10;
nx=0:length(x)-1;
xn=x/max(x);
subplot(3,1,1);stem(nx-50,xn);title('x'); grid on
y=((n.*(n>=0))+((n<=0).*n))/10;
ny=0:length(y)-1;
yn=y/max(y);
subplot(3,1,2);stem(ny-50,yn);title('y');grid on
z=9*(1-exp(-0.4*abs(n)));
nz=0:length(z)-1;
zn=z/max(z);
subplot(3,1,3);stem(nz-50,zn);title('z'); grid on
Output
x
1

-1
-50 -40 -30 -20 -10 0 10 20 30 40 50
y
1

-1
-50 -40 -30 -20 -10 0 10 20 30 40 50
z
1

0.5

0
-50 -40 -30 -20 -10 0 10 20 30 40 50
% correlation
figure;
y1=xcorr(xn,yn)
ny=0:length(y1)-1;
subplot(2,1,1);stem(ny,y1);
title('xy');grid on
y2=xcorr(xn,zn)
ny2=0:length(y2)-1;
subplot(2,1,2);stem(ny2,y2);
title('xz');grid on
Output
xy
40

20

-20
0 20 40 60 80 100 120 140 160 180 200

xz
40

20

-20

-40
0 20 40 60 80 100 120 140 160 180 200
Example #02
Find the Autocorrelation of sequences x[n] given by,
Clc
clear all
close all
%Auto correlation
x=[0 1 -2 3 -4];
nx=0:length(x)-1;
subplot(2,1,1);y=stem(nx,x);
title('x[n]');grid on
y1=xcorr(x)
ny=0:length(y1)-1;
subplot(2,1,2);stem(ny-4,y1);
title('Auto correlation');grid on
Output
x[n]
4

-2

-4
0 0.5 1 1.5 2 2.5 3 3.5 4

Auto correlation
40

20

-20
-4 -3 -2 -1 0 1 2 3 4
Lab task#01
•Q1. Find the correlation b/w the two sequences x[n] and h[n] given by,
Lab task#02
Q2. Auto correlate x[n]=an u[n] for a <1

You might also like