         }
         float magnitude = mag[i];
         magAvg[i] = magAvg[i] * 0.99 + magnitude * 0.01;
-        if (magnitude > maxMag) {
-            maxMag = magnitude;
+        if (magAvg[i] > maxMag && i > 0) {
+            maxMag = magAvg[i];
             maxIndex = i;
         }
 


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

        phaseAvg[i] = norm_rads(phaseAvg[i]);
        // Serial.print("Phase    : "); Serial.println(phase);
        // Serial.print("Phase: "); Serial.println(_phase_avg);
        if (i == winningIndex && abs(phaseAvg[i]) < 0.1) {
          ret = true;
        }
    }
