Asked by Richard
on 30 Jan 2013

I am new to much of Matlab and signal processing, but would like to know if the Matlab function xcorr automatically zero-pads the two input vectors (in real life these would be two vectors of sampled data) to negate the end effects that usually occur when performing discrete Fourier Transforms, or in this case the discrete FFT.

*No products are associated with this question.*

Answer by Wayne King
on 30 Jan 2013

Edited by Wayne King
on 30 Jan 2013

Hi, xcorr() does pad the DFT of the input vectors to the length

2^nextpow2(2*M-1)

where M is the greater length of the two input vectors. So in the case of autocorrelation, that is clearly the length of the input vector.

In the case of cross correlation with different length vectors, M is the length of the longest vector and the shorter vector is appended with zeros in the time domain before computing the DFT.

Richard
on 30 Jan 2013

Thanks Wayne, I think I understand this but just to check: If I have two vectors the same length (say 8) then the *DFT *will pad these vectors to a length 2^15. This huge addition of zeros will negate end effects for all lags that could possibly be considered (in my example 8)?

xcorr does pad zeros, but this is simply to make the vectors the same length not to negate end effects within the DFT. That is done within the DFT function as discussed above?

Is that correct?

Wayne King
on 30 Jan 2013

Hi Richard, No, it will use an padding on the fft() of 2^nextpow2(2*8-1) or 2^4=16

nextpow2(2*8-1) is power of 2 larger than 15 or 4 in this case, since 2^4 is 16.

Opportunities for recent engineering grads.

## 0 Comments