From: jogging on
On Dec 23, 9:23 pm, Sebastian Doht <seb_d...(a)lycos.com> wrote:
> jogging schrieb:
>
>
>
> > Hi,
> >     I am trying to determine the signal shift by correlation method..
> > The following is the matlab code:
> > %case 1
> > Signal1 = zeros(1,32);
> > Signal1(3:13) = 8;
> > Signal2 = zeros(1,32);
> > Signal2(1:11) = 8;
>
> > Idft1=fft(Signal1,32);
> > Idft2=fft(Signal2,32);
>
> > fnorm=(Idft1.*conj(Idft2))/sum( sum( abs(Idft1.*conj(Idft2)) ) );
> > rfnorm=ifft(fnorm,32);
> > [rmax,idxmax]=max(rfnorm(:));
> > dshift=idxmax(1);
>
> > %case 2
> > Signal1 = zeros(1,32);
> > Signal1(3:13) = 8;
> > Signal2 = zeros(1,32);
> > Signal2(5:15) = 8;
>
> > Idft1=fft(Signal1,32);
> > Idft2=fft(Signal2,32);
>
> > fnorm=(Idft1.*conj(Idft2))/sum( sum( abs(Idft1.*conj(Idft2)) ) );
> > rfnorm=ifft(fnorm,32);
> > [rmax,idxmax]=max(rfnorm(:));
> > dshift2=idxmax(1);
>
> > fnorm=(Idft2.*conj(Idft1))/sum( sum( abs(Idft2.*conj(Idft1)) ) );
> > rfnorm=ifft(fnorm,32);
> > [rmax,idxmax]=max(rfnorm(:));
> > dshift3=idxmax(1);
> > display('end!');
>
> > For case 1, dshift = 3;
> > For case 2, dshift = 31;
> > In the matlab the index of an vector start at 1.
> > The actual shift should be dshift minus one.
>
> > In case 1, signal2 should be right shift by 2 to be same as signal1.
> > In case 2, signal2 should be left shift by 2 to be same as signal1.
> > For the ease of programming, I expect dshift can have a sign to
> > indicate
> > the shift direction.
>
> > The method I am going to use is:
> > If (dshift<  length/2)
> >      actual shfit = dshift;
> > else
> >      actual shift = length - dshift.
>
> > But here I don't understand why length/2 can be used to decide
> > the shift direction.
> > Is there any theory behind it?
> > Thanks.
>
> > Regards
> > Jogging
>
> I did not try your code, but you probably messed up because you did not
> pad Signal1 and Signal2 with zeros to length(Signal1)+length(Signal2).
> Therefore you performed circular convolution instead of linear convolution.
> If you're MATLAB includes the Signal Processing Toolbox you can
> alternatively use xcorr() instead of convolving by hand.

Thanks, Sebastian
I don't perform convolution actually, as in the matlab code.
In fact, the program is about phase correlation.
The following website provides the information.
http://en.wikipedia.org/wiki/Phase_correlation

In my matlab code, the fft is one dimension.
In fact, I project the image in the horizon and vertical direction,
and then perform phase correlation.

Regards
Jogging