## resolution of the phase information from the fft Started by 4 months ago11 replieslatest reply 4 months ago248 views

I understand that the frequency resolution for an N point fft sampled at Fs is Fs/N.  However, I'm confused regarding the phase information. For instance, if I sample a signal at 1MHz  for 256 samples, the frequency resolution will be ~3.9kHz per bin.  But say I want to use the FFT to determine phase delay of a given signal,  and I wanted a 1 deg resolution on the phase. I'm struggling to understand the relationship between the phase information obtained from the FFT and the FFT parameters.

Thank you.

[ - ] Think of phase resolution and amplitude resolution as being related.   Neither has anything to do with the sample rate.   Both have to do with the number of effective bits, which has to do with both the number of effective bits in any ADC(s) present as well as any processing gain that has been realized by the time you wish to measure amplitude or phase.  Phase is just an angle calculated from the I and Q components of an analytic signal, so you can determine the effective phase resolution from the number of bits.   e.g., if you only have one bit each of I and Q, you have 90 degrees of phase resolution.   As you increase the number of bits in each, the phase resolution will increase.

I hope that helps a little bit.

[ - ] Thank you for your resonse.  Perhaps I didn't ask the right question, or I don't understand your response fully- so please bear with me.

I want determine the phase shift of a sinusoidal current at a known frequency measured as the voltage drop across a resistor.  I figured I could take the FFT of the samples and obtain the phase information from it--but then I couldn't understand how the phase info would be affected by sample rate, etc..So, I don't have I and Q samples, I have voltage samples of a sinusoid.

Is your  response still applicable in this scenario? --if so, could you please elaborate some more?  For instance, I don't  get how  phase information is not related to time (ie, sample rate in some way), when phase information is by its very nature the postion of the signal at a point in time relative to the signal's cycle or period.  Intuitively, if I sampled faster, I would expect to be able to resolve the phase difference between two signals of the same frequency --in the time domain at least.  For instance, I think cross correlation would work well to determine this phase difference (between a refernce signal an the phase-sifted signall), and the time step would be related to the sample rate, correct?   Why would this then not translate to the frequency damain as well when in fact, I think correlation (and convolution) can be obtained via a Fourier Xform....I'm confused!
[ - ] If you were intending to take an FFT, the phase information in any particular FFT output bin, for example one with a lot of energy for an input sinusoid, will be the angle between the I and Q samples in that bin.  FFTs are generally complex-valued at the output, even if the input was real-valued.   The angle represented in the output will be the difference in phase between the input signal and the FFT reference functions, essentially the FFT window if it isn't zero-padded.

As you mention, the FFT essentially does a cross-correlation between the input signal and the reference (basis) function.  FFT sinusoidal basis functions start at zero phase at the beginning of the FFT window, so an input sinusoid matching a bin frequency will indicate phase difference with the basis function by the phase of the FFT output bin at that frequency.

[ - ] You are not wrong. If I understand your question you have a signal and want to know at a given time what is that signal's phase, correct? In most books this is effectively related "symbol time" which is to say the points in time where you want to note what the phase is of the signal. If you wanted 1 degree of phase resolution on every cycle for a given wave, your sampling would have to be 360x the frequency after converting the waveform to baseband. So for a 1MHz signal, 360MHz of sampling after you mixed down to DC. Whether or not you will be able to resolve the phase difference accurately does mean you need enough bits of signal to represent the angle.

This is used in QPSK to encode 2 bits, so each bit pair represents a 90 degree phase shifts offset by 45 degrees. QPSK however will send several cycles at the phase of interest. (homework problem on why they do this :-)) You could similarly encode 3 bits with 45 degree phase shifts, etc. But the higher values will require higher oversampling to resolve the phase data.

I came up with what I think of as a fairly novel way to finesse this based on some ideas that Marty Graham shared with me years ago but haven't yet done any field trials to see if I can actually demodulate it over the air.

[ - ] If you are after sinusoid phase from FFT then you got correct replies from Slartibartfast. This phase can show delay within one cycle and as such I believe the number of samples per cycle will have some impact on phase accuracy.

If you are after absolute delay then it is something else. The sinusoid will wrap up after 1 cycle and phase will not show absolute delay. You need to do time domain correlation with a reference. For this purpose a sinusoid is not good for delay measurement as its correlation has slow gradual peak.

[ - ] You are in essence asking a nonsensical question.  I hope the following explanation helps.  You didn't specify a real or a complex signal, so I will illustrate with the real signal, which is the more complicated case.  The concepts are the same.

$$x[n] = M \cos( \alpha n + \phi )$$

Using the angle addition formulas (with complex you get just a product).

$$x[n] = M \left[ \cos( \alpha n ) \cos( \phi ) - \sin( \alpha n ) \sin( \phi ) \right]$$

Multiply out.

$$x[n] = \left[ M \cos( \phi ) \right] \cos( \alpha n ) - \left[ M \sin( \phi ) \right] \sin( \alpha n )$$

Recognize the form:

$$x[n] = A \cos( \alpha n ) + B \sin( \alpha n )$$

If we can solve for A and B, then we find M and phi from those.

$$M = \sqrt{ A^2 + B^2 }$$

and

$$\phi = \text{atan2} (-B,A)$$

To solve this, we can recognize the sine and cosine functions as basis vectors, and solve using Linear Algebra.  Call the x[n] vector plain x, the sine S, and the cosine C.

$$x = A C + B S$$

Dot these with the basis vectors and you get.

$$x \cdot C = A \left( C \cdot C \right) + B \left( S \cdot C \right)$$

$$x \cdot S = A \left( C \cdot S \right) + B \left( S \cdot S \right)$$

