possible bug with center keyword option for FFT [message #75046] |
Fri, 11 February 2011 09:58 |
astroboy2k
Messages: 34 Registered: July 2007
|
Member |
|
|
Hello,
I sent the following to ittvis support, but I was wondering if anyone
has an insights into this. Basically, setting the center keyword for
FFT() gives an output that is shifted incorrectly. I'm doing some
really perverse stuff where it's really important to be sure what
frequency(angle) an output element from FFT() corresponds to....
Thanks,
Mark
Hello,
I've been looking at the output from the IDL FFT function and I have
two things to ask about
1: It would be nice for the function to return the angles/frequencies
(ie, zero to 2*pi, or -pi to pi, say) corresponding to the
coefficients. There's a formula given for that in the documentation,
but I'd feel better if IDL supplied that information, especially
considering my second point.
2: According to the documentation, with the center keyword off in
FFT(), element(0) is the FFT coefficient for the zero frequency. With
the keyword center set, this coefficient is shifted to the 'center' of
the array. This is a little ambiguous, especially when an array might
have an even or odd number of points in a dimension.
From what I can tell, FFT(/center) isn't working quite as advertised.
Here's a code snippet:
box=fltarr(8)
box(0:1)=1.
box(6:7)=1.
ff=fft(box,-1)
ff_cent=fft(box,-1,/cent)
ff=float(ff)
ff_cent=float(ff_cent)
;printing the angles/frequencies and ff and ff_cent coefficients I
get:
CENTER KEYWORD = 0 CENTER KEYWORD SET
ANGLE FFT COEFF ANGLE FFT_COEFF
0 0 0.75000 0 0.03661
1 45 0.21339 45 0.00000
2 90 -0.12500 90 0.03661
3 135 0.03661 135 -0.12500
4 180 0.00000 180 0.21339
5 -135 0.03661 225 0.75000
6 -90 -0.12500 270 0.21339
7 -45 0.21339 315 -0.12500
For ff, the zero frequency point is .75. However, in ff_cent it
appears at index=5. Shouldn't it be at index=4? That is, a shift of
180 degrees?
FFT(arr, 1, /center) seems to work OK, if arr is the output from
FFT(arr0,-1,/center), of course.
|
|
|