Professional Documents
Culture Documents
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 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:
311119106059 VEERALAKSHMI P
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
OUTPUT:
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:
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:
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:
Column 9: 24.000
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
GRAPH:
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