[Numpy-discussion] fftfreq very slow; rfftfreq incorrect?
a.h.jaffe at gmail.com
Wed Aug 30 06:04:22 CDT 2006
the current implementation of fftfreq (which is meant to return the
appropriate frequencies for an FFT) does the following:
k = range(0,(n-1)/2+1)+range(-(n/2),0)
I have tried this with very long (2**24) arrays, and it is ridiculously
slow. Should this instead use arange (or linspace?) and concatenate
rather than converting the above list? This seems to result in
acceptable performance, but we could also perhaps even pre-allocate the
The numpy.fft.rfftfreq seems just plain incorrect to me. It seems to
produce lots of duplicated frequencies, contrary to the actual output of
""" rfftfreq(n, d=1.0) -> f
DFT sample frequencies (for usage with rfft,irfft).
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,1,2,2,...,n/2-1,n/2-1,n/2]/(d*n) if n is even
f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2]/(d*n) if n is odd
**** None of these should be doubled, right?
More information about the Numpy-discussion