Correlation and Auto Correlation
Correlation and Auto Correlation
Objectives
Develop an intuitive understanding of the crosscorrelation of two signals.
Define the meaning of the auto-correlation of a signal.
Develop a method to calculate the cross-correlation and
auto-correlation of signals.
Demonstrate the relationship between auto-correlation
and signal power.
Demonstrate how to detect periodicities in noisy signals
using auto-correlation techniques.
Demonstrate the application of cross-correlation to sonar
or radar ranging
Correlation
Correlation addresses the question: to what
degree is signal A similar to signal B.
An intuitive answer can be developed by
comparing deterministic signals with stochastic
signals.
Deterministic = a predictable signal equivalent to that
produced by a mathematical function
Stochastic = an unpredictable signal equivalent to that
produced by a random process
Three Signals
>> n=0:23;
>> A=[ones(1,4),zeros(1,8),ones(1,4),zeros(1,8)];
>> subplot (3,1,1),stem(n,A);axis([0 25 0 1.5]);title('Signal A')
>> B1=randn(size(A)); %The signal B1 is Gaussian noise with the same length as A
>> subplot(3,1,2),stem(n,B1);axis([0 25 -3 3]);title('Signal B1')
>> B2=A;
>> subplot(3,1,3),stem(n,B2); axis([0 25 0 1.5]);title('Signal B2');xlabel('Sample')
Signal A
1.5
1
0.5
By inspection, A is correlated
with B2, but B1 is uncorrelated
with both A and B2. This is an
intuitive and visual definition of
correlation.
10
15
20
25
15
20
25
15
20
25
Signal B1
2
0
-2
0
10
Signal B2
1.5
1
0.5
0
10
Sample
Quantitative Correlation
We seek a quantitative and algorithmic way of
assessing correlation
A possibility is to multiple signals sample-bysample and average the results. This would
give a relatively large positive value for identical
signals and a near zero value for two random
signals.
1
r12
N
N 1
x [ n] x [ n]
n 0
Simple Cross-Correlation
Taking the previous signals, A,
B1(random), and B2 (identical to A):
>> A*B1'/length(A)
ans =
-0.0047
>> A*B2'/length(A)
ans =
0.3333
Simple Cross-Correlation of
Random Signals
>> n=0:100;
>> noise1=randn(size(n));
>> noise2=randn(size(n));
>> noise1*noise2'/length(noise1)
ans =
0.0893
0.5
10
15
20
25
20
25
Sample-Shifted Signal
0.5
10
15
Sample-Shifted Cross-Correlation
Shift the signals k steps with respect to one another and calculate
r12(k).
1
r12 (k )
N
N 1
x [ n] x [ n k ]
n 0
Full Cross-Correlation
>> A=[ones(1,4),zeros(1,8),ones(1,4),zeros(1,8)];
>> A2=filter([0,0,0,0,0,1],1,A);
>> [acor,lags]=xcorr(A,A2);
>> subplot(3,1,1),stem(A); title('Original Signal A')
>> subplot(3,1,2),stem(A2); title('Sample Shifted Signal A2')
>> subplot(3,1,3),stem(lags,acor/length(A)),title('Full Cross-Correlation of A and A2')
Original Signal A
Signal A2 shifted
to the left by 5
steps makes the
signals identical
and r12 = 0.333
0.5
0
10
15
20
25
20
25
1
0.5
0
10
15
0.4
0.2
0
-25
-20
-15
-10
-5
10
15
20
25
The crosscorrelation is
random and
shows no peak,
which implies no
correlation
0.05
0
-0.05
-0.1
-0.15
-0.2
-100
-80
-60
-40
-20
20
40
60
80
100
Auto-Correlation
The cross-correlation of a signal with itself
is called the auto-correlation
1 N 1
r11 (k ) x1[n]x1[n k ]
N n 0
N 1
1
x
[
n
]
x
[
n
]
1
1
N
n 0
N 1
2
x
[ n]
n 0
Auto-Correlation of a Random
Signal
>> n=0:50;
>> N=randn(size(n));
>> [rNN,k]=xcorr(N,N);
>> stem(k,rNN/length(N));title('Auto-correlation of a Random Signal')
Auto-correlation of a Random Signal
1
0.8
Mathematically, the
auto-correlation of a
random signal is like
the impulse function
0.6
0.4
0.2
0
-0.2
-0.4
-50
-40
-30
-20
-10
10
20
30
40
50
Auto-Correlation of a Sinusoid
>> n=0:99;
>> omega=2*pi*100/1000;
>> d1000=sin(omega*n);
>> [acor_d1000,k]=xcorr(d1000,d1000);
>> plot(k,acor_d1000/length(d1000));
>> title('Auto-correlation of signal d1000')
Auto-correlation of signal d1000
0.5
0.4
0.3
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
-0.5
-100
-80
-60
-40
-20
20
40
60
80
100
1
0
It is very difficult
to see the
sinusoid in the
noisy signals
-1
10
20
30
40
50
60
70
80
90
100
70
80
90
100
70
80
90
100
3X Noisy Signal
10
0
-10
0
10
20
30
40
50
60
5X Noisy Signal
10
0
-10
0
10
20
30
40
50
60
0.5
Normal spectra of
a sinusoid
masked by noise:
High noise power
makes detection
less certain
50
100
150
200
50
100
150
200
250
300
Hz
100 Hz 5X Noise
350
400
450
500
350
400
450
500
0.5
250
Hz
300
The autocorrelation of a
noisy signal
provides greater
S/N in detecting
dominant frequency
components
compared to a
normal FFT
0.5
50
100
150
200
50
100
150
200
600
250
300
350
400
Hz
100 Hz, 5X Noise, Auto-correlation Spectrum
450
500
450
500
400
200
0
250
Hz
300
350
400
160
140
120
100
80
60
40
20
0
1770
1780
1790
1800
1810
1820
Year
1830
1840
1850
1860
1870
4000
Autocorrelation
has detected a
periodicity of 9
to 11 years
3500
3500
3000
3000
2500
2500
2000
2000
1500
1500
1000
1000
500
0
-100
4000
500
-80
-60
-40
-20
0
20
Lag, in years
40
60
80
100
10
Years
12
14
16
18
20
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
-0.2
100
200
300
400
500
600
Sample,n
Simulation of a
transmitted and
received pulse (echo)
with a 400 sample
delay
700
800
900
1000
-0.2
100
200
300
400
500
600
Sample, n
700
800
900
1000
0.1
The cross-correlation
of the transmitted and
received signals
shows they are
correlated with a 400
sample delay
0.08
0.06
0.04
0.02
-0.02
-1500
-1000
-500
0
lag, samples
500
1000
1500
The presence of
the return signal in
the presence of
noise is almost
impossible to see
-2
-4
-6
100
200
300
400
500
600
Sample,n
700
800
900
1000
Cross-correlation
of the transmitted
signal with the
noisy echo clearly
shows a
correlation at a
delay of 400
samples
0.08
0.06
0.04
0.02
0
-0.02
-0.04
-1500
-1000
-500
500
1000
1500
Summary
Cross-correlation allows assessment of
the degree of similarity between two
signals.
Its application to identifying a sonar/radar
return echo in heavy noise was illustrated.