I am confused by the phase behavior of my FFT. I'm trying to get the phase of the fundamental harmonic with the usual arctan. The Phase alternates 180 degrees on odd/even samples. Am I doing something wrong or is this just an unadvertised feature of the FFT. Can I fix this? Background: FFT: 512 point 16 bit integer, 8051 8 bit cpu, 24mSec time Windows: Hamming, Blackman-Harris, Flattop Signal: 20-40Hz rpm dependent Source: Engine vibration 1000-3000 rpm Sampling: phase locked with rotation, about 300-700 samples/sec Oversampling: 256 times and average (lots of time left on 2nd CPU) Goal: first 6 harmonics log magnitude, fundamental mag & phase. Thanks JY

# FFT alternating phase problem

Started by ●June 15, 2009

Reply by ●June 16, 20092009-06-16

On Jun 15, 7:43�am, "jyquist" <jo...@iaw.com> wrote:> I am confused by the phase behavior of my FFT. I'm trying to get the phase > of the fundamental harmonic with the usual arctan. The Phase alternates 180 > degrees on odd/even samples. Am I doing something wrong or is this just an > unadvertised feature of the FFT. Can I fix this?Try the double input fuction arctan2. Hope this helps. Greg

Reply by ●June 16, 20092009-06-16

On Jun 16, 2:04�am, Greg <he...@alumni.brown.edu> wrote:> On Jun 15, 7:43�am, "jyquist" <jo...@iaw.com> wrote: > > > I am confused by the phase behavior of my FFT. I'm trying to get the phase > > of the fundamental harmonic with the usual arctan. The Phase alternates 180 > > degrees on odd/even samples. Am I doing something wrong or is this just an > > unadvertised feature of the FFT. Can I fix this? > > Try the double input function arctan2. >his phase function might already be doing that. i think the solution to the problem (if you're using MATLAB or Octave) is fftshift(). you take your chunk of signal, you might window it so most of the action is in the middle of the chunk. when it goes into the FFT, this tone burst is centered in time at the n=N/2 bin, you want it centered at 0, and remember the later half is just like negative time (or frequency). delaying the signal by N/2 samples causes it to be multiplied in the other domain by exp(j*2*pi*(N/2)*k/N) or exp(j*pi*k) or (exp(j*pi))^k or (-1)^k so swap your left and right halves before the FFT. don't reverse the samples inside each half. just a quickie swap. r b-j

Reply by ●June 16, 20092009-06-16

>On Jun 15, 7:43=A0am, "jyquist" <jo...@iaw.com> wrote: >> I am confused by the phase behavior of my FFT. I'm trying to get thephas=>e >> of the fundamental harmonic with the usual arctan. The Phase alternates1=>80 >> degrees on odd/even samples. Am I doing something wrong or is this justa=>n >> unadvertised feature of the FFT. Can I fix this? > >Try the double input fuction arctan2. > >Hope this helps. > >GregThanks for the idea. I am working in 8051 assembly and wrote the four quadrant arctan about 20 years ago and have been using it ever since. The application I wrote it for uses it some times 1000+ times per second. I wrote the FFT in assembly too. It is an ordinary radix-2 form. I wrote it in Pascal floating point first then converted to integers using the range and overflow checking to monitor its behavior. I then wrote it in 8051 assembly and dumped the results to a file for comparison with the Pascal version. I use Excel to plot results. This is a very valuable trick when programming in waveform world. Each intermediate pass was tested not just the final result. Even though any screwup up stream propagates trash downstream. Pointer and index action was tracked too. Once working the program was then optimized about tripling its speed. The result was a 500% speed improvement and a 600% reduction in memory used compared to C. When square root and log were used the C difference was over 1200%. The harmonic I am looking at looks like a traditional peak when root sum of squares is done. Prior to that it in real/Im form it looks like a 3 cycle oscillation taking about 8 points. Both real and imaginary look alike but not necessarily the same size of course. Arctan the even peaks and you get one angle, the odd peaks you get angle+180. The numbers and angle make sense so I believe the arctan is working.

Reply by ●June 16, 20092009-06-16

