You are on page 1of 7

LOYOLA - ICAM

COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

Ex.No -3
Auto Correlation and Cross Correlation
Date: 09.09.2021

AIM:
To write a MATLAB program to obtain the Auto Correlation and Cross Correlation of
two sequences.

APPARATUS REQUIRED:
MATLAB, PC

THEORY:

In signal processing, cross-correlation is a measure of similarity of two series as a function


of the lag of one relative to the other. This is also known as a sliding Dot product orsliding
inner-product. It is commonly used for searching a long signal for a shorter, known feature. It
has applications in Pattern Recognition, Single Particle Analysis, Electron Tomography,
Averaging, Cryptanalysis and Neurophysiology, 

For continuous functions f and g, the cross-correlation is defined as:

where   denotes the Complex Conjugate of   and   is the lag.


Similarly, for discrete functions, the cross-correlation is defined as:

The cross-correlation is similar in nature to the convolution of two functions.

In Autocorrelation, which is the cross-correlation of a signal with itself, there will always be
a peak at a lag of zero, and its size will be the signal power.

311119106059 VEERALAKSHMI P
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

ALGORITHM:
1. Give the input sequences
2. Use the inbuilt MATLAB function (XCORR) to find out the correlation
3. Plot the output graph
4. Observe the result in the command window

PROGRAM:

AUTO CORRELATION

clc
clear all
close all
x=input('enter the value')
n=length(x)
n1=-n:0:n-1;
subplot(2,1,1);
stem(n1,x)
xlabel('Time');
ylabel('Amplitude');
title('input value');
grid on;
z=xcorr(x,x)
l=n-1;
n3=-l:0:l-1;
subplot(2,1,2);
stem(n3,z)
xlabel('Time');
ylabel('Amplitude');
title('auto correlation');
grid on;

INPUT:

enter the value> [3 2 4 1]

311119106059 VEERALAKSHMI P
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

OUTPUT:

enter the value> [3 2 4 1]

x =

3 2 4 1

n = 4

z =

3 14 18 30 18 14 3

GRAPH:

311119106059 VEERALAKSHMI P
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

CALCULATION:

Figure 3.1 Auto Correlation

CROSS CORRELATION:

clc
clear all
close all
x=input('enter the first value')
n=length(x)
n1=-n:0:n-1;

311119106059 VEERALAKSHMI P
subplot(3,1,1);
stem(n1,x)
xlabel('time');
ylabel('amplitude');
title('input value1');

LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

grid on;
y=input('enter the second value')
m=length(y)
m1=-m:0:m-1;
subplot(3,1,2);
stem(m1,y)
xlabel('time');
ylabel('amplitude');
title('input value2');
grid on;
z=xcorr(x,y)
l=n+m-1;
n3=-l:0:l-1;
subplot(3,1,3);
stem(n3,z)
xlabel('time');
ylabel('amplitude');
title('cross correlation');
grid on;

INPUT:

enter the first value> [2 5 6 3]


enter the second value> [1 2 3 7]
OUTPUT:

enter the first value> [2 5 6 7 8]

x =

2 5 6 7 8

n = 5
enter the second value> [3 4 5 6 7]

y =

3 4 5 6 7

m = 5

311119106059 VEERALAKSHMI P
z =

Columns 1 through 8:

14.000 47.000 82.000 118.000 154.000 122.000 86.000


53.000

Column 9: 24.000

LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

GRAPH:

Figure 3.2 Cross Correlation

311119106059 VEERALAKSHMI P
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

CALCULATION:

RESULT:
Thus a MATLAB program is written to obtain the Auto Correlation and Cross
Correlation of two sequences

311119106059 VEERALAKSHMI P

You might also like