Frequency spectrum with fft of a real valued array...?

Discussion in 'Python' started by Holger, Jan 11, 2007.

  1. Holger

    Holger Guest

    Dear all,

    I need to do a FFT on an array of 20k real values. Origin of the sampled
    data is a sinus wave with light harmonics.
    The goal is an frequency spectrum with the magnitudes of the first 50.
    harmonics.

    I addressed python like:

    test_arr = src_data_dict[ channel ][0:19599]
    target_data_dict[ channel ] = FFT.fft(test_arr,n=50,axis=-1)

    This results in an array of complex values but with unexpected big
    coefficients...
    (much higher than the original signal magnitudes)
    How do I get the absolute magnitudes of the harmonics, which are much
    lower than the
    resulting absolute values of the coefficients?

    The result should be like this:

    1.harmonic (50 Hz) 1,0
    2.harmonic (100 Hz) 0,01
    3.harmonic (100 Hz) 0,08
    4.harmonic (100 Hz) 0,0035
    etc.


    at the moment I get a resulting array like:

    CH1
    (1729.80103418+0j)
    (366.689810532+19.5196963754j)
    (370.688444025+32.162562652j)
    (372.122246668+46.9545880507j)
    (379.273599053+59.0724599622j)
    (369.889589421+75.9247281559j)
    (381.070551892+99.07345873j)
    (378.800462354+106.761629308j)
    (375.014128346+131.34177586j)
    (389.110601354+149.320740829j)
    (389.23247472+158.909042086j)
    (398.875237165+197.86980788j)
    (397.927158223+196.858459101j)
    (402.455325066+234.651276425j)
    (411.599088579+256.32156894j)
    (414.469935576+254.512014918j)
    (417.198515262+291.400509132j)
    (426.745545674+320.769421334j)
    (433.987466212+321.929780157j)
    (446.124386798+350.810581686j)
    (455.876025379+383.099789898j)
    (458.083277747+405.592129477j)
    (470.908512117+433.929598454j)
    (482.083855098+468.256188814j)

    What does it mean to me? How do I get to the wanted frequenca spectrum???
    ...

    btw The maximum magnitudes of the original data are app. 70 peak

    Thanks in advance for your help!!!

    Regards Holger
     
    Holger, Jan 11, 2007
    #1
    1. Advertising

  2. Holger

    Robert Kern Guest

    Holger wrote:

    > What does it mean to me? How do I get to the wanted frequenca spectrum???


    It's packed in the conventional FFT format. Here is a function in numpy (the
    successor to Numeric, which I assume that you are using) that generates the
    corresponding frequencies in the same packed format:

    In [324]: import numpy

    In [325]: numpy.fft.fftfreq?
    Type: function
    Base Class: <type 'function'>
    Namespace: Interactive
    File:
    /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3507-py2.5-macosx-10.4-i386.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
     
    Robert Kern, Jan 11, 2007
    #2
    1. Advertising

  3. Holger

    Holger Guest

    Hello Robert!

    Thank you for your tips. They were very useful.

    Bye Holger


    Am 11.01.2007, 19:08 Uhr, schrieb Robert Kern <>:

    > Holger wrote:
    >
    >> What does it mean to me? How do I get to the wanted frequenca
    >> spectrum???

    >
    > It's packed in the conventional FFT format. Here is a function in numpy
    > (the
    > successor to Numeric, which I assume that you are using) that generates
    > the
    > corresponding frequencies in the same packed format:
    >
    > In [324]: import numpy
    >
    > In [325]: numpy.fft.fftfreq?
    > Type: function
    > Base Class: <type 'function'>
    > Namespace: Interactive
    > File:
    > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3507-py2.5-macosx-10.4-i386.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
    >
    >
     
    Holger, Jan 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    1
    Views:
    680
    Sajan
    Feb 4, 2004
  2. aj
    Replies:
    3
    Views:
    4,335
    Jaakko Varteva
    Nov 24, 2005
  3. x1
    Replies:
    9
    Views:
    370
    Rick DeNatale
    Oct 12, 2006
  4. PerlFAQ Server
    Replies:
    0
    Views:
    222
    PerlFAQ Server
    Feb 1, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    210
    PerlFAQ Server
    Mar 26, 2011
Loading...

Share This Page