From: Paul Brossier Date: Thu, 15 Nov 2018 01:03:02 +0000 (+0100) Subject: [fft] fix reconstruction for odd sizes (fftw only) X-Git-Tag: 0.4.8~59^2~1 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=5a703bdbe5426d3328311e60db0a33bd34a951d1;p=aubio.git [fft] fix reconstruction for odd sizes (fftw only) --- diff --git a/src/spectral/fft.c b/src/spectral/fft.c index 0ca467c8..e3a2895c 100644 --- a/src/spectral/fft.c +++ b/src/spectral/fft.c @@ -493,11 +493,22 @@ void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) { compspec->data[i]); } #endif - if (compspec->data[compspec->length/2] < 0) { - spectrum->phas[spectrum->length - 1] = PI; +#ifdef HAVE_FFTW3 + // for even length only, make sure last element is 0 or PI + if (2 * (compspec->length / 2) == compspec->length) { +#endif + if (compspec->data[compspec->length/2] < 0) { + spectrum->phas[spectrum->length - 1] = PI; + } else { + spectrum->phas[spectrum->length - 1] = 0.; + } +#ifdef HAVE_FFTW3 } else { - spectrum->phas[spectrum->length - 1] = 0.; + i = spectrum->length - 1; + spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i], + compspec->data[i]); } +#endif } void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) { @@ -507,8 +518,19 @@ void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) { spectrum->norm[i] = SQRT(SQR(compspec->data[i]) + SQR(compspec->data[compspec->length - i]) ); } - spectrum->norm[spectrum->length-1] = - ABS(compspec->data[compspec->length/2]); +#ifdef HAVE_FFTW3 + // for even length, make sure last element is > 0 + if (2 * (compspec->length / 2) == compspec->length) { +#endif + spectrum->norm[spectrum->length-1] = + ABS(compspec->data[compspec->length/2]); +#ifdef HAVE_FFTW3 + } else { + i = spectrum->length - 1; + spectrum->norm[i] = SQRT(SQR(compspec->data[i]) + + SQR(compspec->data[compspec->length - i]) ); + } +#endif } void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {