From 7059599c5923ca8a70fbcd44d97c5f051537f9b4 Mon Sep 17 00:00:00 2001 From: Enrique Condes Date: Fri, 19 Apr 2024 00:15:53 +0800 Subject: [PATCH] Skip the spike on bin 0 instead of deleting it --- src/arduinoFFT.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/arduinoFFT.cpp b/src/arduinoFFT.cpp index c49fb76..43b328b 100644 --- a/src/arduinoFFT.cpp +++ b/src/arduinoFFT.cpp @@ -142,10 +142,6 @@ void ArduinoFFT::compute(T *vReal, T *vImag, uint_fast16_t samples, #endif } } - // The computation result at position 0 should be as close to 0 as possible. - // The DC offset on the signal produces a spike on position 0 that should be - // eliminated to avoid issues. - vReal[0] = 0; } template void ArduinoFFT::dcRemoval(void) const { @@ -427,7 +423,9 @@ template void ArduinoFFT::findMaxY(T *vData, uint_fast16_t length, T *maxY, uint_fast16_t *index) const { *maxY = 0; - *index = 0; + // A signal with a DC offset produces a spike on bin 0 that should be ignored. + // Start the search on bin 1. + *index = 1; // If sampling_frequency = 2 * max_frequency in signal, // value would be stored at position samples/2 for (uint_fast16_t i = 1; i < length; i++) {