c++ - cross correlation on mbed -


i'm having trouble cross correlation. can tell me mistake ?

i'm trying delay in order angle person talking. project base on sound localization using 2 pieces of sparkfun microphone , lpc1768.

#include "mbed.h" #include "math.h"  #define sample_period 60 #define sample 10 #define pi  3.1416 #define sos 34300 //cm/s #define sampledelay 20  serial pc(usbtx, usbrx); digitalout myled(led1); analogin  rightmic(p16); analogin  leftmic(p19); busout    unused(p15,p17,p18,p20);  timer t,t1;  float max1=0.0;  double max; double min; float min1 = 3.3; float left_results[sample]; float right_results[sample]; int k,ndelays,delay; int max=0;   int indexmax=0; int delaymax; int count;  void correlate(float left_results[] , float right_results[]) {         ndelays=2*sampledelay+1;         float correlation[ndelays];         delaymax=2*sampledelay;         for(int j=0;j<ndelays;j++)         {             correlation[j]=0;             delay=-sampledelay+j;             for(int i=0;i<sample;i++)             {                 k=i+delay;                 if(k<0) //negative                     k+=sample;                  if(k>(sample-1)) //positive                     k-=sample;                 correlation[j]+=(left_results[i]*right_results[i]);             }             if(correlation[j]>max)             {                  max=correlation[j];                 indexmax=j;                 delaymax=delay;             }             pc.printf("correlation[%i]=%f\n\r>",j,correlation[j]);             pc.printf("max=%f\n\r>",max);             pc.printf("delaymax=%d\n\r>",delaymax);         }          pc.printf("correlation: delay=%d\n\r>",delaymax);  } int main()  {        max = 0.0;     min = 3.3;     t.start();     (int i=0; i<sample; i++)     {         while(t.read_ms()<i*sample_period)// wait until next sample time....         {             left_results[i]=leftmic.read();             right_results[i] = rightmic.read();              if (right_results[i] > max)                  max = right_results[i];             if (right_results[i] < min)                  min = right_results[i];             if (left_results[i] > max)                  max = left_results[i];             if (left_results[i] < min)                  min = left_results[i];                 }      t.reset();     max=max*3.3;     min=min*3.3;     pc.printf(" max=%0.3f, min=%0.3f\n\r",max,min);     max=0.0;     min=3.3;     }      correlate(left_results , right_results); } 


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -