0% found this document useful (0 votes)
11 views2 pages

Lab 6

Uploaded by

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

Lab 6

Uploaded by

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

Lab 6

Objective
In this lab we will be able:
 To compute auto and cross correlation using matlab

Introduction
Correlation is a statistical technique that is used to measure the similarity between two
signals. In the case of discrete signals, the correlation is calculated as the inner product
of two signals, where the signals are time-shifted versions of each other. The correlation
coefficient ranges from -1 to 1, where a value of 1 indicates a perfect correlation, a
value of 0 indicates no correlation, and a value of -1 indicates a perfect anti-correlation.

Procedure
In Matlab, there are two main functions that can be used to calculate the correlation of
two discrete signals: xcorr and corrcoef. The xcorr function calculates the cross-
correlation of two signals, while the corrcoef function calculates the correlation
coefficient of two signals. where x and y are the two signals to be correlated, maxlag is
the maximum lag value (default is the length of the input signals), and r is the correlation
values and lag is the lag values of the correlation values.

Lab Task

% Define the first sequence


x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];

% Define the second sequence


y = [15 14 13 12 11 10 9 8 7 6 5 4 3 2 1];

% Calculate the cross-correlation using the xcorr function


[r, lag] = xcorr(x, y);

% Plot the correlation values against the lag values


figure;
subplot(2,1,1);
plot(lag, r);
xlabel('Lag');
ylabel('Correlation');
title('Cross-Correlation of the two sequences');

% Calculate the correlation coefficient using the corrcoef function


R = corrcoef(x, y);

% Display the correlation coefficient matrix


subplot(2,1,2);
disp(R);
title('Correlation Coefficient of the two sequences');
Conclusion
In conclusion, the xcorr and corrcoef functions in Matlab can be used to calculate the
correlation of two discrete signals. The xcorr function calculates the cross-correlation of
two signals, while the corrcoef function calculates the correlation coefficient of two
signals. Both functions are easy to use and provide useful information about the
similarity between two signals.

You might also like