DSPRelated.com
Forums

Phase of FFT compared to phase of Sinusoid

Started by Unknown March 21, 2006
peter.moreton@gmail.com wrote:
> Thanks guys, I have worked out the problem. > > When i did fft(cos(2 Pi x/16)) with x=0 to 15, the phase was correct. > > My problem was coming from the fact that my frequency was not an > integer number of wavelengths over the range.
One way of looking at phase results is that the FFT is really reporting the average phase as referenced to the center of the FFT aperature (you may have to negate the the real and/or imaginary parts depending on where you set your zero phase reference), not the origin. If you start a synthetic signal at zero phase at the start of the aperature, and there is some remainder phase at the end (which will be the case if you don't have an exact integer number of cycles within the aperature), then the phase in the middle will be half the remainder, with equal and opposite relative phase errors on either side of center cancelling out. To make it easy to always get some constant phase FFT result no matter what the frequency, try generating your test waveforms from the center of the window outwards (e.g. from -t/2 to 0 to t/2 , instead of from 0 to t ) IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
peter.moreton@gmail.com wrote:
> Thanks guys, I have worked out the problem. > > When i did fft(cos(2 Pi x/16)) with x=0 to 15, the phase was correct. > > My problem was coming from the fact that my frequency was not an > integer number of wavelengths over the range.
One way of looking at phase results is that the FFT is really reporting the average phase as referenced to the center of the FFT aperature (you may have to negate the the real and/or imaginary parts depending on where you set your zero phase reference), not the origin. If you start a synthetic signal at zero phase at the start of the aperature, and there is some remainder phase at the end (which will be the case if you don't have an exact integer number of cycles within the aperature), then the phase in the middle will be half the remainder, with equal and opposite relative phase errors on either side of center cancelling out. To make it easy to always get some constant phase FFT result no matter what the frequency, try generating your test waveforms from the center of the window outwards (e.g. from -t/2 to 0 to t/2 , instead of from 0 to t ) IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
in article 1143172935.819523.68600@u72g2000cwu.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/23/2006 23:02:

> One way of looking at phase results is that the FFT is > really reporting the average phase as referenced to the > center of the FFT aperature (you may have to negate the > the real and/or imaginary parts depending on where you > set your zero phase reference), not the origin.
i don't get that, Ron. i'm equating "FFT" to "DFT" for mathematical purposes. an FFT is a fast method of computing the DFT. in the DFT the phase of any component is the phase relative to x[0], not x[N/2]. if you want it relative to the center, you have to do that "fftshift()" (a MATLAB function that i would call "fftswap" or "swaphalves") before applying it to the DFT. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article 1143172935.819523.68600@u72g2000cwu.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/23/2006 23:02:

> One way of looking at phase results is that the FFT is > really reporting the average phase as referenced to the > center of the FFT aperature (you may have to negate the > the real and/or imaginary parts depending on where you > set your zero phase reference), not the origin.
i don't get that, Ron. i'm equating "FFT" to "DFT" for mathematical purposes. an FFT is a fast method of computing the DFT. in the DFT the phase of any component is the phase relative to x[0], not x[N/2]. if you want it relative to the center, you have to do that "fftshift()" (a MATLAB function that i would call "fftswap" or "swaphalves") before applying it to the DFT. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article 1143172935.819523.68600@u72g2000cwu.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/23/2006 23:02:

> One way of looking at phase results is that the FFT is > really reporting the average phase as referenced to the > center of the FFT aperature (you may have to negate the > the real and/or imaginary parts depending on where you > set your zero phase reference), not the origin.
i don't get that, Ron. i'm equating "FFT" to "DFT" for mathematical purposes. an FFT is a fast method of computing the DFT. in the DFT the phase of any component is the phase relative to x[0], not x[N/2]. if you want it relative to the center, you have to do that "fftshift()" (a MATLAB function that i would call "fftswap" or "swaphalves") before applying it to the DFT. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article 1143172935.819523.68600@u72g2000cwu.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/23/2006 23:02:

> One way of looking at phase results is that the FFT is > really reporting the average phase as referenced to the > center of the FFT aperature (you may have to negate the > the real and/or imaginary parts depending on where you > set your zero phase reference), not the origin.
i don't get that, Ron. i'm equating "FFT" to "DFT" for mathematical purposes. an FFT is a fast method of computing the DFT. in the DFT the phase of any component is the phase relative to x[0], not x[N/2]. if you want it relative to the center, you have to do that "fftshift()" (a MATLAB function that i would call "fftswap" or "swaphalves") before applying it to the DFT. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
robert bristow-johnson wrote:
> in article 1143172935.819523.68600@u72g2000cwu.googlegroups.com, Ron N. at > rhnlogic@yahoo.com wrote on 03/23/2006 23:02: > > > One way of looking at phase results is that the FFT is > > really reporting the average phase as referenced to the > > center of the FFT aperature (you may have to negate the > > the real and/or imaginary parts depending on where you > > set your zero phase reference), not the origin. > > i don't get that, Ron. i'm equating "FFT" to "DFT" for mathematical > purposes. an FFT is a fast method of computing the DFT. > > in the DFT the phase of any component is the phase relative to x[0], not > x[N/2]. if you want it relative to the center, you have to do that > "fftshift()" (a MATLAB function that i would call "fftswap" or "swaphalves") > before applying it to the DFT.
It seems to work differently for single sinusoids that are not at bin center frequencies. Synthesize one that has zero phase at sample 0 and the fft results will show a non-zero phase in the nearest bin, and a phase changing with frequency (until you hit another bin center). Synthesize a sinusoid that has even or odd symmetry about sample n/2 and it will show up as a pi/2 multiple, depending on the symmetry, and completely independent of the single sinusoids frequency. Only when referenced to sample n/2 is the phase completely independant of analog frequency after a FFT/DFT transform. So I think the in general case, the DFT/FFT phase is really referenced to sample n/2, with a fixed reference rotation back to sample 0 depending on bin number (even or odd), which is why a sample 0 reference seems to work, but only when assuming only bin center frequencies exist. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
in article 1143184207.713932.128110@j33g2000cwa.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/24/2006 02:10:

> So I think the in general case, the DFT/FFT phase is really > referenced to sample N/2,
no. since the DFT is an operation that literally imposes periodicity or circularity on the input data, there is no qualitative difference between boundaries between N/2-1 and N/2 or between N-1 and N (or 0).
> with a fixed reference rotation back > to sample 0 depending on bin number (even or odd),
that even/odd thing is because you're referencing at N/2. half the time you'll be right, the other half you'll be off by 180 degrees.
> which is why a sample 0 reference seems to work, but only when > assuming only bin center frequencies exist.
so when the sinusoid is just a teeny milli-smidgen off of the center frequency, there is some kind of step function that makes this work totally differently? Ron, i'll be stepping out for a couple of days, but this is a problem that can be solved mathematically (even for the case where the frequency is not dead center for the bin). the "y-axis" for the input sequence goes through x[0] and, it is against that the time of that "y-axis" that the phase is measured against. now it is *true* (but i don't think the definition) that the DFT is equal to the N equally spaced samples of the DTFT of the same sequence of x[n] that is ZERO-extended (not periodically extended). ask yourself what the DTFT of that zero-extended sequence is for the case that the frequency is not an integer multiple of 1/N. use a complex sinusoid exp(j*2*pi*f0 + theta) where f0 is not M/N. find the peak (it will be the middle of the sinc() function), and evaluate the phase of the DTFT at that peak. i'll bet you that it is theta. now, for the discrete samples in the freq domain that are adjacent to that peak (at indices floor(N*f0) and floor(N*f0)+1) the phase will be different, but not that much different. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article 1143184207.713932.128110@j33g2000cwa.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/24/2006 02:10:

> So I think the in general case, the DFT/FFT phase is really > referenced to sample N/2,
no. since the DFT is an operation that literally imposes periodicity or circularity on the input data, there is no qualitative difference between boundaries between N/2-1 and N/2 or between N-1 and N (or 0).
> with a fixed reference rotation back > to sample 0 depending on bin number (even or odd),
that even/odd thing is because you're referencing at N/2. half the time you'll be right, the other half you'll be off by 180 degrees.
> which is why a sample 0 reference seems to work, but only when > assuming only bin center frequencies exist.
so when the sinusoid is just a teeny milli-smidgen off of the center frequency, there is some kind of step function that makes this work totally differently? Ron, i'll be stepping out for a couple of days, but this is a problem that can be solved mathematically (even for the case where the frequency is not dead center for the bin). the "y-axis" for the input sequence goes through x[0] and, it is against that the time of that "y-axis" that the phase is measured against. now it is *true* (but i don't think the definition) that the DFT is equal to the N equally spaced samples of the DTFT of the same sequence of x[n] that is ZERO-extended (not periodically extended). ask yourself what the DTFT of that zero-extended sequence is for the case that the frequency is not an integer multiple of 1/N. use a complex sinusoid exp(j*2*pi*f0 + theta) where f0 is not M/N. find the peak (it will be the middle of the sinc() function), and evaluate the phase of the DTFT at that peak. i'll bet you that it is theta. now, for the discrete samples in the freq domain that are adjacent to that peak (at indices floor(N*f0) and floor(N*f0)+1) the phase will be different, but not that much different. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article 1143184207.713932.128110@j33g2000cwa.googlegroups.com, Ron N. at
rhnlogic@yahoo.com wrote on 03/24/2006 02:10:

