# Autocorrelation Computation with MATLAB

I have done the computation of the autocorrelation of a sequence (vector), here called "frame", and I have plotted it. Here the code:

The resulting graph is:

I do not understand the position of the peak in this graph: I know that the peak of the autocorrelation should be in the origin, why is it there?

The x axis is simply an index number, and this is showing your the correlation for leading and trailing shifts. The shift at index 80 is lag = 0, the origin you are interested in. Type help(xcorr) in Matlab to get further detail in how to return the lag. Following that, if you do the following you will get the result you are looking for:

r, lag = xcorr(frame, frame);
figure()
plot(lag, r)


I did it as shown above to highlight how to return lag from xcorr specifically while minimizing change to your code, but xcorr(frame) will return the same result as xcorr(frame,frame) so can be further simplified for the case of autocorrelation.