Professional Documents
Culture Documents
1D Convolution and Correlation
1D Convolution and Correlation
-1 0 1 2 3 4 5 6
0 5 4 2 3 7 4 0
1 2 3 0 0 0 0 0
5 4 2 3 7 4 0 0
0 10 8 4 6 14 8 0
0 0 15 12 6 9 21 12
5 14 25 19 19 27 29 12
1D Correlation
Cross-correlation measures the similarity
between two signals.
The 1D Cross Correlation between two signals
and is given by
-1 0 1 2 3 4 5 6
0 5 4 2 3 7 4 0
1 2 3 0 0 0 0 0
0 0 5 4 2 3 7 4
0 10 8 4 6 14 8 0
15 12 6 9 21 12 0 0
15 22 19 17 29 29 15 4
Cross-Correlation of Two Vectors
r = xcorr(x,y) returns the cross-correlation of two
discrete-time sequences.
Cross-correlation measures the similarity between
a vector x and shifted (lagged) copies of a
vector y as a function of the lag.
If x and y have different lengths, the function
appends zeros to the end of the shorter vector so
it has the same length as the other.
Cross-Correlation of Two Vectors
Example:
Create a vector x and a vector y that is equal
to x shifted by 5 elements to the right.
Compute and plot the estimated cross-correlation
of x and y.
The largest spike occurs at the lag value when the
elements of x and y match exactly (-5).
Cross-Correlation of Two Vectors
MATLAB Code
n = 0:15;
x = 0.84.^n;
y = circshift(x,5);
[c,lags] = xcorr(x,y);
stem(lags,c);
Autocorrelation of Vector
r = xcorr(x) returns the autocorrelation sequence
of x.
If x is a matrix, then r is a matrix whose columns
contain the autocorrelation and cross-correlation
sequences for all combinations of the columns
of x.
Autocorrelation of Vector
Example: Compute and plot the estimated
autocorrelation of a vector x.
The largest spike occurs at zero lag, when x
matches itself exactly.
MATLAB Code
n = 0:15;
x = 0.84.^n;
[c,lags] = xcorr(x);
stem(lags,c);