[Numpy-discussion] FFT definition
Hanno Klemm
klemm@phys.ethz...
Mon Feb 5 04:20:47 CST 2007
Hi there,
I have a question regarding the definitions surrounding FFTs. The help
to numpy.fft.fft says:
>>> help(N.fft.fft)
Help on function fft in module numpy.fft.fftpack:
fft(a, n=None, axis=-1)
fft(a, n=None, axis=-1)
Will return the n point discrete Fourier transform of a. n
defaults to the
length of a. If n is larger than a, then a will be zero-padded to
make up
the difference. If n is smaller than a, the first n items in a will be
used.
The packing of the result is "standard": If A = fft(a, n), then A[0]
contains the zero-frequency term, A[1:n/2+1] contains the
positive-frequency terms, and A[n/2+1:] contains the
negative-frequency
terms, in order of decreasingly negative frequency. So for an 8-point
transform, the frequencies of the result are [ 0, 1, 2, 3, 4, -3,
-2, -1].
This is most efficient for n a power of two. This also stores a
cache of
working memory for different sizes of fft's, so you could
theoretically
run into memory problems if you call this too many times with too many
different n's.
>>>
However, the help to numpy.fft.helper.fftfreq says:
>>> help(N.fft.helper.fftfreq)
Help on function fftfreq in module numpy.fft.helper:
fftfreq(n, d=1.0)
fftfreq(n, d=1.0) -> f
DFT sample frequencies
The returned float array contains the frequency bins in
cycles/unit (with zero at the start) given a window length n and a
sample spacing d:
f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n) if n is even
f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n) if n is odd
>>>
So one claims, that the packing goes from [0,1,...,n/2,-n/2+1,..,-1]
(fft) and the other one claims the frequencies go from
[0,1,...,n/2-1,-n/2,...-1]
Is this inconsistent or am I missing something here?
Hanno
--
Hanno Klemm
klemm@phys.ethz.ch
More information about the Numpy-discussion
mailing list