diff --git a/src/modules/gyro_fft/GyroFFT.cpp b/src/modules/gyro_fft/GyroFFT.cpp index 248ebbcf705..32006d33380 100644 --- a/src/modules/gyro_fft/GyroFFT.cpp +++ b/src/modules/gyro_fft/GyroFFT.cpp @@ -439,12 +439,6 @@ void GyroFFT::FindPeaks(const hrt_abstime ×tamp_sample, int axis, q15_t *ff // FFT output buffer is ordered [real[0], imag[0], real[1], imag[1], real[2], imag[2] ... real[(N/2)-1], imag[(N/2)-1] for (uint16_t bucket_index = 0; bucket_index < (2 * _imu_gyro_fft_len - 1); bucket_index = bucket_index + 2) { - const float real = fft_outupt_buffer[bucket_index]; - const float imag = fft_outupt_buffer[bucket_index + 1]; - - const float fft_magnitude_squared = real * real + imag * imag; - bin_mag_sum += fft_magnitude_squared; - const float freq_hz = (bucket_index / 2) * resolution_hz; @@ -452,6 +446,12 @@ void GyroFFT::FindPeaks(const hrt_abstime ×tamp_sample, int axis, q15_t *ff && (freq_hz >= _param_imu_gyro_fft_min.get()) && (freq_hz <= _param_imu_gyro_fft_max.get())) { + const float real = fft_outupt_buffer[bucket_index]; + const float imag = fft_outupt_buffer[bucket_index + 1]; + + const float fft_magnitude_squared = real * real + imag * imag; + bin_mag_sum += fft_magnitude_squared; + for (int i = 0; i < MAX_NUM_PEAKS; i++) { if (fft_magnitude_squared > peak_magnitude[i]) { peak_magnitude[i] = fft_magnitude_squared;