forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 7:28 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  [ 4 posts ] 
Author Message
 Post subject: Trouble with corrr1d and convr1d
PostPosted: Tue Dec 23, 2014 4:21 pm 
Offline

Joined: Tue Dec 23, 2014 3:57 pm
Posts: 2
I'm currently working on making a C# program that can calculate the lag between two audio files and their correlation and alglib seems like the perfect solution to help me with that. Right now I have a very simple program written just to get familiar with alglib's cross correlation capabilities that simply saves the two audio wav files as byte arrays, converts the byte arrays to double arrays and passes these double arrays into the corrr1d method. My problem is that the corrr1d method just returns an array of NaN values. I dug into the source code for the corrr1d method and found that it uses the convr1d method and this is where the NaN values are coming from. The array that it returns is just NaN values. Is there something that I must do to the double arrays before passing them into the corrr1d method or anything else I might be forgetting? Also the double arrays contain very extreme values (-8.5 E 253 and 1.5 E -308 for example), maybe there is a limit to the values that alglib can handle? Any help would be greatly appreciated.

My simple program:

Double[] result;
String audioFile= Path to audio file;
String refAudioFile = path to reference audio file;
Byte[] audioByteData = File.ReadAllBytes(audioFile);
Byte[] refAudioByteData = File.ReadAllBytes(refAudioFile);
double[] audioData = new double[audioByteData.Length/8];
double[] refAudioData = new double[refAudioByteData.Length/8];
for(int i = 0;i<audioData.Length;i++){
audioData[i] = BitConverter.ToDouble(audioByteData,i*8);
}
for(int i = 0;i<refAudioData.Length;i++){
refAudioData[i] = BitConverter.ToDouble(refAudioByteData,i*8);
}
alglib.corrr1d(audioData, audioData.Length, refAudioData, refAudioData.Length,out result);


Top
 Profile  
 
 Post subject: Re: Trouble with corrr1d and convr1d
PostPosted: Thu Dec 25, 2014 8:24 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Hello!

It is hard to tell anything definite without debugging your code, but most likely reason is that you have values with extreme magnitudes. As you told, from 10^-308 to 10^253. High end (10^253) is most probable source of errors - every time it is squared we get INF, which becomes NAN after 1-2 floating point operations. I recommend you to normalize your data before passing them to ALGLIB.


Top
 Profile  
 
 Post subject: Re: Trouble with corrr1d and convr1d
PostPosted: Sun Dec 28, 2014 6:03 pm 
Offline

Joined: Tue Dec 23, 2014 3:57 pm
Posts: 2
Thanks for your response, that sounds like it is the cause of the problem I'm having. I took a step back from the audio portion of my problem and I'm trying to work with the corrr1d function with just simple double arrays, but the results I'm getting are still not correct (for the most part). My question is whether the cross correlation capabilities of alglib will only work properly if the pattern is completely contained within the signal. I've ran the function on a couple of different arrays and this seems to be the case. For example:

double[] Signal = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
double[] Pattern = new double[] { 4, 5, 6, 7, 8, 9, 10, 11, 12 };
alglib.corrr1d(Signal, Signal.Length, Pattern, Pattern.Length, out Result);
Result = 348 420 492 564 636 552 469 388 310 236 167 104 48...

with the highest value being at index=5, which is the correct lag. But when I run it on this example:

double[] Signal = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
double[] Pattern = new double[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
alglib.corrr1d(Signal, Signal.Length, Pattern, Pattern.Length, out Result);
Result = 962 884 803 720 636 552 469 388 310 236...

with the highest value being at index=0, which is not the result I was expecting. I was expecting the highest value to be at the same index, just with a lower correlation value. So do you know if the pattern needs to be completely contained within the signal?


Top
 Profile  
 
 Post subject: Re: Trouble with corrr1d and convr1d
PostPosted: Tue Jul 21, 2015 11:39 pm 
Offline

Joined: Tue Jul 21, 2015 11:33 pm
Posts: 1
I have the same issue as gmaser35. If the pattern is not within the signal completely, I get the max correlation value somewhere at the beginning.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 39 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group