[SciPy-user] the physical frequency of FFT

Gary Pajer gary.pajer at gmail.com
Thu Mar 20 10:22:49 EDT 2008


On Tue, Mar 18, 2008 at 6:57 PM, Forrest Sheng Bao
<forrest.bao at gmail.com> wrote:
>
>
>
> On Tue, Mar 18, 2008 at 5:30 PM, Robert Kern <robert.kern at gmail.com> wrote:
> >
> > On Tue, Mar 18, 2008 at 5:09 PM, Forrest Sheng Bao wrote:
> > > Hi,
> > >
> > > I have some other questions about the fft function. Suppose I have N
> > > sampling points and the sampling rate is Fs. I performed an N-point FFT,
> > > using the code fft(my_list_of_data).
> > >
> > >
> > > Doesn't the k-th point (0<k<N/2) correspond to the physical frequency
> > > (k*Fs)/(2*N)?
> >
>
> I saw an example at Scipy Getting Started guide:
> http://www.scipy.org/Getting_Started
>
> Can you take a look at the demo In [2] to In [5]. It seems each frequency
> bin occupies a bandwidth of Fs/N and those frequency bins are ordered from 0
> to N-1.
>
> >
> >
> > It follows the conventional FFT packing:
> >
> > In [9]: numpy.fft.fftfreq?
> > Type:           function
> > Base Class:     <type 'function'>
> > Namespace:      Interactive
> > File:           /Users/rkern/svn/numpy/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
>
> Ok, each point in the result of FFT correspond to the frequency bin
> calculated by fftfreq. So the k-th point of the first half points of fft
> output, indexing from 0 to N/2, correspond the physical frequency k*Fs/N.
>
> Thus, if I wanna consider a frequency band 2-4Hz while the sampling rate is
> 100Hz and I have 1000 sampled points, then I just need to consider the
> results between the 20th and the 40th points. Is my understanding right?


Yes.  You can help your understanding by recognizing that the points
in frequency space represent points on a discrete lattice.  They do
not represent the centers of bins, despite the wording in many
textbooks (and the docstring, evidently).  I've seen much confusion
caused by the words "bin" and "leakage".  (Death to both words!)  One
might think that if you try to represent a pure sine whose period is
incommensurate with your sampling period (and hence whose frequency
falls in between frequency-space points) would lead to a fft whose
frequency lies in the nearby "bin" or fills the "bin" somehow.
Instead, one observes "leakage".   Very bad words, IMHO.

-g



More information about the SciPy-User mailing list