0% found this document useful (0 votes)
20 views9 pages

Exp2 (1) DSP

The document outlines an experiment on auto correlation and cross correlation of signals using Python code as part of a Digital Signal Processing course at Rajshahi University of Engineering & Technology. It explains the theory behind correlation, provides algorithms for calculating both types of correlation, and includes Python code examples for implementation. The conclusion emphasizes the significance of these techniques in analyzing signal characteristics and relationships between signals.

Uploaded by

shahriar nafis
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)
20 views9 pages

Exp2 (1) DSP

The document outlines an experiment on auto correlation and cross correlation of signals using Python code as part of a Digital Signal Processing course at Rajshahi University of Engineering & Technology. It explains the theory behind correlation, provides algorithms for calculating both types of correlation, and includes Python code examples for implementation. The conclusion emphasizes the significance of these techniques in analyzing signal characteristics and relationships between signals.

Uploaded by

shahriar nafis
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/ 9

“Heaven’s light is our guide”

Rajshahi University of Engineering & Technology

DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING

Course Code: EEE 4108


Course name: Digital Signal Processing
Experiment No: 02
Name of the experiment: Study of auto correlation and cross correlation of
the given signals using Python Code.

Submitted by: Submitted to:


Name: Shahriar Nafis Dr. Mohammod Abdul Motin
Roll: 1901042 Assistant Professor
Section: A Department of EEE
Series: 19 Rajshahi University of Engineering
& Technology

Date of Experiment: 04-05-24


Experiment no: 02

Name of the experiment: Study of auto correlation and cross correlation of the
given signals using Python Code.

Theory:
Correlation is a statistical measure that expresses the extent to which two signals or
datasets change together. It is a common technique used in signal processing to
determine the similarity between two signals. For correlation signals are timevarying
quantities. They could be any type of data that changes over time, such as audio
signals, temperature readings, or financial data. Correlation is mainly two types:
i. Auto Correlation: Auto-correlation is a measure of how a signal correlates
with a delayed version of itself over different time lags. It is a useful tool
in signal processing for identifying patterns, periodicities, and the presence
of noise in a signal. For a discrete time signal x[n], auto-correlation Rxx[k]
at lag k is defined as:

Rxx[k] = ∑𝑛x[n] ⋅ x[n + k]

Where, k is the lag and the summation is performed over all values of n
where the product x[n] ⋅ x[n + k] is defined.

ii. Cross Correlation: Cross-correlation is a measure of similarity between


two signals as a function of the time lag applied to one of them. It is widely
used in signal processing to detect similarities, time shifts, and alignments
between signals. For a discrete time signal x[n] and y[n], the cross
correlation Rxy[k] at lag K is defined as:

Rxy[k] = ∑𝑛x[n] ⋅ y[n + k]

Where, k is the lag and the summation is performed over all values of n
where the product x[n] ⋅ y[n + k] is defined.
Algorithm to determine auto correlation:
1. Obtain the discrete signal x of length N
2. Initialize an array Rxx to store the auto-correlation values for each lag k.
3. For each lag k from 0 to N−1:
Compute the sum of products x[n] ⋅ x[n + k] for all n where x[n + k] is
defined.
4. The array Rxx contains the auto-correlation values for each lag.

Algorithm to determine Cross correlation:


1. Obtain the discrete signals x and y of length N each
2. Initialize an array Rxy to store the cross-correlation values for each lag k.
3. For each lag k from –N+1 to N−1:
Compute the sum of products x[n] ⋅ y[n + k] for all n where y[n + k] is
defined.
4. The array Rxy contains the cross-correlation values for each lag.

Python Code for Auto Correlation and Cross Correlation:

import numpy as np import


matplotlib.pyplot as plt

#Auto_Correlation #declaring
functions
x = [1, 2, 3, 2, 1]
y1 = x plt.stem(x)
plt.show()
#defining
correlation
function def
auto_correlation(
x,y1):
correlation = np. correlate(x, y1, mode = 'full')
return correlation

#using correlation function correlation1 =


auto_correlation(x,y1) s1 = np.linspace(1,
len(correlation1), len(correlation1)) print("auto-
correlation:", correlation1)

plt.plot(s1, correlation1)
plt.show()

#Cross_Correlation
#declaring functions
x = [1, 2, 3, 2, 1] y2
= [2, 3, 2, 1]
plt.stem(y2)
plt.show()

#defining correlation function


def cross_correlation(x,y2):
correlation = np.correlate(x, y2, mode = 'full')
return correlation

#using correlation function correlation2 =


cross_correlation(x, y2) s2 = np.linspace(1,
len(correlation2), len(correlation2)) print("cross-
correlation:", correlation2)

plt.plot(s2, correlation2)
plt.show()

Output of the code:

Fig-1: Original signal x


auto-correlation: [ 1 4 10 16 19 16 10 4 1]

Fig-2: Auto correlation


Fig-3: Comparable signal y2
cross-correlation: [ 1 4 10 16 18 14 7 2]
Fig-4: Cross Correlation

Discussion & Conclusion:


In this code, a function was declared for Auto correlation and Cross correlation each.
Other than declaring a function, it is possible to determine the two correlations using
‘for’ loop. Auto-correlation is a powerful technique for analyzing the internal
structure of a signal. It helps in identifying repeating patterns, detecting periodicity,
and assessing the presence of noise. By calculating and interpreting the
autocorrelation function, valuable insights can be gained into the characteristics of
the signal. On the other hand, Cross-correlation is also a powerful technique for
analyzing the relationship between two signals. By calculating and interpreting the
cross-correlation function, the degree of similarity can be identified, time lags can
be detected, and insights into the temporal alignment of the signals can be gained.
This makes cross-correlation an essential tool in various fields such as signal
processing, communications, and time series analysis.
So, it is seen that both Auto correlation and Cross correlation are important and
powerful techniques used in Digital Signal Processing.

You might also like