This gives you two equations, two unknowns.  The nice thing about the trig functions is that if the interval is a whole number of cycles, the mixed dot product term will be zero and you get:

$$x \cdot C = A \left( C \cdot C \right)$$

$$x \cdot S = B \left( S \cdot S \right)$$

When you align your DFT frame on a whole number of cycles, this is precisely the DFT calculation for a given bin.  The first equation is the real part, and the second the imaginary.

From these you can calculate A and B directly.  This is why everybody says the angle of the bin value represents the phase, and that is how you read the value.

The more difficult calculation is when your signal is not a whole number of cycles within your DFT frame.  That is what my blog articles are mostly about.  I recommend you have a look at my overview article and read the related articles to your situation.

"Overview of my Articles"

Now, addressing the resolution issue.  Calculating the frequency by the nearest bin is known as "Coarse Resolution".  With a high SNR signal, the frequency can be determined to a small fraction of the bin width.  This is called "Fine Resolution".

For very small differences, each increment of error in your frequency represents a $$\pi \left(1-1/N \right)$$ change in your calculated phase value.  So, phase resolution is roughly one third as good as frequency resolution in the fine domain.
Hope this helps.

P.S.  In a bin calculation, since the sine function is negated in the DFT definition you have:

$$\phi = \text{atan2} (Im,Re)$$

[ - ] To elaborate a little bit on what it seems you are trying to accomplish.  For a pure complex tone, a shift in the phase causes tandem rotations of all the bins.  If it is a whole integer frequency, all the other bins will be zero, so rotating them is moot.  However, if there is "leakage", it will rotate in tandem as well.  For a real valued tone this is only approximately true (as in not exactly, it will still be quite accurate) near the peak bin.  The further from DC or Nyquist you frequency is, the better the approximation.

I am assuming from the one degree resolution that you have a phase difference that is smaller than a cycle, otherwise what the others say is true.

Suppose you have a stereo pair of microphones listening on a steady tone source and you are trying to calculate direction of arrival using the phase difference.  In that case you don't even have to worry about the frequency or whether it is close to a bin or not.  All the bins in the peak bin area will twist almost the exact same amount.  The difference in the angle between the left channel bin and the corresponding right channel bin will give you the phase difference of the two arriving captures.

Due to the exponential nature of the unit circle, you can divide one bin value by the other and the angle of the quotient will be your phase difference.  If it is quite small, the atan2 can be replace with atan and you are probably good with the first few terms of the atan series.

If you don't get what I am saying, I recommend my "A Recipe for a Basic Trigonometry Table", particularly the source code in Appendix I.
[ - ] Thank you for taking the time to explain all this. I still don't get it, but I will...it'll just take me some time.  I'm not sure what is nonsensical about my question -- I wanted to understand how sampling rate affected the phase resolution of the FFT.

Since I'm dealing with voltages and currents, I'm talking about real signals.  Say I generate a voltage sinsoid at 1MHz, and I measure the voltage across a resistor to derive the current through the circuit, and I am interested in determining the phase shift between these two signals (I know the phase of voltage signal since I'm generating it and it is 0).  My intuition was that the faster the sample rate, the better resolution I would have in determining the phase shift between these two signal --ie, if I sampled this "current"  waveform at 360MHz, I'd get a 1 deg resolution (I think).  So, I wanted to understand how this would "show" up in the FFT or what I would have to do (in terms of sampling, Fs and number of bits, and number of points of the FFT) to improve the phase resolution in the FFT.

I didn't understand the first response I got from @Slartibartfast (and don't quite yet understand)_ that said that the sample rate doesn't factor in the phase info from the FFT, when it seemed to me like it did in the time domain.  So, at the 1MHz bin, for example, I will have a phase,$$\phi$$, from the FFT -- but how accurate is that phase and could it have been made better by sampling faster.  That was the question I was trying to ask.

I really do appreciate you guys taking the time to respond in such detail --even if I don't quite yet understand.  I'm still digesting the responses, and appreciate the references you pointed me to dig deeper into this stuff.

Thank you.

[ - ] I'm sorry, by "meaningless" I meant "it doesn't matter", not "stupid".

If you select a frame size that is a whole number of cycles in the frame, say seven.  No matter what N is, as long as it is greater than 14, the bin values for the DFT will all be zero except at bin 7 and -7, aka N-7.

For a noiseless signal, as you increase N by increasing the sampling frequency, this value will not change when you normalize it by 1/N, so it will not increase your resolution.

In an actual (avoiding the word 'real') signal, increasing the number of samples will mitigate the effect of noise.  Also, if it is not a pure tone, but has higher harmonics, increasing the sampling rate will keep higher harmonics from ending up in the same bin due to "aliasing".

For tones with frequencies in between bins, the effect of increasing N will alter the bin values.  That's were the $$(1-1/N)$$ factor comes in.  It is easier to see in the bin value formulas for a complex tone, than in a real tone.

See "DFT Bin Value Formulas for Pure Complex Tones".  (16), the whole number case, is devoid of N.  In constrast, (24) shows that the angle of bin value will rotate according to $$\phi$$ the same as (16) for a fixed frequency, but will also twist ever so slightly when N changes.  The values of $$Z_k$$ are already normalized by $$1/N$$ in the article.

A real tone can be considered the sum of two complex tones because

$$\cos( \theta ) = \frac{1}{2} e^{i \theta} + \frac{1}{2} e^{-i \theta}$$

[ - ] Let us make it simple:

-phase from FFT output is based on Re & Im amplitude so depends on bit resolution

-angle resolution depends on how many samples per cycle are at input so depends on sampling rate and location of frequency bin.

-you can be as accurate within one cycle only due to wrap up

[ - ] 