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

Trouble with corrr1d and convr1d
http://forum.alglib.net/viewtopic.php?f=2&t=2211
Page 1 of 1

Author:  gmaser35 [ Tue Dec 23, 2014 4:21 pm ]
Post subject:  Trouble with corrr1d and convr1d

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);

Author:  Sergey.Bochkanov [ Thu Dec 25, 2014 8:24 am ]
Post subject:  Re: Trouble with corrr1d and convr1d

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.

Author:  gmaser35 [ Sun Dec 28, 2014 6:03 pm ]
Post subject:  Re: Trouble with corrr1d and convr1d

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?

Author:  zoell [ Tue Jul 21, 2015 11:39 pm ]
Post subject:  Re: Trouble with corrr1d and convr1d

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.

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