# Constructing the Auto Correlation Matrix in Matlab

(6 votes, average: 4.33 out of 5)

Auto-correlation, also called series correlation, is the correlation of a given sequence with itself as a function of time lag. Cross-correlation is a more generic term, which gives the correlation between two different sequences as a function of time lag.

Check this ebook : Simulation of Digital Communications using Matlab – by Mathuranathan Viswanathan

Given two sequences $$x$$ and $$y$$, the cross-correlation at times separated by lag i is given by ( $$*$$ denotes complex conjugate operation)
$$R_{{xy}_i}=Corr(x,y)_i = \sum_{j=-\infty}^{\infty} x_j y^*_{j+i}$$

Auto-correlation is a special case of cross-correlation, where $$x=y$$. Once use a brute force method (using for loops implementing the above equation) to compute the auto-correlation sequence. However, other alternatives are also at your disposal.

## Method 1: Auto-correlation using xcorr function

For a N-dimensional given vector $$x$$, the Matlab command $$xcorr(x,x)$$ or simply $$xcorr(x)$$ gives the auto-correlation sequence. For the input sequence $$x=[1,2,3,4]$$, the command $$xcorr(x)$$ gives the following result.

## Method 2: Auto-correlation using Convolution

Auto-correlation sequence can be computed as the convolution between the given sequence and the reversed (flipped) version of the conjugate of the sequence.The conjugate operation is not needed if the input sequence is real.

## Method 3: Auto-correlation using Toeplitz matrix

Auto-correlation sequence can be found using Toeplitz matrices. An example for using Toeplitz matrix structure for computing convolution is given here. The same technique is extended here, where one signal is set as input sequence and the other is just the flipped version of its conjugate. The conjugate operation is not needed if the input sequence is real.

## Method 4: Auto-correlation using FFT/IFFT

Auto-correlation sequence can be found using FFT/IFFT pairs. An example for using FFT/IFFT for computing convolution is given here. The same technique is extended here, where one signal is set as input sequence and the other is just the flipped version of its conjugate.The conjugate operation is not needed if the input sequence is real.

Note that in all the above cases, due to the symmetry property of auto-correlation function, the center element represents $$R_{xx}(0)$$.

## Construction the Auto-correlation Matrix

Auto-correlation matrix is a special form of matrix constructed from auto-correlation sequence. It takes the following form.
$$\begin{bmatrix} R_{xx}(0) & R_{xx}^*(1) & R_{xx}^*(1) & \cdots & R_{xx}^*(N-1) \\ R_{xx}(1) & R_{xx}(0) & R_{xx}^*(1) & \cdots & R_{xx}^*(N-2) \\ R_{xx}(2) & R_{xx}(1) & R_{xx}(0) & \cdots & R_{xx}^*(N-3) \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ R_{xx}(N-1) & R_{xx}(N-2) & R_{xx}(N-3) & \cdots & R_{xx}(0) \end{bmatrix}$$

The auto-correlation matrix is easily constructed, once the auto-correlation sequence $$R_{xx}(0), R_{xx}(1),…, R_{xx}(N-1)$$ is known. The auto-correlation matrix $$R_x$$ is a $$Hermitian$$ matrix as well as a $$Toeplitz$$ matrix. This property is exploited in the following Matlab code for constructing the Auto-Correlation matrix.

$$R_x=\begin{bmatrix} 17 & 8+6i & 2+4i \\ 8-6i & 17 & 8+6i \\ 2-4i & 8-6i & 17 & \end{bmatrix}$$