mbed_dev
mbed_dev

Reputation: 1470

Length of FFT and IFFT

I have some signals which I add up to a larger signal, where each signal is located in a different frequency region. Now, I perform the FFT operation on the big signal with FFTW and cut the concrete FFT bins (where the signals are located) out.

For example: The big signal is FFT transformed with 1024 points, the sample rate of the signal is fs=200000.

I calculate the concrete bin positions for given start and stop frequencies in the following way:

tIndex.iStartPos = (int64_t) ((tFreqs.i64fstart) / (mSampleRate / uFFTLen));

and e.g. I get for the first signal to be cut out 16 bins. Now I do the IFFT transformation again with FFTW and get the 16 complex values back (because I reserved the vector for 16 bins).

But when I compare the extracted signal with the original small signal in MATLAB, then I can see that the original signal (is a wav-File) has xxxxx data and my signal (which I saved as raw binary file) has only 16 complex values.

So how do I obtain the length of the IFFT operation to be correctly transformed? What is wrong here?

EDIT The logic itself is split over 3 programs, each line is in a multithreaded environment. For that reason I post here some pseudo-code:

ReadWavFile(); //returns the signal data and the RIFF/FMT header information
CalculateFFT_using_CUFFTW(); //calculates FFT with user given parameters, like FFT length, polyphase factor, and applies polyphased window to reduce leakage effect
GetFFTData(); //copy/get FFT data from CUDA device
SendDataToSignalDetector(); //detects signals and returns center frequency and bandwith for each sigal
Freq2Index(); // calculates positions with the returned data from the signal detector
CutConcreteBins(position);
AddPaddingZeroToConcreteBins(); // adds zeros till next power of 2
ApplyPolyphaseAndWindow(); //appends the signal itself polyphase-factor times and applies polyphased window
PerformIFFT_using_FFTW();
NormalizeFFTData();
Save2BinaryFile();

-->Then analyse data in MATLAB (is at the moment in work).

Upvotes: 4

Views: 1847

Answers (2)

SleuthEye
SleuthEye

Reputation: 14579

If you have a real signal consisting of 1024 samples, the contribution from the 16 frequency bins of interest could be obtained by multiplying the frequency spectrum by a rectangular window then taking the IFFT. This essentially amounts to:

  1. filling a buffer with zeros before and after the frequency bins of interest
  2. copying the frequency bins of interest at the same locations in that buffer
  3. if using a full-spectrum representation (if you are using fftw_plan_dft_1d(..., FFTW_BACKWARD,... for the inverse transform), computing the Hermitian symmetry for the upper half of the spectrum (or simply use a half-spectrum representation and perform the inverse transform through fftw_plan_dft_c2r_1d).

That said, you would get a better frequency decomposition by using specially designed filters instead of just using a rectangular window in the frequency domain.

Upvotes: 2

MSalters
MSalters

Reputation: 179779

The output length of the FT is equal to the input length. I don't know how you got to 16 bins; the FT of 1024 inputs is 1024 bins. Now for a real input (not complex) the 1024 bins will be mirrorwise identical around 512/513, so your FFT library may return only the lower 512 bins for a real input. Still, that's more than 16 bins.

You'll probably need to fill all 1024 bins when doing the IFFT, as it generally doesn't assume that its output will become a real signal. But that's just a matter of mirroring the lower 512 bins then.

Upvotes: 1

Related Questions