[SciPy-user] FFT indexes with zero-padding

Robert Kern robert.kern@gmail....
Mon Jan 19 22:22:52 CST 2009


On Mon, Jan 19, 2009 at 22:18, Forrest Sheng Bao <forrest.bao@gmail.com> wrote:
> Hi,
>
> I am thinking about a question regarding the indexes of FFT result with
> zero-padding.
>
> Suppose there is no zero-padding that the length of signal is a power of 2,
> like 4096. Then the index corresponding to frequency f should be f/fs*N,
> where fs is the sampling rate and N is the number of points.
>
> But, what if the length of signal is not a power of 2? Like 5000? How does
> Scipy.signal module handle this?
>
> For example, I have 5000 samples and am doing 5000-point FFT. The sampling
> rate is 200Hz. Is the index for 2 Hz still 2 / 200* 5000 = 50?

In [16]: numpy.fft.fftfreq?
Type:           function
Base Class:     <type 'function'>
String Form:    <function fftfreq at 0x18a29fb0>
Namespace:      Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy-1.2.0rc2-py2.5-macosx-10.3-fat.egg/numpy/fft/helper.py
Definition:     numpy.fft.fftfreq(n, d=1.0)
Docstring:
    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


-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list