Calculate time delay with Cross Correlation

Dependencies:   mbed DHT

Files at this revision

API Documentation at this revision

Comitter:
reritter
Date:
Thu May 11 14:16:58 2017 +0000
Parent:
7:99d5e92152e0
Commit message:
sm? ?ndringar

Changed in this revision

medeltest.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/medeltest.cpp	Thu May 11 12:52:56 2017 +0000
+++ b/medeltest.cpp	Thu May 11 14:16:58 2017 +0000
@@ -39,7 +39,7 @@
 double micDist = 0.15; //meters
 double threshold_1 = 0; //value when going to active mode channel 1  //old hardcoded value = 330
 double threshold_2 = 0; //value when going to active mode channel 2 //old hardcoded value = 200
-double threshold_adjust = 15;  //used to adjust threshold, + for less sensitivity, - for increased sensitivity
+double threshold_adjust = 100;  //used to adjust threshold, + for less sensitivity, - for increased sensitivity
 bool calibratedStatus = false;      //flag to make sure Nuclueo only calibrated once for background noise
 bool checkTemp = false;         //flag - true to checktemp, false to use predefined values
 int positionOfMaxVal_1;
@@ -260,7 +260,7 @@
                         blinkTime = blinkTime + 500;
                     }
                 }
-                threshold_1 = threshold_2 + threshold_adjust;
+                threshold_1 = threshold_1 + threshold_adjust;
                 threshold_2 = threshold_2 + threshold_adjust;
 
                 //Calibrate temp and hum
@@ -286,7 +286,7 @@
                 
                 double avgTimedelay = 0;
                 int counter = 0;
-                while(counter<100){
+                while(counter<500){
                     int i = 0;
                     bool quit = false;
                     while(!quit) {
@@ -299,11 +299,11 @@
                             capturestamps_1[0] = timestamps_1[i];
                             capture_2[0] = channel_2[i];
                             capturestamps_2[0] = timestamps_2[i];
-                            for(int i = 1; i < captureLength; i++) {
-                                capture_1[i] = getAudioValue(mic1);
-                                capturestamps_1[i] = t.read_us();
-                                capture_2[i] = getAudioValue(mic2);
-                                capturestamps_2[i] = t.read_us();
+                            for(int j = 1; j < captureLength; j++) {
+                                capture_1[j] = getAudioValue(mic1);
+                                capturestamps_1[j] = t.read_us();
+                                capture_2[j] = getAudioValue(mic2);
+                                capturestamps_2[j] = t.read_us();
                             }
                             quit = true;
                         }
@@ -320,7 +320,7 @@
                     avgTimedelay =  avgTimedelay + FindTimeDelay(positionOfMaxVal_1, positionOfMaxVal_2); //microseceonds
                     counter++;
                 }
-                timedelay = avgTimedelay*0.01;
+                timedelay = avgTimedelay/500;
                 DebugPrintDelay(std::cout<<"avgTimedelay is: "<<timedelay<<std::endl;);
                 STATE = CALC;
                 break;