FFTW / fftw3

DO NOT CHECK OUT THESE FILES FROM GITHUB UNLESS YOU KNOW WHAT YOU ARE DOING. (See below.)
GNU General Public License v2.0
2.76k stars 667 forks source link

use fftw_plan_dft_r2c_1d get inf #249

Open ShuoShenDe opened 3 years ago

ShuoShenDe commented 3 years ago

hello,guys~ I try to used fftw_plan_dft_r2c_1d for a 2D vector. So, vector shape is (NumFrames, WindowOutHalfLength)

So ,I used fftw_plan_dft_r2c_1d in following codes: ` float fftwInForward; fftwf_complex fftwOutForward; vector test(halfNFFT); fftwInForward = (float)fftwf_malloc(sizeof(float) 2 (stft.WindowOutLength / 2.0 + 1)); fftwOutForward = (fftwf_complex)fftwf_malloc(sizeof(fftwf_complex) * stft.WindowOutHalfLength); fftwf_plan forward = fftwf_plan_dft_r2c_1d(stft.WindowOutLength, fftwInForward, fftwOutForward, FFTW_DESTROY_INPUT);

for (int frame = 0; frame < stft.NumFrames; frame++)
{
    fftwInForward[0] = filteredCepstrum[frame][0];
    for (int bin = 1; bin < nCoeff + 1; bin++) {
        fftwInForward[bin] = filteredCepstrum[frame][bin] * window[int(halfNFFT / 2) + bin - 1];
    }
    for (int bin = halfNFFT - nCoeff; bin < halfNFFT; bin++) {
        fftwInForward[bin] = filteredCepstrum[frame][bin] * window[int(halfNFFT / 2) + bin - halfNFFT];
    }
    for (int bin = nCoeff; bin < halfNFFT - nCoeff; bin++)
    {
        fftwInForward[bin] = 0;
    }

    fftw_execute(forward);

    for (int bin = 0; bin < halfNFFT; bin++) {
        filteredCepstrum[frame][bin] = exp(fftwOutForward[bin][0]);
    }

}`

However, almost all data become "nan" or "-nan". like follows: image

When I change the data type to double, some rows have several "inf" inside. image

I checked the input data(fftwInForward), there is not "inf" or "nan" inside. Does anyone know what happened?