# FFT Phase interpretation of input signal with non-integer number of cycles in FFT window

It is known that if we take the FFT of a signal at such a frequency which has non-integer number of cycles in the sample window we get different value of phase even if the original signal was at phase 0 (reference to cos wave). Looking at the time-domain signal can we predict what the phase output is going to be i.e. as there any intuitive sense behind the phase that is reported?

• Start with this one, then read the supporting articles, and you will have a theoretical foundation as well as exact answers: dsprelated.com/showarticle/787.php – Cedron Dawg Jan 7 at 13:15
• The "Qualitative Analysis" section of dsprelated.com/showarticle/771.php should also be helpful. Particularly, this pearl: "When the k value goes from below f to above f, the sign on the denominator changes and the numerator stays roughly the same. This explains why the bin values on either side of f are nearly opposite each other. This also happens around (N−f)." Way underappreciated since most DFT analysis gets done with the magnitudes. This is for a sweeping $k$ with a fixed $f$ (cycles per frame). – Cedron Dawg Jan 8 at 21:48

The link in the comment is for exact answers for real tones.

Intuition (derived from understanding the theory) is pretty simple.

A real valued pure tone is actually the sum of two complex pure tones. I like to use the cosine function for pure real tones. I use $$\alpha$$ in my articles for the radians per sample frequency value. $$\omega$$ is commonly used in the literature.

$$x[n] = M \cos( \alpha n + \phi ) = M \cdot \frac{e^{i( \alpha n + \phi )}+e^{-i( \alpha n + \phi )}}{2}$$

This muddles things up a bit. Pure complex tones are simpler.

For a pure complex tone with a whole number of cycles in the frame (say $$k$$), the $$k$$th DFT bin value is

$$X[k] = NM e^{i \phi }$$

This is also true for $$k+1$$, $$k+2$$, etc. So if you do a frequency sweep, each time you hit a whole number of cycles in the frame, the corresponding bin value has the same phase value. Simple.

For frequencies between the bin values, the bins will rotate. This can be seen from eq (24) in this article:

\begin{aligned} X[k] & = M e^{ i \left[ -\delta (N-1) / 2 + \phi \right] } \cdot \frac{ \sin( \delta N / 2 ) }{ \sin( \delta / 2 ) } \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i \left[ -\delta (N-1) / 2 \right] } \right] \cdot \left[ \frac{ \sin( \delta N / 2 ) }{ N \sin( \delta / 2 ) } \right] \\ \end{aligned}

Note, this equation shows that all the "leakage" bins for non-integer frequencies will also rotate in parallel as the phase in the signal is shifted.

Since the analysis was for a sweep of $$k$$ for a fixed $$f$$, I defined $$\delta$$ as:

$$\delta = ( k - f ) \frac{2\pi}{N}$$

For every change of $$f$$ (cycles per frame) or $$k$$ (bin index) by 1, the resulting $$\delta N$$ changes by $$2\pi$$.

The bin value equation can be manipulated some:

\begin{aligned} X[k] &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i \left[ (f-k) \frac{N-1}{N} \pi \right] } \right] \cdot \left[ \frac{ \sin \left( (f-k) \pi \right) }{ N \sin\left( \frac{f-k}{N} \pi \right) } \right] \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i \left[ (f-k) \frac{N-1}{N} \pi \right] } \right] \cdot \left[ \frac{ \frac{ \sin \left( (f-k) \pi \right) }{(f-k) \pi} }{ \frac{ \sin\left( \frac{f-k}{N} \pi \right) }{\frac{f-k}{N} \pi} } \right] \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i (f-k) \left( 1 - \frac{1}{N}\right) \pi } \right] \cdot \left[ \frac{ \operatorname{sinc} \left( (f-k) \pi \right) }{ \operatorname{sinc} \left( \frac{f-k}{N} \pi \right) } \right] \\ \end{aligned}

Where "sinc" is the unnormalized version:

$$\operatorname{sinc} (x) = \frac{\sin(x)}{x}$$

This clearly breaks the equation into three parts:

1. The default bin value

