KissFFT (kiss_fftr to kiss_fftri) - How to reconstruct the original signal?

半世苍凉 提交于 2019-12-10 19:23:52

问题


I'm having some trouble understanding how to use KissFFT (1.2.9) correctly. All I am trying to achieve for now is to perform an FFT and then immediately perform an iFFT to reconstruct the original signal again. The code snippet below demonstrates what I'm doing:

void test(short* timeDomainData, int length)
{
    // Create the configurations for FFT and iFFT...
    kiss_fftr_cfg fftConfiguration = kiss_fftr_alloc( length, 0, NULL, NULL );
    kiss_fftr_cfg ifftConfiguration = kiss_fftr_alloc( length, 1, NULL, NULL );

    // Allocate space for the FFT results (frequency bins)...
    kiss_fft_cpx* fftBins = new kiss_fft_cpx[ length / 2 + 1 ];

    // FFT...
    kiss_fftr( fftConfiguration, timeDomainData, fftBins );

    // iFFT...
    kiss_fftri( ifftConfiguration, fftBins, timeDomainData );
}

What I found is that this actually crashes at run-time. I found that by dividing the size by 2 when creating the KissFFT configurations stopped the crashing:

kiss_fftr_cfg fftConfiguration = kiss_fftr_alloc( length / 2, 0, NULL, NULL );
kiss_fftr_cfg ifftConfiguration = kiss_fftr_alloc( length / 2, 1, NULL, NULL );

However, when I play the reconstructed audio data it's mostly silent with the odd crackle.

Can anyone point me in the right direction?

Many thanks, P

Edit 1: This is how I include the KissFFT header file and define the FIXED_POINT variable:

#define FIXED_POINT 16
#include "kiss_fftr.h"

This ensures that the typedef'd 'kiss_fft_scalar' type is forced to int16_t (short).

Edit 2: The target platform is Android, so I have also added the following to my Android.mk file:

LOCAL_CPPFLAGS += -DFIXED_POINT

回答1:


I noticed you are sending in shorts. Are you sure you've compiled everything to use int16_t as the DATATYPE? Sometimes a mismatch of preprocessor environments can cause a problem.

Also, the fixed point version scales downward both directions (fwd,inv). So if you expect to reconstruct your signal, you'll want to multiply things by a total of nfft. I'd recommend multiplying with saturation in two stages.

e.g. if you're doing an FFT+IFFT of size 1024, then multiply by 32 after the FFT, then again by 32 after the IFFT.




回答2:


I'm not sure about the silence, but if you're getting lots of crackles then it may because you're processing adjacent blocks independently rather than using Overlap-Add, where you effectively cross-fade between each block to get a smoother characteristic.




回答3:


I'm struggling to do the same thing in Android, haven't got it yet (see here!), but I can see a problem in your code: "fftBins" needs to be "length" size. The reason is that it is the raw transform, not the frequency magnitude/phases... I think? Or have I got it wrong?



来源:https://stackoverflow.com/questions/10934378/kissfft-kiss-fftr-to-kiss-fftri-how-to-reconstruct-the-original-signal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!