From: jogging on
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
From: ImageAnalyst on
I'm not sure what dshift is since you didn't give any code. If there
is no shift then the peak will be at length/2 where length is 2*length
(signal1) since correlation gives a longer vector. Otherwise the peak
will be the shifted number of pixels away from the length/2 pixel.
From: jogging on
On Dec 23, 10:14 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> I'm not sure what dshift is since you didn't give any code.  If there
> is no shift then the peak will be at length/2 where length is 2*length
> (signal1) since correlation gives a longer vector.  Otherwise the peak
> will be the shifted number of pixels away from the length/2 pixel.

Sorry. I only post part of my message.

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