Skip to main content
20 events
when toggle format what by license comment
Apr 2, 2021 at 8:41 comment added pajczur 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.
Apr 2, 2021 at 8:25 comment added pajczur 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.
Apr 2, 2021 at 7:11 vote accept pajczur
Apr 1, 2021 at 3:15 comment added ZR Han 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.
Mar 31, 2021 at 12:29 comment added pajczur 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.
Mar 31, 2021 at 12:23 comment added ZR Han 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.
Mar 31, 2021 at 12:17 comment added pajczur 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.
Mar 31, 2021 at 12:15 comment added ZR Han 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.
Mar 31, 2021 at 12:05 comment added ZR Han 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?
Mar 31, 2021 at 11:55 comment added pajczur 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.
Mar 31, 2021 at 11:49 comment added ZR Han Not the output of FFT, but the output of IFFT. btw put math code like this $math here$
Mar 31, 2021 at 10:33 comment added pajczur And od course if there are both real and imag then this is complex number.
Mar 31, 2021 at 10:20 comment added pajczur 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?
Mar 31, 2021 at 10:17 comment added pajczur 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?
Mar 31, 2021 at 9:56 comment added ZR Han 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?
Mar 31, 2021 at 9:42 comment added pajczur 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.
Mar 31, 2021 at 9:34 comment added ZR Han Recall the definition of DFT and check here dsp.stackexchange.com/questions/53706/…
Mar 31, 2021 at 9:33 comment added pajczur 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.
Mar 31, 2021 at 9:29 comment added pajczur 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?
Mar 31, 2021 at 9:21 history answered ZR Han CC BY-SA 4.0