Re: possible bug with center keyword option for FFT [message #75040] |
Fri, 11 February 2011 12:41  |
R.G.Stockwell
Messages: 163 Registered: October 2004
|
Senior Member |
|
|
"R.G. Stockwell" wrote in message news:ij46h9$cg9$1@speranza.aioe.org...
>
>
> "Mark" wrote in message
> news:babf90b7-e4a3-48bc-aecf-ae81e4a055d4@o18g2000prh.google groups.com...
>
>
> 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.
You are absolutely correct. This is an error in IDL.
**********************************************
also, for the odd case, IDL is also wrong.
When there is an odd number of points, the actual nyquist value is not
sampled. (great trick question for anyone who thinks the nyquist is 1/(2T))
so you have, N = 7, and take T = 1 as the sampling interval:
I, freq
0, DC
1, 1/N
2, 2/N
3, 3/N
4, -3/N
5, -2/N
6, -1/N
so the 'centered' fft is:
i, old i, freq
0, 4, -3/N
1, 5, -2/N
2, 6, -1/N
3, 0, DC
4, 1, 1/N
5, 2, 2/N
6, 3, 3/N
From the example shown, the dc went to the 4th index when centered, it MUST
go to the 3rd index.
cheers,
bob
PS, I hope it's obvious how I am writing that. the first number is the
current index of the spectrum array. Then the next column is the "old"
index based on the result of a straight FFT (i.e with out the center
keyword), then the final column is what the frequency value is, of a N point
time series with sampling T = 1, and here N = 7 but I thought that it would
be confusing to write out the 7 each time.
----------------------------
R.G. Stockwell, Ph.D.
Northwest Research Associates,
Colorado Research Associates Div.
3380 Mitchell Lane Boulder CO USA 80301
----------------------------
|
|
|
Re: possible bug with center keyword option for FFT [message #75041 is a reply to message #75040] |
Fri, 11 February 2011 12:34   |
R.G.Stockwell
Messages: 163 Registered: October 2004
|
Senior Member |
|
|
>
>
> "Mark" wrote in message
> news:babf90b7-e4a3-48bc-aecf-ae81e4a055d4@o18g2000prh.google groups.com...
>
>
> 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.
You are absolutely correct. This is an error in IDL.
The normal packing is
0 DC value
1/(NT)
2/(NT)
...
(N/2-1)/(NT)
(N/2)/NT = 1/(wT) = special point, IF n is even, aliased nyquist value
-(N/2-1)/(NT)
-(N/2-2)/(NT)
...
-2/NT
-1/NT
So, if you want to "center" it, then you obviously want the most neg freq
which I would say is -(N/2-1)/(NT), but you could arguably say it is the
nyquist (for the even case). There is an ambiguity there.
But, you always want the DC at the "center" followed by all the positive
frequencies.
For the case of 8 points you have
i, freq
0 DC
1 1/N
2 2/N
3 3/N
4 nyquist
5 -3/N
6 -2/N
7 -1/N
So to 'center' it, it must become
i, old i, freq
0 5 -3/N
1 6 -2/N
2 7 -1/N
3 0 DC
4, 1 1/N
5, 2 2/N
6, 3 3/N
7, 4 nyquist
However, it could also be (cause the nyquist is both most neg and most
positive)
I, old I, freq
0 4 nyquist
1, 5 -3/N
2, 6 -2/N
3, 7 -1/N
4, 0 DC
5, 1 1/N
6, 2 2/N
7, 3 3/N
Now, either way, IDL is wrong since it has a postive frequency as it's first
point, then the nyquist, then the neg freqs.
Here, the DC can go to index 3, or to 4, but NOT to 5.
cheers,
bob
--
----------------------------
R.G. Stockwell, Ph.D.
Northwest Research Associates,
Colorado Research Associates Div.
3380 Mitchell Lane Boulder CO USA 80301
----------------------------
|
|
|
Re: possible bug with center keyword option for FFT [message #75044 is a reply to message #75041] |
Fri, 11 February 2011 10:17   |
astroboy2k
Messages: 34 Registered: July 2007
|
Member |
|
|
On Feb 11, 1:05 pm, David Fanning <n...@dfanning.com> wrote:
> Mark writes:
>> 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....
>
> I recall an earlier discussion here that this keyword
> might not be working correctly. I know I made a note in
> my book about this, and I normally save the reference,
> but I can't put my hands on it at the moment.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Thanks David.
I had a look on this group but apparently I missed that.... I hope the
work on the book is going well.
|
|
|
|
|