@@ -40,7 +40,7 @@ ArduinoFFT<T>::ArduinoFFT(T *vReal, T *vImag, uint_fast16_t samples,
40
40
template <typename T> ArduinoFFT<T>::~ArduinoFFT (void ) {
41
41
// Destructor
42
42
if (_precompiledWindowingFactors) {
43
- delete [] _precompiledWindowingFactors;
43
+ delete[] _precompiledWindowingFactors;
44
44
}
45
45
}
46
46
@@ -142,6 +142,10 @@ void ArduinoFFT<T>::compute(T *vReal, T *vImag, uint_fast16_t samples,
142
142
#endif
143
143
}
144
144
}
145
+ // The computation result at position 0 should be as close to 0 as possible.
146
+ // The DC offset on the signal produces a spike on position 0 that should be
147
+ // eliminated to avoid issues.
148
+ vReal[0 ] = 0 ;
145
149
}
146
150
147
151
template <typename T> void ArduinoFFT<T>::dcRemoval(void ) const {
@@ -247,7 +251,7 @@ void ArduinoFFT<T>::majorPeakParabola(T *vData, uint_fast16_t samples,
247
251
248
252
// And magnitude is at the extrema of the parabola if you want It...
249
253
if (magnitude != nullptr ) {
250
- *magnitude = a * x * x + b * x + c;
254
+ *magnitude = ( a * x * x) + ( b * x) + c;
251
255
}
252
256
253
257
// Convert to frequency
@@ -270,7 +274,7 @@ void ArduinoFFT<T>::setArrays(T *vReal, T *vImag, uint_fast16_t samples) {
270
274
_oneOverSamples = 1.0 / samples;
271
275
#endif
272
276
if (_precompiledWindowingFactors) {
273
- delete [] _precompiledWindowingFactors;
277
+ delete[] _precompiledWindowingFactors;
274
278
}
275
279
_precompiledWindowingFactors = new T[samples / 2 ];
276
280
}
@@ -501,7 +505,7 @@ template <typename T> double ArduinoFFT<T>::sqrt_internal(double x) const {
501
505
#endif
502
506
503
507
template <typename T>
504
- const T ArduinoFFT<T>::_WindowCompensationFactors[10 ] = {
508
+ const T ArduinoFFT<T>::_WindowCompensationFactors[11 ] = {
505
509
1.0000000000 * 2.0 , // rectangle (Box car)
506
510
1.8549343278 * 2.0 , // hamming
507
511
1.8554726898 * 2.0 , // hann
@@ -511,7 +515,10 @@ const T ArduinoFFT<T>::_WindowCompensationFactors[10] = {
511
515
2.7557840395 * 2.0 , // blackman nuttall
512
516
2.7929062517 * 2.0 , // blackman harris
513
517
3.5659039231 * 2.0 , // flat top
514
- 1.5029392863 * 2.0 // welch
518
+ 1.5029392863 * 2.0 , // welch
519
+ // This is added as a precaution, since this index should never be
520
+ // accessed under normal conditions
521
+ 1.0 // Custom, precompiled value.
515
522
};
516
523
517
524
template class ArduinoFFT <double >;
0 commit comments