Generalized cross correlation problem

Hello everybody, I wrote a code for generilizrd cross correlation (GCC) to find the time delay between two signals but unfortunatly the index of the maximum value is always zero ,how can I solve this problem. This is my code :
fChannel1 = fft(x1);
fChannel2 = fft(x2);
conjFChannel2 = conj(fChannel2);
num = (fChannel1).*conjFChannel2;
den = abs((fChannel1).*(conjFChannel2));
fGeneralized = num./(den);
generalizedCrossCorrelation = ifft(fGeneralized);
[maxcorr max_index] = max(fftshift(generalizedCrossCorrelation));
Any help in this regard will be appreciated.

4 Comments

You forgot to supply the data (x1 and x2).
Actully I tried many signals at the first they give me the index equal to zero where it shouldn't be zero ,then I tried other signals it give index not equal to zero but it also give a wrong index, e.g: t=0:.001:1; x1=sin(2*pi*t); x2=cos(2*pi*t); the index=502 when use the generalized cross correlation but when I used the the cross correlation code the max_index=1219,this is the code of cross correlation: cross_correlation=xcorr(x1,x2); [max_cross max_index_cross]=max(cross_correlation);
You do know that the cross correlation of two signals has a length that is equal to both the lengths of the component signals added together, don't you? Did you take that into account?
Yes I know,and I took it in account.now in the following code I assume the auto correlation for x1 is the reference(in both cases the cross correlation and generalized correlation) then I took the diifference between the index at the auto(in each cross correlation and generalized correlation) and the index_maximum of correlation output between x1 and x2, where the this difference in indexes should be equal whatever the used method,this is the code: t=0:.001:1; x1=sin(2*pi*t); x2=cos(2*pi*t); fChannel1 = fft(x1); fChannel2 = fft(x2); conjFChannel2 = conj(fChannel2); num = (fChannel1).*conjFChannel2; den = abs((fChannel1).*(conjFChannel2)); fGeneralized = num./den; generalizedCrossCorrelation = ifft(fGeneralized); [maxcorr1 max_index1] = max(fftshift(generalizedCrossCorrelation));
conjFChannel1 = conj(fChannel1); num = (fChannel1).* conjFChannel1; den = abs((fChannel1).*(conjFChannel1)); fGeneralized = num./den; generalizedCrossCorrelation = ifft(fGeneralized); [maxcorr index_auto_generalized] = max(fftshift(generalizedCrossCorrelation));%Auto generalized correlation
diff1=abs(max_index1- index_auto_generalized);
Y1=xcorr(x1,x2); [max2 index2]=max(Y1);
Y2=xcorr(x1); [max_auto index_auto]=max(Y2); diff2=abs(index2-index_auto); %diff2 should be equal diff1 whatever yhe used method

Sign in to comment.

Answers (0)

Asked:

on 1 Apr 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!