forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 11:17 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Understanding Cross-Correlation using ALGLIB
PostPosted: Tue Dec 20, 2011 2:40 am 
Offline

Joined: Tue Dec 20, 2011 2:34 am
Posts: 4
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


Top
 Profile  
 
 Post subject: Re: Understanding Cross-Correlation using ALGLIB
PostPosted: Tue Dec 20, 2011 3:04 am 
Offline

Joined: Tue Dec 20, 2011 2:34 am
Posts: 4
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?


Top
 Profile  
 
 Post subject: Re: Understanding Cross-Correlation using ALGLIB
PostPosted: Tue Dec 20, 2011 1:23 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Understanding Cross-Correlation using ALGLIB
PostPosted: Wed Dec 21, 2011 2:33 am 
Offline

Joined: Tue Dec 20, 2011 2:34 am
Posts: 4
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?


Top
 Profile  
 
 Post subject: Re: Understanding Cross-Correlation using ALGLIB
PostPosted: Wed Dec 21, 2011 8:42 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Understanding Cross-Correlation using ALGLIB
PostPosted: Wed Dec 21, 2011 5:37 pm 
Offline

Joined: Tue Dec 20, 2011 2:34 am
Posts: 4
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group