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.

asked Sep 30, 2013 at 13:57
\$\endgroup\$

3 Answers 3

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.
answered Dec 2, 2013 at 22:03
\$\endgroup\$
3
\$\begingroup\$

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

answered Oct 1, 2013 at 5:23
\$\endgroup\$
1
  • \$\begingroup\$ I was trying to calculate by hand, actually. \$\endgroup\$ Commented Oct 1, 2013 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).

answered Apr 14, 2014 at 19:04
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.