1
votes

I wanted to know the reasoning behind a conflict ONLY in imaginary parts after IFFT.

For both my C/C++ implementation and Matlab implemenation I am doing the same following steps.

  1. My signal x is of dimension Mx1 and I perform an N-point FFT (where N = 2*M) on that signal to get N-point signal in frequency domain.
  2. Apply a customized filter on this frequency domain signal (both real and imaginary parts are changed in step).
  3. Perform in N-point inverse FFT.

Both C/C++ and Matlab implementations generate exactly the same result except the after the inverse IFFT step, imaginary parts do not match but real parts do match.

If I skip step 2 above, IFFT output of both implementation match without any problem. It is intended that my input signal to IFFT (i.e., after step2 filter) is not required to be conjugate symmetric. Infact this signal may even not be a Hermitian/symmetric.

Currently, I am using C-implementation of FFT/IFFT defined as a function smbFft available in this CPP-FILE.

Any clues, why this could be happening?

PS: It would be great, if someone can point me to an FFT implementation in C/C++, which is exactly aligned with corresponding Matlab implementation.

Thanks.

Edit: I just tested FFTW implementation instead of smbFfT (I mentioned above). FFTW implementation also has the same problem, which suggest that both of these tested C-implementations perform IFFT with hermitian symmetry setting. I need to perform the same IFFT in C as Matlab does with IFFT(..., 'nonsymmetric').

1
Post your code. Specially, beware of Matlab ' operator, which applies a complex conjugation - Luis Mendo
try FFT -> IFFT without other changes with both codes too confirm the inverse operation in your C code is correct. The results should be equal to the input (taking into account numerical precison) - Sebastien
@Sebastien I just edited above, I skip step 2 above, the output of IFFT matches with Matlab's IFFT. - user1082170
@LuisMendo Thanks for your pointer. I am aware of this operation. - user1082170
Do you use the exact same filter in both cases? I used to use fftw for C code. very efficient and robust. - Sebastien

1 Answers

1
votes

If you want a strictly real result (imaginary parts all equal to zero), then you need to make the vector be exactly conjugate symmetric (real parts mirrored, imaginary parts inversely mirrored) before the IFFT.

Matlab and C treat index 0 or 1 of arrays differently. Make sure your filter takes that into account as well.