| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Signal Processing Toolbox |
| Contents | Index |
| Learn more about Signal Processing Toolbox |
C = xcorr2(A,B)
xcorr2(A)
C = xcorr2(A,B) returns the cross-correlation of matrices A and B with no scaling. xcorr2 is the two-dimensional version of xcorr. It has its maximum value when the two matrices are aligned so that they are shaped as similarly as possible.
If matrix A has dimensions (Ma, Na) and matrix B has dimensions (Mb, Nb), The equation for the two-dimensional discrete cross-correlation is
![]()
where
and
.
xcorr2(A) is the autocorrelation matrix of input matrix A. It is identical to xcorr2(A,A).
If matrix I1 has dimensions (4,3) and matrix I2 has dimensions (2,2), the following equations determine the number of rows and columns of the output matrix:
![]()
![]()
The resulting matrix is

![]()
In cross-correlation, the value of an output element is computed as a weighted sum of neighboring elements. For example, suppose the first input matrix represents an image and is defined as
I1 = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
The second input matrix also represents an image and is defined as
I2 = [8 1 6
3 5 7
4 9 2]
The following figure shows how to compute the (2,4) output element (zero-based indexing) using these steps:
The (2,4) output element from the cross-correlation is
![]()

The normalized cross-correlation of the (2,4) output element is
585/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.8070
where I1p = [1 8 15; 7 14 16; 13 20 22].
![]() | xcorr | xcov | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |