Calculate time delay with Cross Correlation

Dependencies:   mbed DHT

Revision:
7:99d5e92152e0
Parent:
6:73617748bb3a
Child:
8:21e74746a067
--- a/medeltest.cpp	Thu May 11 12:31:53 2017 +0000
+++ b/medeltest.cpp	Thu May 11 12:52:56 2017 +0000
@@ -286,7 +286,7 @@
                 
                 double avgTimedelay = 0;
                 int counter = 0;
-                while(counter<1000){
+                while(counter<100){
                     int i = 0;
                     bool quit = false;
                     while(!quit) {
@@ -320,7 +320,7 @@
                     avgTimedelay =  avgTimedelay + FindTimeDelay(positionOfMaxVal_1, positionOfMaxVal_2); //microseceonds
                     counter++;
                 }
-                timedelay = avgTimedelay*0.001;
+                timedelay = avgTimedelay*0.01;
                 DebugPrintDelay(std::cout<<"avgTimedelay is: "<<timedelay<<std::endl;);
                 STATE = CALC;
                 break;
@@ -334,7 +334,7 @@
                 //int positionOfMaxVal_2 = FindPeak(2);
                 //run functions
                 //double timedelay = FindTimeDelay(positionOfMaxVal_1, positionOfMaxVal_2); //microseceonds
-                if(abs(timedelay) > micDist/calcSoundSpeed(temp, hum)){
+                if(abs(timedelay/1000000) > micDist/calcSoundSpeed(temp, hum)){         //now timedelay in sec
                     STATE = CALC_ERROR;
                     break;
                 }
@@ -344,8 +344,8 @@
                 //go to state SEND if no calc_error
 
                 Debug(
-                    std::cout << "max position for channel 1: " << positionOfMaxVal_1+1 << std::endl;
-                    std::cout << "max position for channel 2: " << positionOfMaxVal_2+1 << std::endl;
+                    //std::cout << "max position for channel 1: " << positionOfMaxVal_1+1 << std::endl;
+                    //std::cout << "max position for channel 2: " << positionOfMaxVal_2+1 << std::endl;
                     std::cout << "run FindPeak, delay is: " << timedelay << "microseconds" << std::endl;
                     std::cout << "run calcDist, delta s is: " << distance << "  millimeters" << std::endl;
                     std::cout << "run calcAngle, angle is: " << angle << " radians" << std::endl;