5 years, 3 months ago.

correlation problem.help!!

i;m doing a project on sparkfun microphone with lpc1768. i'm trying figure out where my mistake lies in the correlation process. coz i can't seem to determine my delay.so hopefully someone can give me a helping hand.thank you

1 Answer

5 years, 3 months ago.

I guess you try to use digitized audiosignals from left and right microphones and then find the delay to compute direction of the soundsource. You first take 1024 samples right and then 1024 samples left. You store them all but it doesnt seem like you use any of the stored samples, you just find min and max as you go along? The itg and itg1 values are always just the last samples. You sample as fast as possible so actual samplerate is undefined. The delay between left and right samples is also long and undefined because of the slow printf() operations. Dont see how you can correlate or compute delay between left and right in this setup.

Accepted Answer

i don't get what u really mean.but is it due to timer when i have to use a timer like this to have a sample rate.?

posted by faris abdat 01 Jun 2015

Your system is only going to work if the data you are performing a correlation on contains the same sounds as heard by both the left and the right microphones.

You read the right microphone a few times and store the last value in itg. You then do a printf which takes a long time, exactly how long will depend on the numbers that it is printing, and the serial port baud rate. You then read the left microphone a few times and store the last reading as itg1

Unless your microphones are a huge distance apart and the sound source just the right distance on the right you will be correlating two completely unrelated numbers.

What you need to do is store two arrays of readings that are as close to time synchronized as possible and at a known sample rate. You then correlate these arrays, not single values.

Something roughly along the lines of:

uint16_t left_results[SAMPLE_SIZE];
uint16_t right_results[SAMPLE_SIZE];

main () {
  for (int i = 0; i<SAMPLE_SIZE; i++) {
    left_results = left.read_u16(); // use the u16 versions, it's faster and we want the samples to be as close as possible in time.
    right_results = right.read_u16();
    while (timer.read_ms() < i*SAMPLE_PERIOD) { // wait until the next sample time....
  // any printfs of max/min etc can go here now that the timing critical part is over  
  correlate(left_results , right_results); // perform the correlation on the arrays of values you collected.

Since you read one microphone then the other that will skew the results slightly to one side but if you can measure this it should be possible to correct for it.

posted by Andy A 01 Jun 2015

thank you for help.i am not familiar with u16 version.i will be doing the float instead. i got stuck into a problem doing this method.if i don't place a while loop, it won't work.if i place i*sample_period it won't work too.i'm not sure why.so this is what i have done.i place a while loop and the thing is if i place the correlate out of the while loop it won't be reachable.and if i place it inside the loop, it won't correlate.but the thing is i need to correlate it once only.i'm not sure why here.a helping hand please. and to my last question can u roughly tell me how is the flow that i could get the phase of the speaker.?appreciate your help a lot.

posted by faris abdat 02 Jun 2015