C++ mbed上的互相关

C++ mbed上的互相关,c++,mbed,C++,Mbed,我很难得到互相关。有人能告诉我我的错误在哪里吗 我试图得到延迟,以便得到这个人说话的角度。我的项目是基于使用两个sparkfun麦克风和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, USB

我很难得到互相关。有人能告诉我我的错误在哪里吗

我试图得到延迟,以便得到这个人说话的角度。我的项目是基于使用两个
sparkfun麦克风和
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();
    for (int i=0; i<SAMPLE; i++)
    {
        while(t.read_ms()<i*SAMPLE_PERIOD)// wait until the 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);
}
#包括“mbed.h”
#包括“math.h”
#定义样本周期60
#定义样本10
#定义PI 3.1416
#定义sos 34300//cm/s
#定义采样延迟20
串行pc(USBTX、USBRX);
数码输出myled(LED1);
右mic类似物(p16);
左mic类似物(p19);
未使用的总线输出(p15、p17、p18、p20);
定时器t,t1;
float max1=0.0;
双峰;
双分钟;
浮点数min1=3.3;
浮动左_结果[样本];
右浮动_结果[样本];
int k,n延迟,延迟;
int Max=0;
int indexMax=0;
int delayMax;
整数计数;
无效关联(左浮动结果[],右浮动结果[])
{
ndelays=2*SAMPLEDELAY+1;
浮动相关性[ndelays];
delayMax=2*采样延迟;

对于(int j=0;jim改进的文本格式改进的文本格式改进的文本格式