   uint16_t startIndex, endIndex;
   // KickFFT<int32_t>::fft(fs, 0, 4, FFT_SIZE, fftBuffer, mag, startIndex, endIndex);
   fft_phase(FS, 0, F2, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
-  bool phaseNearZero = updatePhase(mag, phase, startIndex, endIndex);
-  if (diff > 0 && !phaseNearZero) {
+  updatePhase(mag, phase, startIndex, endIndex);
+  bool phaseNearZero = false;
+  for (int i = startIndex; i < endIndex; i++) {
+      if (i == winningIndex && abs(phaseAvg[i]) < 0.1) {
+        phaseNearZero = true;
+      }
+  }
+
+  if (diff > magAvg[0]) {
     digitalWrite(LED_PIN, LOW);
 
+    Serial.print("Diff:\t"); Serial.println(diff);
     Serial.print("Phase:\t");
     for (int i = 0; i < endIndex; i++) {
       float phase = phaseAvg[i];

#include <PDM.h>
#include <KickFFT.h>

#define ACC_SIZE 64
#define FFT_SIZE 512
#define HANN_SIZE 60
#define FS (16000.0 / ACC_SIZE)
#define F2 3.5f
#define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))

      //samples--;
    }
    // clear the read count
    uint32_t duration = micros() - start;
    //Serial.print("micros: "); Serial.println(duration);
    //Serial.print("samples: "); Serial.println(samplesRead);

    samplesRead = 0;
  }
  Serial.print("max: ");
