Thread Subject: Crosscorrelation lengths

Subject: Crosscorrelation lengths

From: Josef H

Date: 15 Mar, 2010 09:15:08

Message: 1 of 4

Hello,
I am doing cross-correlation in matlab and comparing the result with matlabs builtin 'xcorr' function. The results are pretty much the same, except that matlabs is twice the length with lots of zeros. Have I missed something important?

The way I do it is; fft - conjugate - multiply - ifft
With two signals, each with length 256, i get an output correlation result of 256 bits.

with matlab xcorr function (without any extra parameters) the result is 512 bits.

The waveforms look the same but the matlab correlation has more zeros and slopes when rising towards the peak. Does anyone know if my home-made cross correlation might be faulty?

Subject: Crosscorrelation lengths

From: Rune Allnor

Date: 15 Mar, 2010 09:21:06

Message: 2 of 4

On 15 Mar, 10:15, "Josef H" <fly...@gmail.com> wrote:
> Hello,
> I am doing cross-correlation in matlab and comparing the result with matlabs builtin 'xcorr' function. The results are pretty much the same, except that matlabs is twice the length with lots of zeros. Have I missed something important?
>
> The way I do it is; fft - conjugate - multiply - ifft
> With two signals, each with length 256, i get an output correlation result of 256 bits.
>
> with matlab xcorr function (without any extra parameters) the result is 512 bits.
>
> The waveforms look the same but the matlab correlation has more zeros and slopes when rising towards the peak. Does anyone know if my home-made cross correlation might be faulty?

Look up 'circular convolution'. When one use DFTs to compute
convolutions (cross correlation is a form of convolution)
one needs to add enough space to hold the whole result.

When convolving an M-length sequence with an N-length sequence,
the DFT length must be at least M+N-1.

Rune

Subject: Crosscorrelation lengths

From: Josef H

Date: 15 Mar, 2010 13:21:08

Message: 3 of 4

> Look up 'circular convolution'. When one use DFTs to compute
> convolutions (cross correlation is a form of convolution)
> one needs to add enough space to hold the whole result.
>
> When convolving an M-length sequence with an N-length sequence,
> the DFT length must be at least M+N-1.
>
> Rune

I see, when I do the fft with 2*N depth the result looks the exact same so thats where it differs. But the information that I loose is not very interesting so I might just keep the shorter FFT, since the results with longer FFT just results in more slopes due to the zero-padding, and I'm just interested in finding peaks, not the actual result of the convolution. It wont affect this detection of peaks as far as I can see?

Subject: Crosscorrelation lengths

From: Rune Allnor

Date: 15 Mar, 2010 13:24:46

Message: 4 of 4

On 15 Mar, 14:21, "Josef H" <fly...@gmail.com> wrote:
> > Look up 'circular convolution'. When one use DFTs to compute
> > convolutions (cross correlation is a form of convolution)
> > one needs to add enough space to hold the whole result.
>
> > When convolving an M-length sequence with an N-length sequence,
> > the DFT length must be at least M+N-1.
>
> > Rune
>
> I see, when I do the fft with 2*N depth the result looks the exact same so thats where it differs. But the information that I loose is not very interesting so I might just keep the shorter FFT, since the results with longer FFT just results in more slopes due to the zero-padding, and I'm just interested in finding peaks, not the actual result of the convolution. It wont affect this detection of peaks as far as I can see?

If you don't do the zero padding your results will
be plain wrong.

Rune

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
cross correlation Josef H 15 Mar, 2010 05:19:06
fft Josef H 15 Mar, 2010 05:19:06
xcorr Josef H 15 Mar, 2010 05:19:06
rssFeed for this Thread

Contact us at files@mathworks.com