The fact that you don't get corr=1 at the expected location is because the normalization in Mathlab (and possibly also in other packages) is not performed correctly. A cross correlation is in fact a "sliding dot product" between the two data arrays. To get -1<=corr<=1 one can get the cos(theta) related to the dot product, which means that for each window one has to normalize the unnormalized corr by dividing by the product of the two vector lengths that is currently in use.
You can find the correct formula in eq. (1) of the following article