>On Jun 16, 2:04=A0am, Greg <he...@alumni.brown.edu> wrote: >> On Jun 15, 7:43=A0am, "jyquist" <jo...@iaw.com> wrote: >> >> > I am confused by the phase behavior of my FFT. I'm trying to get theph=>ase >> > of the fundamental harmonic with the usual arctan. The Phasealternates=> 180 >> > degrees on odd/even samples. Am I doing something wrong or is thisjust=> an >> > unadvertised feature of the FFT. Can I fix this? >> >> Try the double input function arctan2. >> > >his phase function might already be doing that. > >i think the solution to the problem (if you're using MATLAB or Octave) >is fftshift(). > >you take your chunk of signal, you might window it so most of the >action is in the middle of the chunk. when it goes into the FFT, this >tone burst is centered in time at the n=3DN/2 bin, you want it centered >at 0, and remember the later half is just like negative time (or >frequency). delaying the signal by N/2 samples causes it to be >multiplied in the other domain by exp(j*2*pi*(N/2)*k/N) or exp(j*pi*k) >or (exp(j*pi))^k or (-1)^k > >so swap your left and right halves before the FFT. don't reverse the >samples inside each half. just a quickie swap. > >r b-j >My signal is somewhat sinusoidal with the second harmonic about 15 db down and the third about 20 db down. The window process centers the peak in the middle of the input sample buffer. I tried putting the window peak 50% left so sample 0 was the peak. Of course it wrapped around so the rest of the peak was at the end of the buffer. This did create an interesting distortion. Pardon my ignorance but I don't understand n=3DN/2 or exactly what you mean by swap left and right, even though English is my first and only language. Thank you all for taking an interest in problem. JY

Reply by ●June 17, 20092009-06-17

On Jun 16, 4:49�pm, "jyquist" <jo...@iaw.com> wrote:> >On Jun 16, 2:04=A0am, Greg <he...@alumni.brown.edu> wrote: > >> On Jun 15, 7:43=A0am, "jyquist" <jo...@iaw.com> wrote: > > >> > I am confused by the phase behavior of my FFT. I'm trying to get the > ph= > >ase > >> > of the fundamental harmonic with the usual arctan. The Phase > alternates= > > 180 > >> > degrees on odd/even samples. Am I doing something wrong or is this > just= > > an > >> > unadvertised feature of the FFT. Can I fix this? > > >> Try the double input function arctan2. > > >his phase function might already be doing that. > > >i think the solution to the problem (if you're using MATLAB or Octave) > >is fftshift(). > > >you take your chunk of signal, you might window it so most of the > >action is in the middle of the chunk. �when it goes into the FFT, this > >tone burst is centered in time at the n=3DN/2 bin, you want it centered > >at 0, and remember the later half is just like negative time (or > >frequency). �delaying the signal by N/2 samples causes it to be > >multiplied in the other domain by exp(j*2*pi*(N/2)*k/N) or exp(j*pi*k) > >or (exp(j*pi))^k or (-1)^k > > >so swap your left and right halves before the FFT. �don't reverse the > >samples inside each half. �just a quickie swap. > > >r b-j > > My signal is somewhat sinusoidal with the second harmonic about 15 db > down > and the third about 20 db down. The window process centers the peak in the > middle of the input sample buffer. I tried putting the window peak 50% left > so sample 0 was the peak. Of course it wrapped around so the rest of the > peak was at the end of the buffer. This did create an interesting > distortion. > > Pardon my ignorance but I don't understand n=3DN/2oh, i didn't realize this. goddammit! Google is putting in some kinda extra ASCII when i say "=" (i mean to say only the equal sign), Google appends the characters "3D" to it. i dunno why, but Google Groups seems to understand that when it sticks that in, it's not supposed to be seen, so *they* do not display it. but your newsserver probably passes those characters and you client probably displays them. just remove the damn "3D" everywhere. they might do something similar to other characters. damn Google. why do they do that? this really messes me up. i do a lot of ASCII math here at comp.dsp. the bastards!> or exactly what you > mean by swap left and right, even though English is my first and only > language.of the buffer of data that you input to the FFT, put the first half of the date in the second buffer half and what was the second half into the first. swap x[n] with x[n+N/2] for n < N/2 it's what fftshift(X) does in MATLAB. r b-j

Reply by ●June 17, 20092009-06-17

robert bristow-johnson wrote:> On Jun 16, 4:49 pm, "jyquist" <jo...@iaw.com> wrote:>> Pardon my ignorance but I don't understand n=3DN/2 > > oh, i didn't realize this. goddammit! Google is putting in some > kinda extra ASCII when i say "=" (i mean to say only the equal sign), > Google appends the characters "3D" to it.It's an encoding method called "Quoted Printable" - it uses the "equal-sign" (0x3D) for an escape to a hexadecimal character code, for control characters and 8-bit Latin-1 characters. But it has to also escape the equal-sign itself, hence these "equals3D" artifacts. Don't know where it's getting injected, be it in your browser, or in Google Groups' innards, or downstream...