1

let's say we have signal in time domain. After we make FFT on it we will receive that signal in frequency domain. And as far as I know the real numbers mean magnitudes of each frequency bin, and imaginary numbers mean phase shifh of each frequency bin.

And then if we make inverse FFT we get again the the signal in time domain. And as far as I know that signal is expressed by real result of IFFT. But then what mean imaginary part of IFFT output?

And - what is also important - how to use it?

I am asking because I have problems with phase synchronising after IFFT so I wonder that maybe that imaginary part of IFFT has something to do?

What is very strange for me is that I have exactly the same algorithm and I get totally different results on two various computers.

I created the clean sine wave oscillator. And I use it to test my FFT->IFFT algorithm.

And on one machine it seems like phase is synchronised properly if my FFT->IFFT size is 4 times buffer size. I mean that for each one buffer (let's say size 512) I calculate FFT->IFFT size 2048. Where first 512 samples are my sine wave, and the rest 1536 samples are just zeros. And I get quite good results.

But on other machine with exact the same algorithm, the same buffer size 512 and the same sample rate 44100 I have phase issue that cause my signal sound awful.

I have no idea why it is happen. The only thing which come to my head is that the machine with awful IFFT signal is just slower and the awful sound is not caused by unsynchronised phase but because of gaps between each buffer. But I can't believe it while both machines are similarly powerfull.

So finally the main question is how to ensure phase is always synchronised after IFFT. And how to do that to work on all machines the same?

For any help great thanks in advance.

pajczur
  • 359
  • 3
  • 11
  • 2
    It sounds like you’ve gotten ahead of yourself. The (I)FFT is an algorithm for efficiently implementing a (I)DFT. A DFT is reversible, so if you do a DFT followed by an IDFT, your output equals your input. What does it mean if you get complex data when you were expecting real data? It means you did something wrong. Further, if you are building your own (I)FFT, you should be testing it against a known good result, such as FFTW, or an analytically obtained (I)DFT. – Dan Szabo Mar 31 '21 at 23:49

1 Answers1

1

And as far as I know the real numbers mean magnitudes of each frequency bin, and imaginary numbers mean phase shifh of each frequency bin.

No. The magnitude of the complex spectrum $|X(k)|$ means magnitude of each freqency bin, and the phase angle of the complex spectrum $\angle X(k)$ represents phase shift.

But then what mean imaginary part of IFFT output?

If the input of IFFT is conjugate symmetric, the output of IFFT must be a real signal, and vice versa, FFT of a real signal must be conjugate symmetric.

ZR Han
  • 3,228
  • 6
  • 16
  • Hmm... great thanks for your answer. Yes I was wrong with real=magnitude, imag=phase. Sorry my mistake, I've just forgot abot what you've told. But still I am not sure what exactly do you mean by "conjugate symmetric". How to ensure that symetric conjugate. And would it help with my phase issues after IFFT? – pajczur Mar 31 '21 at 09:29
  • And if magnitude is in FFT is sqrt(real^2 + imag^2) then should I use the same after IFFT to achieve each sample (time domain) proper value? Or what? At the moment it looks like just using real as a sample value works fine, only the phase issues I have. – pajczur Mar 31 '21 at 09:33
  • Recall the definition of DFT and check here https://dsp.stackexchange.com/questions/53706/result-of-conjugate-symmetry-property-of-dft – ZR Han Mar 31 '21 at 09:34
  • I will read that, thanks. What can I say now is that I've just tested sqrt(real^2 + imag^2) after IFFT for each sample in the buffer, but it gives totaly wrong results. I have something that is even not close to sine wave. – pajczur Mar 31 '21 at 09:42
  • I don't quite get your point. If I understand correctly, you are trying to enframe a sine wave with 512 samples, apply zero-padding to 2048 samples, do FFT, and then take IFFT? While you didn't do anything between FFT and IFFT, why is the output of IFFT complex? – ZR Han Mar 31 '21 at 09:56
  • hmm... This is the IFFT equation: X(n)=\frac{1}{N}\sum_{k=0}^{N-1} x(k) e^{i 2 \pi k n / N} So it is clear it contain imaginary parts. Am I wrong? – pajczur Mar 31 '21 at 10:17
  • Sorry I have no idea how to put latex code here. But the main thing here is: in IFFT equation there is imaginary part, so how you assume there is not? – pajczur Mar 31 '21 at 10:20
  • And od course if there are both real and imag then this is complex number. – pajczur Mar 31 '21 at 10:33
  • Not the output of FFT, but the output of IFFT. btw put math code like this $math here$ – ZR Han Mar 31 '21 at 11:49
  • Sorry, maybe my English is not clear. But YES output of FFT has real and imag parts, and YES the output of IFFT also has real and imag part. So both are complex. That is what I meant. But your question "...why is the output of IFFT complex?" suggests the output of IFFT has not imag part. Here is again for remind (and to test your math tags :) ) the IFFT equation: $X(n)=\frac{1}{N}\sum_{k=0}^{N-1} x(k) e^{i 2 \pi k n / N}$ so as you can see it has i which is imaginary i. – pajczur Mar 31 '21 at 11:55
  • As I said before, for a real sequence $x(n)$, its FFT $X(k)$ is conjugate symmetric, which means $X(-k) = X^*(k)$. On the other hand, if $X(k)$ satisfies conjugate symmetry property, its IFFT $x(n)$ must be real. What does your input of IFFT look like? Does it satisfy the property above? – ZR Han Mar 31 '21 at 12:05
  • The right side in the equation of IDFT has $i$ doesn't mean the left side can't be real. A simple example: for a real signal x, fft(x) is complex but ifft(fft(x)) equals to x. – ZR Han Mar 31 '21 at 12:15
  • As input to IFFT I use straight the output of FFT, which are:
    • complex numbers (with real and imag);
    • and I manualy set to zero all real and imag bins above Nequest freq (fftSize / 2);

    And such numers (both real and imag) I send to IFFT. That's my intput of IFFT. Of course I tested other solutions. For example calculating the magnitude by sqrt(real^2 + imag^2) and phase by atan2(imag, real)/fPi; and such data used as input to IFFT (where for real I use magnitude and for imag I use phase). But it also gives me wrong results.

    – pajczur Mar 31 '21 at 12:17
  • Frequency bins above fftSize/2 is the negative frequencies. FFT doesn't return frequencies above Nyquist freqency. Don't do anything, send the FFT output into IFFT and you will get the desired result. – ZR Han Mar 31 '21 at 12:23
  • The main problem here I see is that probably you think about some existing FFT algorithm, while I use my own. Yes yes yes... I know it's stupid to creating own FFT while there are planly free to use libraries like FFTW. But I am that kind of person that can't sleep if don't understand something. Maybe that's the misunderstanding from the begining. My main reason I created that thread was not how to use FFT but more how to create it? I try to understand how it works. And due to math equations I found in books for FFT and IFFT both have output complex numbers. FFT is part of my hobby. – pajczur Mar 31 '21 at 12:29
  • OK I know you are creatting your own FFT. Let me make it clear again, the main problem is that you set all FFT bins above fftSize/2 to zero. Fourier transform (or series) for a discrete time signal is periodic - the frequency bins above fftSize/2 are negative frequencies and should be preserved. – ZR Han Apr 01 '21 at 03:15
  • Great thanks for your support. It’s all true what you’ve said but to last one comment I have doubts. I found why I have phase issue. And now I still put zeros to all freq bins above fftSize/2. And it works like a charm. – pajczur Apr 02 '21 at 08:25
  • And one could ask what was my mistake. So let me explain. Little bit It has something to do with putting zero to all freq bin above fftSize/2. I wanted to be even smarter (hah... stupid me) and set zero not only for freq bins above fftSize/2 but also to all bins corresponding to all freq above 20kHz (bin > 20000 * (44100/fftSize)) And it is still ok in my applecation, but the problem was I had the same set for IFFT output, so all somples in time domain above 20000*(44100/fftSize) was zeros. It is obvious and stupid mistake, but sometimes it is hard to find such stupid mistake in code. – pajczur Apr 02 '21 at 08:41