2. The twisting caused by being off bin.

3. The magnitude adjustment for being off bin.

The last version shows how the discrete case differs from the continuous case. The value of the denominator in the last factor approaches 1 as N goes to infinity.

None of these equations are dependent on N being even or odd.

Now, turning to the real tone case. In the vicinity of a peak, whether on the positive or negative frequency side, one of the constituent complex tones is dominant. Therefore the real value tone will have approximately the same behavior in the neighborhood of the peak. Near the DC and Nyquist bins, the dominance is least.

(I also use a $$1/N$$ normalized DFT in my articles. I've converted the equations in this answer to the more common unnormalized definition.)

Suppose the $$k=p$$ is the peak bin with an angle of $$\theta$$.

\begin{aligned} \theta &= \arg(X[p]) \\ &= \phi + \left[ (f-p) \frac{N-1}{N} \pi \right] \\ \end{aligned}

This shows you the relationship between the phase angle of the signal ($$\phi$$ observed in the time domain) and the angle of the peak bin ($$\theta$$). For complex pure tones, it is exact. For real pure tones, it is an approximation which is most accurate near half the Nyquist frequency. $$(f-p)$$ will range from -0.5 to 0.5.

Usually, we are trying to do the reverse, i.e. figure out the signal's phase angle from the DFT bin values.

$$\phi = \theta - \left[ (f-p) \frac{N-1}{N} \pi \right]$$

Then even/odd issue comes in when you trace these rotations all the way around the ring, so to speak.

\begin{aligned} X[k+N] &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i \left[ (f-k-N) \frac{N-1}{N} \pi \right] } \right] \cdot \left[ \frac{ \sin \left( (f-k-N) \pi \right) }{ N \sin\left( \frac{f-k-N}{N} \pi \right) } \right] \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i (f-k) \frac{N-1}{N} \pi } e^{ i (1-N) \pi } \right] \\ & \cdot \left[ \frac{ \sin \left( (f-k) \pi \right) \cos \left( N \pi \right) - \cos \left( (f-k) \pi \right) \sin \left( N \pi \right) } { N \sin\left( \frac{f-k}{N} \pi \right) \cos\left( \pi \right) - N \cos\left( \frac{f-k}{N} \pi \right) \sin\left( \pi \right) } \right] \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i (f-k) \frac{N-1}{N} \pi } (-1)^{ 1-N } \right] \cdot \left[ \frac{ \sin \left( (f-k) \pi \right) (-1)^{ N } } { N \sin\left( \frac{f-k}{N} \pi \right) (-1) } \right] \\ &= \left[ N M e^{ i \phi } \right] \cdot \left[ e^{ i (f-k) \frac{N-1}{N} \pi } \right] \left( (-1)^{ 1-N } \right) \\ &\cdot \left[ \frac{ \sin \left( (f-k) \pi \right) } { N \sin\left( \frac{f-k}{N} \pi \right) } \right] \left( (-1)^{ N-1 } \right) \\ &= X[k] \left( (-1)^{ 1-N } \right) \left( (-1)^{ N-1 } \right) \\ \end{aligned}

The first negative one to a power factor comes from the rotation factor, and the second comes from the magnitude factor. For odd N, these are both one. For even N, they are both negative one. So, if you are looking at the magnitude factor only, it seems there is a mismatch for even N values. This generally shows up when somebody uses the sinc function as an approximation (for large N) and follows it around the circle. For an infinite size circle (the limit) it doesn't matter. The sinc function reaches zero then.

There is a circular waveform discontinuity at sample 0 of an FFT input (to sample N-1), if it isn’t exactly integer periodic in aperture. However, if the waveform is continuous at sample N/2, then the phase can be measured at that point.

You can measure phase at the halfway point by doing an FFTshift, or by flipping the phase of every odd numbered FFT output bin. If you know, or can estimate the frequency, then if you estimate the phase at sample N/2, you can use the frequency and phase at a known point to compute the phase at any other point in time. Including at the beginning of the original sample data window.

This answer is for even N Lengths of FFT. (Dawg may have a better answer for odd lengths.)