PDA

View Full Version : FFT alternating phase problem


jyquist
06-15-2009, 12:43 PM
I am confused by the phase behavior of my FFT. I'm trying to get the phas
of the fundamental harmonic with the usual arctan. The Phase alternates 18
degrees on odd/even samples. Am I doing something wrong or is this just a
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

Greg
06-16-2009, 07:04 AM
On Jun 15, 7:43*am, "jyquist" <[email protected]> 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

robert bristow-johnson
06-16-2009, 07:28 AM
On Jun 16, 2:04*am, Greg <[email protected]> wrote:
> On Jun 15, 7:43*am, "jyquist" <[email protected]> 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 alternates180
> > degrees on odd/even samples. Am I doing something wrong or is this justan
> > 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

jyquist
06-16-2009, 09:36 PM
>On Jun 15, 7:43=A0am, "jyquist" <[email protected]> wrote:
>> I am confused by the phase behavior of my FFT. I'm trying to get th
phas=
>e
>> of the fundamental harmonic with the usual arctan. The Phase alternate
1=
>80
>> degrees on odd/even samples. Am I doing something wrong or is this jus
a=
>n
>> unadvertised feature of the FFT. Can I fix this?
>
>Try the double input fuction arctan2.
>
>Hope this helps.
>
>Greg


Thanks for the idea. I am working in 8051 assembly and wrote the fou
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 wrot
it in Pascal floating point first then converted to integers using the
range and overflow checking to monitor its behavior. I then wrote it i
8051 assembly and dumped the results to a file for comparison with th
Pascal version. I use Excel to plot results. This is a very valuable tric
when programming in waveform world. Each intermediate pass was tested no
just the final result. Even though any screwup up stream propagates tras
downstream. Pointer and index action was tracked too. Once working th
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. Whe
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 su
of squares is done. Prior to that it in real/Im form it looks like a
cycle oscillation taking about 8 points. Both real and imaginary look alik
but not necessarily the same size of course. Arctan the even peaks and yo
get one angle, the odd peaks you get angle+180. The numbers and angle mak
sense so I believe the arctan is working.

jyquist
06-16-2009, 09:49 PM
>On Jun 16, 2:04=A0am, Greg <[email protected]> wrote:
>> On Jun 15, 7:43=A0am, "jyquist" <[email protected]> wrote:
>>
>> > I am confused by the phase behavior of my FFT. I'm trying to get th
ph=
>ase
>> > of the fundamental harmonic with the usual arctan. The Phas
alternates=
> 180
>> > degrees on odd/even samples. Am I doing something wrong or is thi
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 d
down
and the third about 20 db down. The window process centers the peak in th
middle of the input sample buffer. I tried putting the window peak 50% lef
so sample 0 was the peak. Of course it wrapped around so the rest of th
peak was at the end of the buffer. This did create an interestin
distortion.

Pardon my ignorance but I don't understand n=3DN/2 or exactly what yo
mean by swap left and right, even though English is my first and onl
language.

Thank you all for taking an interest in problem.

JY

Eric Weaver
06-17-2009, 03:39 PM
robert bristow-johnson wrote:
> On Jun 16, 4:49 pm, "jyquist" <[email protected]> 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...