 #include <PDM.h>
 #include <KickFFT.h>
 
-#define ACC_SIZE 128
-#define FFT_SIZE 256
+#define ACC_SIZE 64
+#define FFT_SIZE 512
+#define HANN_SIZE 20
+#define FS (16000.0 / ACC_SIZE)
+#define F2 4.0f
+#define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))
 
 #define LED_PIN 13
 



void addToFFT(float val) {
  // Serial.println(val);
  for (int i = FFT_SIZE - 1; i > 0; i--) {
    fftBuffer[i] = fftBuffer[i-1];
  }
  fftBuffer[0] = val;
  float fs = 16000/ACC_SIZE;
  float mag[20];
  float phase[20];
  uint16_t startIndex, endIndex;
  // KickFFT<int32_t>::fft(fs, 0, 4, FFT_SIZE, fftBuffer, mag, startIndex, endIndex);
  fft_phase(fs, 0, 4, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
  updatePhase(mag, phase, startIndex, endIndex);
  float hz = fs * _phaseRateAverage / 2 / PI;
  // Serial.print("endIndex: "); Serial.println(endIndex);
  // Serial.print("BPM: "); Serial.println(hz * 60);
  //Serial.print("radsPerUpdate: "); Serial.println(_phaseRateAverage);


  sht30.begin();
  PDM.onReceive(onPDMdata);
  PDM.begin(1, 16000);

  // init hann window
  for (int i = 0; i < HANN_SIZE ; i++) {
    float sinVal = sin(PI * (i + HANN_SIZE) / (2.0f * HANN_SIZE));
    hannWindow[i] = sinVal * sinVal;
  }

}

void loop(void) {
