Hi guys, I have a problem of doing cross correlation in matlab. What I'm trying to do is calculate the similarity of image in order to get a location of mis matches. I do it by 'xcorr' function and compare with FFT correlation so as to compare the result. What I have done is about to be just fine, but I just realised that when I took a very short signal to be correlated with another signal, then the peak may not always be detected at where it should be. I've found out that it was because if the correlation resulting in small height of peak then there might be other location where the data has the peak higher than the peak occurs from cross correlation. To make is clear, this is the code I've tried to do; a = 2*(rand(512,1)-0.5); b = rand(512,1); for i = 1:1024; b(i) = 0; end; i = 1; for h = 101:103; b(i) = a(h); i = i+1; end; c=rand(512,1); for g=1:1024; c(g)=0; end; %xcorr c=xcorr(a,b); %FFT L=max(length(a)-1,length(b)-1); NL=2*L; x=fft(a,NL); y=fft(b,NL); z=fftshift(real(ifft(x.*conj(y)))); As you can see, when the signal copied from a into the origin of b is very small, it can be a problem of peak detection, and I don't know how to solve this because I think I have set the length correctly, and the result of the correlation is exactly the same for both xcorr and FFT correlation, including the ones with peak detection problem. Please help me figure this out, Thanks. regards, Dykes
cross correlation gives wrong peak location
Started by ●February 4, 2008