0% found this document useful (0 votes)
2 views

Correlation of Signals

Uploaded by

Thekra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Correlation of Signals

Uploaded by

Thekra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Correlation of signals

MATLAB tutorial series (Part 1.2)

Pouyan Ebrahimbabaie

Laboratory for Signal and Image Exploitation (INTELSIG)


Dept. of Electrical Engineering and Computer Science
University of Liège
Liège, Belgium

Applied digital signal processing (ELEN0071-1)


19 February 2020
Motivation

• We wish to measure the similarity between a


signal of interest and a reference signal.

2
Motivation

• We wish to measure the similarity between a


signal of interest and a reference signal.

3
Motivation

• We wish to measure the similarity between a


signal of interest and a reference signal.

4
Correlation signal

Correlation signal (main formula):


𝒓𝒙𝒚 𝒍 = ෍ 𝒙 𝒏 × 𝒚 𝒏 − 𝒍 −∞<𝒍<∞
𝒏=−∞

5
Correlation signal

Correlation signal (main formula):


𝒓𝒙𝒚 𝒍 = ෍ 𝒙 𝒏 × 𝒚 𝒏 − 𝒍 −∞<𝒍<∞
𝒏=−∞

It is certainly not a convolution!


Correlation signal

Correlation signal (main formula):


𝒓𝒙𝒚 𝒍 = ෍ 𝒙 𝒏 × 𝒚 𝒏 − 𝒍 −∞<𝒍<∞
𝒏=−∞

It is certainly not a convolution!

Alternative formula:
𝒓𝒙𝒚 𝒍 = 𝒙 𝒍 ∗ 𝒚[−𝒍]

7
Correlation signal

Correlation signal (main formula):


𝒓𝒙𝒚 𝒍 = ෍ 𝒙 𝒏 × 𝒚 𝒏 − 𝒍 −∞<𝒍<∞
𝒏=−∞

It is certainly not a convolution!

Alternative formula:
𝒓𝒙𝒚 𝒍 = 𝒙 𝒍 ∗ 𝒚[−𝒍]

Normalized correlation:
𝒓𝒙𝒚 𝒍
−𝟏 ≤ 𝝆𝒙𝒚 [𝒍] ≜ ≤𝟏
𝑬𝒙 𝑬𝒚 8
How does it work?!

Example 1:
let 𝒙 𝒏 = 𝒄𝒚 𝒏 − 𝒏𝟎 , 𝒄 > 𝟎

9
How does it work?!

Example 1:
let 𝒙 𝒏 = 𝒄𝒚 𝒏 − 𝒏𝟎 , 𝒄 > 𝟎
𝝆𝒙𝒚 𝒍

𝒏𝟎 𝒍
10
How does it work?!

Example 1:
let 𝒙 𝒏 = 𝒄𝒚 𝒏 − 𝒏𝟎 , 𝒄 > 𝟎 → 𝝆𝒙𝒚 𝒏𝟎 = 𝟏 .
𝝆𝒙𝒚 𝒍

𝒏𝟎 𝒍
11
How does it work?!

Example 2:
let 𝒙 𝒏 and 𝒚 𝒏 be two uncorrelated signal.
𝝆𝒙𝒚 𝒍

𝒍
12
Autocorrelation

Autocorrelation is the correlation of signal


with itself.

𝒓𝒙 𝒍 = 𝒙 𝒍 ∗ 𝒙[−𝒍]
Autocorrelation

Autocorrelation is the correlation of signal


with itself.

𝒓𝒙 𝒍 = 𝒙 𝒍 ∗ 𝒙[−𝒍]

Wiener-Khintchine theorem:

𝐃𝐓𝐅𝐓 𝟐
𝒋𝝎
𝒓𝒙 𝒍 = 𝒙 𝒍 ∗ 𝒙 −𝒍 𝑹𝒙 𝝎 = 𝑿(𝒆 )
Numerical computation of correlation signal

Cross correlation:

𝒓𝒙𝒚 𝒍 = ෍ 𝒙 𝒏 × 𝒚 𝒏 − 𝒍 −∞<𝒍<∞
𝒏=−∞
MATLAB function:

[rxy,Lag]=xcorr(x,y) % returns cross-correlation

rxy=conv(x,flipud(y)) % alternative method


Echo

𝒚 𝒏 = 𝒙[𝒏]
Echo

𝒚 𝒏 = 𝒙[𝒏]
Echo

𝒚 𝒏 = 𝒙 𝒏 + 𝒂 𝒙[𝒏 − 𝑫]
Echo

𝒚 𝒏 = 𝒙 𝒏 + 𝒂 𝒙[𝒏 − 𝑫]

Attenuation Distance
Echo

𝒚 𝒏 = 𝒙 𝒏 + 𝒂 𝒚[𝒏 − 𝑫] →
𝒀 𝒛 = 𝑿 𝒛 + 𝒂 𝑿 𝒛 𝒛−𝑫
Echo

