2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$
  • Your code contains magic numbers, avoid them
  • To calculate the autocorrelation, you do not add zeros. y(1+lag:end).*y(1:end-lag) would match the definition.
  • Multiplying requires your data to be binary -1 or 1, not 0 or 1. I would use a version which processes logic arrays.
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

How about xcorr(y)? The xcorr() function is part of the Signal Processing Toolbox.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I was trying to calculate by hand, actually. \$\endgroup\$ – Mauren Oct 1 '13 at 13:48
0
\$\begingroup\$

Are you trying to calculate the correlation factor or the cross correlation function?
The correlation factor is basically a normalized dot product of two vectors.
The cross correlation could be calculated using the conv function (By flipping one of the vectors).

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.