# Is this a valid way of computing autocorrelation?

I am a beginner in Digital Signal Processing and I was trying to compute and plot an autocorrelation.

I've wrote this piece of code:

r = [zeros(2,1); y(1:98,1)];
r = r.*y;


and I wished to know if this is a valid way of computing an autocorrelation.

• To calculate the autocorrelation, you do not add zeros. y(1+lag:end).*y(1:end-lag) would match the definition.
How about xcorr(y)? The xcorr() function is part of the Signal Processing Toolbox.
The cross correlation could be calculated using the conv function (By flipping one of the vectors).