forum.alglib.net
http://forum.alglib.net/

Understanding Cross-Correlation using ALGLIB
http://forum.alglib.net/viewtopic.php?f=2&t=506
Page 1 of 1

Author:  dmanroyal [ Tue Dec 20, 2011 2:40 am ]
Post subject:  Understanding Cross-Correlation using ALGLIB

Hello all,

I like to compare two sample points and I recently found ALGLIB implementation of Cross Correlation. However, I just wanted to write a simple test program to see what the results would give me. I did research and read up on Cross-Correlation but I am still kind of confused as to how to read the results. Can anyhow help me?

Here is my sample program:

int main(int argc, char *argv[])
{
double signalData[SIGNAL_SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
double patternData[PATTERN_SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
real_1d_array signal;
real_1d_array pattern;
real_1d_array corrResult;

signal.setcontent(SIGNAL_SIZE, signalData);
pattern.setcontent(PATTERN_SIZE, patternData);

corrr1d(signal, SIGNAL_SIZE, pattern, PATTERN_SIZE, corrResult);

double *d = corrResult.getcontent();

return 0;
}

Now, what I get back from the results is the following.

[0] 285.00000000000000 double
[1] 240.00000000000000 double
[2] 196.00000000000000 double
[3] 154.00000000000000 double
[4] 115.00000000000000 double
[5] 80.000000000000000 double
[6] 50.000000000000000 double
[7] 26.000000000000000 double
[8] 9.0000000000000000 double
[9] 0.00000000000000000 double
[10] 0.00000000000000000 double
[11] 9.0000000000000000 double
[12] 26.000000000000000 double
[13] 50.000000000000000 double
[14] 80.000000000000000 double
[15] 115.00000000000000 double
[16] 154.00000000000000 double
[17] 196.00000000000000 double
[18] 240.00000000000000 double

Author:  dmanroyal [ Tue Dec 20, 2011 3:04 am ]
Post subject:  Re: Understanding Cross-Correlation using ALGLIB

So, the results provide me with how "closely" my samples are related. And this is present by the strength of the values.

However, if I want to go further and see if thw two sample points are related..could I do the following?

1) AutoCorrelate my signal data with itself. Keep the vector results, R1.
2) Cross Correlate the signal data with the pattern data. Keep vector results, R2.
3) Compare the R1 and R2 to see if they are similar or same?

Is that correct?

Author:  Sergey.Bochkanov [ Tue Dec 20, 2011 1:23 pm ]
Post subject:  Re: Understanding Cross-Correlation using ALGLIB

What did you mean when you said "two sample points are related"? I don't know how to estimate similarity between two points - with cross-correlation, only samples can be estimated.

Author:  dmanroyal [ Wed Dec 21, 2011 2:33 am ]
Post subject:  Re: Understanding Cross-Correlation using ALGLIB

Hi Sergey,

Thanks for your response. Yes, I was referring to two sample sets. So, in my code above, I set both samples to identical data sets.

So, if I am reading the results correctly, it is telling me that index 0 has the strongest value...and that would make sense. Is that correct?

Author:  Sergey.Bochkanov [ Wed Dec 21, 2011 8:42 am ]
Post subject:  Re: Understanding Cross-Correlation using ALGLIB

Yes, it is correct - when you calculate autocorrelation, first index is the largest one (it can be easily seen when you look at correlation as dot product of two N-dimensional vectors - two normalized vectors will have largest product if and only if they are equal to each other. This case corresponds to zero offset when calculating autocorrelation.

Author:  dmanroyal [ Wed Dec 21, 2011 5:37 pm ]
Post subject:  Re: Understanding Cross-Correlation using ALGLIB

Hi again. Thank you for your answer, sir. Very helpful!

I wanted to apply the comparison of my sample sets and was curious what is the best approach when there is a pattern sample in the signal sample but it is NOT EXACT. Meaning there it is appromixate but not exactly like the signal sample. Is there a good solution to say well it is not exact but it is near some tolerence that is acceptable for my application?

So, I find strongest coefficient offset from the cross correlation of my sample data and my pattern data. The sample data does contain an approximate of my pattern data....can I just take compare the correlation result (starting at the strongest value offset) with some degree of tolerence and use that for determining that the signal matches the pattern?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/