How to find the period of a noisy signal using MATLAB's $\tt xcorr$?
You are getting that result because you are taking into account other maxima that do not correspond to the points you are actually looking for.

When you call findpeaks() with no other parameter than the input signal, you are taking into account all the points marked with a blue arrow. To determine the period, you just want those inside red circles.



Note that, due to the noise, inside some red circles there are more than just one point considered as a peak. That is undesired as well.

You have to put a restriction to find peaks such that they are at least 160 samples away from each other (in this case, due to your signal and its correlation). You can see that if you replace 

[~,locs]=findpeaks(ac);

with

[pks,locs] = findpeaks(ac,'MinPeakDistance',300); %Or any number &gt;160

the period will be the expected one.