[SciPy-user] the physical frequency of FFT

Forrest Sheng Bao forrest.bao at gmail.com
Tue Mar 18 18:57:53 EDT 2008


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?


>
>
> > Consider the single-sided case. If I just plot the FFT result by
> > plot(fft(my_list_of_data)), the x-coordinate ([0,Pi]) is the image part
> and
> > the amplitude is the real part, right?
>
> No. I believe that matplotlib (I have to assume this is the plotting
> library you are using; please state so in the future) just ignores the
> imaginary part. The X-coordinate is just arange(len(my_list_of_data)),
> and the Y-coordinate is the real part of the FFT. Because of the
> packing of the FFT, you will need to rearrange things in order to make
> a sensible plot. I recommend using fftfreq() to get an array of
> corresponding frequencies and using fftshift() on both the frequency
> array and the FFT.
>

I just wanna compute the power spectrum to each physical frequency band.
Since my signal is real, the FFT result is symmetric. So I think that I can
neglect the part of negative frequency.


>
>
> In [10]: numpy.fft.fftshift?
> Type:           function
> Base Class:     <type 'function'>
> Namespace:      Interactive
> File:           /Users/rkern/svn/numpy/numpy/fft/helper.py
> Definition:     numpy.fft.fftshift(x, axes=None)
> Docstring:
>    fftshift(x, axes=None) -> y
>
>    Shift zero-frequency component to center of spectrum.
>
>    This function swaps half-spaces for all axes listed (defaults to all).
>
>    Notes:
>      If len(x) is even then the Nyquist component is y[0].
>
> > If I wanna estimate the power spectrum at each frequency, should I
> square
> > the real part or computer the norm (square root of the sum of squares of
> the
> > real and image part) of the complex number, at each FFT point?
>
> Just the sum of squares, I believe.
>
> --
> 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
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080318/33e37045/attachment.html>


More information about the SciPy-User mailing list