# Understanding the phase in DFT

Although using regularly the FFT algorithm to compute DFTs, I don't really understand how the phase part works.

e.g. in Matlab:

Fs=1e3;
t=linspace(0,1,Fs);
f=1;
x=sin(2*pi*f*t);
X=fft(x);
Xphase=angle(X);
Xmag=abs(X);


I know that "phase" can mean a shift (an angular) shift of a wave with respect to another. But I can't really say what the values in each point of Xphase mean. Can someone explain ? e.g. I was trying with this simple example of a pure sine wave (which shouldn't be dephased I guess?)

Xphase contains values between -3.1385 to 3.1416 so roughly from -180 degrees to 180 degrees... why?

• I find this very informative. It is on the continuous Fourier transform though it is easy to understand this for DFT as well. – havakok Jul 17 at 14:06

Suppose you have a sinusoidal that has a whole number of cycles ($$k$$) in your DFT frame containing $$N$$ sample points. It can be parameterized like this:

$$x[n] = A \cos \left( \left( k\frac{2\pi}{N}\right)n + \phi \right)$$

If you take the $$1/N$$ normalized DFT of this (FFT is a DFT that is computed efficiently), all the bins will be zero except for bins $$k$$, and $$(N-k)$$. With MATLAB, bin $$k$$ occurs at index $$k+1$$.

$$X[k] = \frac{A}{2} e^{i\phi}$$

and

$$X[N-k] = \frac{A}{2} e^{-i\phi}$$

So, you can see, in the ideal case of a pure tone with a whole number of cycles in the frame, the phase angle of the DFT bin corresponds directly to the phase argument in the signal.

The values from $$-\pi$$ to $$\pi$$ are by convention and are measured in radians. This range covers every possible angle.

If you don't have a whole number of cycles, you can find my simplified bin value formulas here: https://www.dsprelated.com/showarticle/771.php

https://gizmodo.com/pentagon-ordered-to-tell-congress-if-it-weaponized-tick-1836391549

In the time domain, a $$2\pi$$ change in the phase represents the shift of an entire cycle, which can also be considered one wavelength. Shift it by $$\pi$$ (popularly known as a 180 degree shift), and you effectively invert it. Shift it back and forth by $$\pi/2$$ and sine becomes cosine and vice versa.

Maybe this will spark an understanding:

$$cos( ft + \phi ) = \cos( ft ) \cos( \phi ) - \sin( ft ) \sin( \phi ) = a \cos(ft) + b \sin(ft)$$

So, fiddling with the phase adjusts how much cosine vs the sine is in the tone within that reference frame.

What I described above is the bedrock connection between the phase in the time domain and the phase in a DFT bin for real valued signals.

The relationship between this shifting in the time domain and the angle in the corresponding bin is one-to-one for sinusoidals with a whole number of cycles in a DFT frame.

$$a = \cos(\phi)$$

$$b = -\sin(\phi)$$

$$\frac{b}{a} = -\frac{\sin(\phi)}{\cos(\phi)} = -\tan(\phi)$$

Mix in an $$i^2$$ and you got bin interpretation.

• Thanks for the answer. However, I am looking for a more intuitive understanding of what the phase angle really means , e.g., what does it "represent as a shift" , e.g. the values in angle(x), represent a shift w.r.t ...what? – Machupicchu Jul 17 at 19:33
• Thanks for your effort. However, there is still something that bothers me. I m not sure i m able to formulate it in a meaningful way but roughly: ok i understand with your formula that a phase shift in cos of freq f is related to a weighted sum of sine and cos. But how does that explain that we need/use the phase part in Fourier transform? The imaginary part which is not the same.as the phase which is actually arctan(im/re)..? – Machupicchu Jul 17 at 20:25
• @Machupicchu You're welcome. The last blurb should help you out. I'm leaving for a while. This might help too: dsp.stackexchange.com/questions/59305/… – Cedron Dawg Jul 17 at 20:33
• Ok thanks. In fact i think using the trig circle can help me too. (And the matrix vector interpretation of the DFT (1D dft) each component of the vector Wx (given W is dft matrix, x is signal), would be a complex number z = rexp(iphi) and so r is magnitude (abs(z)) and phi is angle(z) so considering the phase, which i m interested in, phi would then be (here for just 1 component) the amount of phase shift from.the pure real cosine of the given frequency k for that z component ... if you see what i mean?Correct ? – Machupicchu Jul 17 at 21:03
• @Machupicchu Yes. Each bin corresponds to a component with with a frequency of its bin index in cycles per frame. I recommend you read the following of my articles in this order: dsprelated.com/showarticle/754.php dsprelated.com/showarticle/1238.php dsprelated.com/showarticle/768.php dsprelated.com/showarticle/1284.php Then follow the links if needed. – Cedron Dawg Jul 17 at 21:17

If you were to change the relative phase of some FFT result bins, the place where all the peaks would line up could change, thus representing a time domain shift of some peak. The peaks or transients would be moved to occur earlier or later in the FFT window. Sometimes, an FFT analysis cares about the shape of the time domain waveforms and what time (within the FFT frame) events, peaks, or zero crossings occur. Lossless information thus requires the FFT phase.

Phase in an FFT result also contains information about symmetry: the real or cosine part represents even symmetry (about the center of the FFT aperture), the imaginary component or sine part represent anti-symmetry (an odd function). So any photo or image would get its symmetry hugely distorted without full FFT phase information.