Digital Signal Processing Reference
In-Depth Information
between the signals, while zero correlation coefficient signifies that the two signals
are not at all similar. A negative number indicates a negative correlation, meaning
that one signal tends to decrease as the other increases.
Correlation between two different sequences is the cross-correlation and cor-
relation between two identical sequences is the auto-correlation. Correlation can
be viewed as convolution, by reversing one signal. Instead of considering signal
y[k] being indexed from 0 to some positive limit K, we will
fold
it around the
0th sample, and consider that it starts at
−
K. For example, if y[n]
=
[5,3,1,6],
=
=
=
=
we interpret this as y[0]
5; y[1]
3; y[2]
1, and y[3]
6. If we fold this
−
=
−
=
−
=
=
signal around, we would have y[
3]
6, y[
2]
1, y[
1]
3, and y[0]
5.
When we convolve y with x, we would sum
x
[
n
]
×
y
[
n
−
k
]. Using the folded ver-
sion of y, the only thing to change is the index, e.g.,
x
[
n
]
×
y
[
n
−
(
−
k
)
]orsimply
x
[
n
]
k
].
As the number of data samples affects the cross-correlation measure, so the cross-
correlation value must be divided by the number of data samples.
×
y
[
n
+
N
−
1
1
N
S
xy
[
k
]
=
x
[
n
]
y
[
n
+
k
]
(B.11)
n
=
0
The function below finds the cross-correlation between two signals. The total
program is given in
http://extras.springer.com
.
correlate_apu.m
% Measure of similarity between two signals.
%
% Usage: [rho]
=
correlate_apu(k, x, y);
% inputs: k
=
shift (integer between 0 and length(y)-1)
%x,y
=
the signals to correlate
% output: rho
=
the correlation coefficient -1..0..1
%
% Note: This function assumes length(x)
=
length(y).
% Apurba Das, CDAC Kolkata
function [rho]
=
correlate_apu(k, x, orig_y)
% Shift y by k units
y
=
[orig_y(k+1:length(orig_y)), orig_y(1:k)];
N
=
length(x);
sxx
=
x
∗
x.
- sum(x)
∗
sum(x)/N;
syy
=
y
∗
y.
- sum(y)
∗
sum(y)/N;
sxy
=
x
∗
y.
- sum(x)
∗
sum(y)/N;
rho
=
sxy / sqrt(sxx
∗
syy);
Search WWH ::
Custom Search