NumPy and FFT

Warren B. Focke moron at Glue.umd.edu
Sun May 21 21:48:38 EDT 2000


Jad sez:
 
> I have a 1D array (say a) which contains real data
...
> which function do i have to use in order to get b = FT(a) ?

	The discrete Fourier transform has no knowledge, or need for
it, about your measurement intervals or the frequencies that the
length of your sequence implies.  You will have to construct the
column of frequencies yourself.
	The function you want to use to do the transform is fft.  It
might seem, since you have real data, that you want the real_fft
function, but it's broken.  I've tried to submit a patch, but it
produced neither response nor action.  I had assumed they were just
too busy to deal with it, but maybe I didn't send it to the right
place.  Perhaps I'll try again.
	Said patch also included expanded documentation for the fft
function, which is as follows:

> 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.

In your case (real data), you can ignore the negative frequency terms.

Warren Focke
-- 
If you feel that you have both feet planted on level ground, then the
university has failed you. -Robert Goheen, President, Princeton University



More information about the Python-list mailing list