xcorr

27 views (last 30 days)
Padma
Padma on 28 Oct 2011
Hi
could someone please explain the xcorr function more in detail. I actually tried reading the content under the help section but i could not understand properly. In the statement, [c,lags] = xcorr(x,y), could you explain what exactly is 'c' and 'lags' and could you please take an example and explain the output clearly.I am a beginner to matlab, please help me get the concept clearly.

Accepted Answer

Honglei Chen
Honglei Chen on 28 Oct 2011
C is the answer you get by dong the correlation and lags is the corresponding and what xcorr(A,B) does is really moving A around and see whether it matches up with B.
Let's use a simple example, A = [1 1] and B = [1 1]
In this case, to have non-zero correlation output, A can be moved back and force by one sample and still have some overlap with B.
So at lag = -1, you can imagine that
A: 1 1
B: 1 1
so C at this point is 1. Similarly for lag = 0, you have
A: 1 1
B: 1 1
so C at this point is 2. If you do this for every position, you get
C = [1 2 1]
lag = [-1 0 1]
i.e., if the lag is -1 (A move to the left), the correlation is 1, if A does not move, the correlation is 2, ...
From this result, A and B matches best at where the maximum of C occurs, which is lag = 0.
HTH

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!