# argmax of the cross correlation

I want to find the shift between 2 signals $$\sin a$$ and $$\sin b$$ where (with Matlab code)

$$a = \{0, 1,2,3,4\}$$ $$b = a +1$$ $$\implies b = \{1,2,3,4,5\}$$ then $$\arg\max \sin a = 2$$

and $$\arg\max \sin a = 3$$ Their shift is then 1.

However if I'm trying to compute their cross correlation (using Matlab), I get the argmax at 7 and not at 1

a = 0:1:5
b = a + 1
[argvalue, argmax] = max(xcorr(sin(a), sin(b)))


What am I missing (probably something very basic... many thanks in advance)

• Welcome to SE.SP! I'm assuming your second plot is $\arg \max \sin b$ not $\arg \max \sin a$? The correlation $x$-axis will be from -5 to +5, to the 6 in your final plot should be the origin (0). – Peter K. May 19 '20 at 21:43