𝒚 𝒏 = 𝒙 𝒏 + 𝒂 𝒚[𝒏 − 𝑫] →
𝒀 𝒛 = 𝑿 𝒛 + 𝒂 𝑿 𝒛 𝒛−𝑫 →
Echo filter: 𝑯[𝒛] = 𝒀 [𝒛]/𝑿[𝒛] = (𝟏 + 𝒂𝒛−𝑫 )
Application (sound)

MATLAB functions:

[x,Fs]=audioread(‘Filename.wav’)
% Reads audio file and return sampled signal x
(all channels), and sampling frequency Fs.

sound(x,Fs) % play the sound

filter(b,a,x)% filter the signal x using the rational


transfer function
Example 1.6: play and plot a sound

% read audio file .wav


[x,Fs]=audioread('Atonment.wav');
% play the sound
sound(x,Fs)
% plot left or right channel
figure(1)
plot(x(:,1))
% compute autocorrelation sequence
[acorrX,lagX]=xcorr(x(:,1),x(:,1));
% plot autocorrelation function
figure(2)
plot(lagX,acorrX,'LineWidth',2.5)
Example 1.6: play and plot a sound

% read audio file .wav


[x,Fs]=audioread('Atonment.wav');
% play the sound
sound(x,Fs)
% plot left or right channel
figure(1)
plot(x(:,1))
% compute autocorrelation sequence
[acorrX,lagX]=xcorr(x(:,1),x(:,1));
% plot autocorrelation function
figure(2)
plot(lagX,acorrX,'LineWidth',2.5)
Example 1.6: play and plot a sound

% read audio file .wav


[x,Fs]=audioread('Atonment.wav');
% play the sound
sound(x,Fs)
% plot left or right channel
figure(1)
plot(x(:,1))
% compute autocorrelation sequence
[acorrX,lagX]=xcorr(x(:,1),x(:,1));
% plot autocorrelation function
figure(2)
plot(lagX,acorrX,'LineWidth',2.5)
Example 1.7: generate reverberation

% read audio file


[x,Fs]=audioread('Atonment.wav');
% delay in seconds (e.g. 0.3, 0.4, 0.5).
% play with these!
delay=0.2;
%alpha (metal room 0.9)
alpha=0.6;
% delay in samples
d=delay*Fs;
% echo filter coefficents
b=1;
a=[1, zeros(1,d-1), -alpha];
Example 1.7: generate reverberation

% read audio file


[x,Fs]=audioread('Atonment.wav');
% delay in seconds (e.g. 0.3, 0.4, 0.5).
% play with these!
delay=0.2;
%alpha (metal room 0.9)
alpha=0.6;
% delay in samples
d=delay*Fs;
% echo filter coefficents
b=1;
a=[1, zeros(1,d-1), -alpha];
Example 1.7: generate reverberation

% read audio file


[x,Fs]=audioread('Atonment.wav');
% delay in seconds (e.g. 0.3, 0.4, 0.5).
% play with these!
delay=0.2;
%alpha (metal room 0.9)
alpha=0.6;
% delay in samples
d=delay*Fs;
% echo filter coefficents
b=1;
a=[1, zeros(1,d-1), -alpha];
Example 1.7: generate reverberation

% read audio file


[x,Fs]=audioread('Atonment.wav');
% delay in seconds (e.g. 0.3, 0.4, 0.5).
% play with these!
delay=0.2;
%alpha (metal room 0.9)
alpha=0.6;
% delay in samples
d=delay*Fs;
% echo filter coefficents
b=1;
a=[1, zeros(1,d-1), -alpha];
Example 1.7: generate reverberation

% read audio file


[x,Fs]=audioread('Atonment.wav');
% delay in seconds (e.g. 0.3, 0.4, 0.5).
% play with these!
delay=0.2;
%alpha (metal room 0.9)
alpha=0.6;
% delay in samples
d=delay*Fs;
% reverberator
b=1;
a=[1, zeros(1,d-1), -alpha];
Example 1.7: generate reverberation

% generate signal + reverbration


y=filter(b,a,x);
% play new sound
sound(y,Fs)
% compuet autocorrelation
[acorrY,lagY]=xcorr(y(:,1),y(:,1));
% plot autocorr of echo
% /!\ find delay from autocorrelation signal
plot(lagY,acorrY,'LineWidth',2.5)
Example 1.7: generate reverberation

% generate signal + reverberation


y=filter(b,a,x);
% play new sound
sound(y,Fs)
% compuet autocorrelation
[acorrY,lagY]=xcorr(y(:,1),y(:,1));
% plot autocorr of echo
% /!\ find delay from autocorrelation signal
plot(lagY,acorrY,'LineWidth',2.5)
Example 1.7: generate reverberation

% generate signal + reverberation


y=filter(b,a,x);
% play new sound
sound(y,Fs)
% compuet correlation
[acorrY,lagY]=xcorr(y(:,1),y(:,1));
% plot autocorr of reverberated signal
% /!\ find delay from autocorrelation signal
plot(lagY,acorrY,'LineWidth',2.5)
Useful links

• https://nl.mathworks.com/help/matlab/ref/audioread.ht
ml

• https://nl.mathworks.com/help/matlab/ref/filter.html

• https://nl.mathworks.com/help/signal/ref/xcorr.html

You might also like