0
$\begingroup$

I try to make graph/print for magnitudes and phase shifts for impulse response calculated by FFT. For magnitude everything works perfect, but for phase shift I get some strange curve for higher frequencies. I can't figure out why. Could anyone help me?

I calculate phase shift by that: atan2(fftOutput.imag(),fftOutput.real()) * 180.0/M_PI;

And for simply impulse, like: impulse[1024] = { 1, 0, 0, 0 ... 0 }

with no processing I expect straight line (phase shift for all freq bin should be zero).

But I get something like that (I drawn it in paint, cause I can't run my app at the moment, but it looks almost exactly the same):

enter image description here

Why is that?

$\endgroup$
5
  • $\begingroup$ What fft implementation do you use? $\endgroup$
    – Matt L.
    Sep 10, 2018 at 10:25
  • $\begingroup$ I am not sure what are you asking for. Sometime ago I implemented various types of FFT by my own (I mean I wrote my own FFTs alghorithms). For that case I use Radix-2 for $2^L$ buffer sizes, and for else sizes I use mixed radix FFT. For both cases I get the same issue. $\endgroup$
    – pajczur
    Sep 10, 2018 at 10:36
  • 2
    $\begingroup$ Well, there must be a bug somewhere, right? So I'm asking the questions that you could also ask yourself in order to narrow down where the bug is. If the output of the atan2 function is nonsensical, there are two options: either its input (i.e., the fft output) is nonsensical, or the atan2 implementation is wrong. So why don't you just do the same computation with some software (Matlab/Octave/Python etc.) that has a relatively high chance of giving the correct result and check the difference with your implementation? $\endgroup$
    – Matt L.
    Sep 10, 2018 at 10:46
  • $\begingroup$ Ok I will try, but I don’t know how to use other FFTs algorithms such as FFTw. I just wanted to use in hurry something that I know. But it looks it’s something wrong. $\endgroup$
    – pajczur
    Sep 10, 2018 at 10:50
  • $\begingroup$ The documentation is straightforward with examples. There are double and float versions of the libraries prebuilt for widows, Mac, Linux on pc, arm.... $\endgroup$
    – user28715
    Sep 10, 2018 at 13:16

1 Answer 1

0
$\begingroup$

Something is wrong with your FFT. This looks like your input signal is either time reversed or shifted (circular) by one sample to the left.

$\endgroup$
2
  • $\begingroup$ Ok, I am not sure about input impulse signal. So to explain it clearly, let’s suppose I have buffer size 1024, and I want to make fft for impulse response, then: 1) do I need signal like 1, 0, 0, 0... at all 1023 zeros? OR 2) do I need signal like 1, 0, 0... at all 511 zeros, again 1, 0, 0... 511 zeros? I am asking that because for me there are some misunderstanding with Nyquist freq $\endgroup$
    – pajczur
    Sep 10, 2018 at 15:17
  • $\begingroup$ Ok You are totally right. Now I figure it out. There was problem with my signal, I had signal with two impulses on the beginning. Instead just one I had 1, 1, 0, 0, 0, 0.... $\endgroup$
    – pajczur
    Sep 10, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.