> So I think the in general case, the DFT/FFT phase is really > referenced to sample N/2,
no. since the DFT is an operation that literally imposes periodicity or circularity on the input data, there is no qualitative difference between boundaries between N/2-1 and N/2 or between N-1 and N (or 0).
> with a fixed reference rotation back > to sample 0 depending on bin number (even or odd),
that even/odd thing is because you're referencing at N/2. half the time you'll be right, the other half you'll be off by 180 degrees.
> which is why a sample 0 reference seems to work, but only when > assuming only bin center frequencies exist.
so when the sinusoid is just a teeny milli-smidgen off of the center frequency, there is some kind of step function that makes this work totally differently? Ron, i'll be stepping out for a couple of days, but this is a problem that can be solved mathematically (even for the case where the frequency is not dead center for the bin). the "y-axis" for the input sequence goes through x[0] and, it is against that the time of that "y-axis" that the phase is measured against. now it is *true* (but i don't think the definition) that the DFT is equal to the N equally spaced samples of the DTFT of the same sequence of x[n] that is ZERO-extended (not periodically extended). ask yourself what the DTFT of that zero-extended sequence is for the case that the frequency is not an integer multiple of 1/N. use a complex sinusoid exp(j*2*pi*f0 + theta) where f0 is not M/N. find the peak (it will be the middle of the sinc() function), and evaluate the phase of the DTFT at that peak. i'll bet you that it is theta. now, for the discrete samples in the freq domain that are adjacent to that peak (at indices floor(N*f0) and floor(N*f0)+1) the phase will be different, but not that much different. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."