I am trying to do some TDOA calculations with data received from three microphones. I am getting the time values from micros() after generating a sound e.g., a clap. I receive all the data I need but now when I try to calculate the TDOA with the speed of sound; I am not getting the expected values. Most of the time I just get zero but occasionally I get some random number.
How should I code this function properly?
The Function follows:
//=== The following variable are declared in the general variable area atop this program
volatile unsigned long Mach_Dist_1;
volatile unsigned long Mach_Dist_2
volatile double machInch = (machSpeed * .0254);
void machDistance() {
sensorId_1 = 0;
sensorId_2 = 0;
Mach_Dist_1 = 0;
Mach_Dist_2 = 0;
double convMS = 1000000;
// Determine which sensor was triggered first (TOA) then calculate TDOA of the other two sensors.
if (event_Time1 << event_Time2) {
Mach_Dist_1 = ((event_Time2 - event_Time1)) / convMS * machInch;
Mach_Dist_2 = ((event_Time3 - event_Time1)) / convMS * machInch;
sensorId_1 = 2; sensorId_2 = 3;
}
if ((event_Time2 << event_Time1) && (event_Time2 << event_Time3)) {
if (event_Time1 << event_Time3) {
Mach_Dist_1 = ((event_Time1 - event_Time2)) / convMS * machInch;
Mach_Dist_2 = ((event_Time3 - event_Time2)) / convMS * machInch;
sensorId_1 = 1; sensorId_2 = 3;
}
else if (event_Time1 >> event_Time3) {
Mach_Dist_1 = ((event_Time3 - event_Time2)) / convMS * machInch;
Mach_Dist_2 = ((event_Time1 - event_Time2)) / convMS * machInch;
sensorId_1 = 3; sensorId_2 = 1;
}
}
if (event_Time3 << event_Time2) {
Mach_Dist_1 = ((event_Time2 - event_Time3)) / convMS * machInch;
Mach_Dist_2 = ((event_Time1 - event_Time3)) / convMS * machInch;
sensorId_1 = 2; sensorId_2 = 1;
}
}