# Phase shift problem in Fast Fourier Transform

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 = { 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): Why is that?

• What fft implementation do you use? Sep 10, 2018 at 10:25
• 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. Sep 10, 2018 at 10:36
• 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? Sep 10, 2018 at 10:46
• 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. Sep 10, 2018 at 10:50
• The documentation is straightforward with examples. There are double and float versions of the libraries prebuilt for widows, Mac, Linux on pc, arm....
– user28715
Sep 10, 2018 at 13:16