Connect with us

FFT Rounding error?

Discussion in 'Electronic Design' started by Andrew Holme, May 12, 2007.

Scroll to continue with content
  1. Andrew Holme

    Andrew Holme Guest

    I computed this forward FFT using MS VC++ 6.0 and FFTW:

    http://www.holmea.demon.co.uk/Misc/FFT.gif

    I don't think the "tail" should flick up like that at the low-frequency end.
    Is this caused by a lack of floating-point precision?

    TIA
     
  2. Rune Allnor

    Rune Allnor Guest

    It would be a lot easier to have an opinion if one knew the
    input data and what is displayed...?

    Rune
     
  3. What are the two lowest frequencies calculated in that display?

    This may be a result of having a non integer number of
    cycles at the lowest frequency computed.
     
  4. Andrew Holme

    Andrew Holme Guest

    It's a prediction of frequency synthesizer phase noise, generated by
    simulation. FFT input is 1e6 samples of VCO control voltage. Graph is
    generated by calculating modulation index at each point in FFT output (NBFM
    approximation). Phase noise dominated by VCO rolls off at -20dB/decade
    outside loop bandwidth. Spur is 100 KHz reference frequency. Due to use of
    3rd order loop filter, noise slope should be 40-20=20dB per decade inside
    loop bandwidth, and it is, except where that "tail" flicks up.

    Does anyone recognise the effect?

    TIA
     
  5. Andrew Holme

    Andrew Holme Guest

    I'm not sure what you mean by the two lowest frequencies.

    FFT input is 1e6 samples, sampled at 1 MHz. There are 1e6 output buckets,
    each 1 Hz wide.
    Bucket 0 is DC (not plotted)
    Bucket 1 is 1 Hz
    Bucket 2 is 2 Hz e.t.c
    The data is not repetitive, essentially a steady DC level with noise and 100
    KHz ripple.
     
  6. So the line at the left side of the graph is really not
    information. the only information is in the points at 1 Hz,
    2 Hz, etc. So 1Hz and 2Hz are the two lowest frequencies
    displayed by this graph.
    What would you expect to find in this data if the original
    samples contained some 1.5 Hz energy?
     
  7. MooseFET

    MooseFET Guest

    Does your data have a ramp in it?

    1,2,3,4,5,6.... makes that sort of shape.
     
  8. Andrew Holme

    Andrew Holme Guest

    Ah! I think you put your finger on it. I've just removed the DC, and the
    problem has gone. When you have an exactly integral number of cycles, the
    FFT shows a sharp reponse, and when you don't, it spills into adjacent
    buckets doesn't it? I think my DC bucket is spilling.

    Thanks John.
     
  9. Rune Allnor

    Rune Allnor Guest

    Phase noise? Is this the phase, not magnitude, as returned by
    the FFT?
    This is a WAY to complicated an example to verify the FFT! To test
    the FFT, use one sinusoidal at a fraction of the sampling frequency,
    f = n/N*Fs, and see what happens.

    You use FFTW. That library returns results in ways that some times
    are not at all obvious. Are you sure you unwrapped the results
    properly?

    Rune
     
  10. Andrew Holme

    Andrew Holme Guest

    Damn. The problem is back. It's not just DC. I think I need to make the
    1e6 samples end on the same value they started at. Something like a Hanning
    window. I think the discontinuity is creating a response at 1 Hz. Does
    FFTW do windowing?
     
  11. Jamie

    Jamie Guest

    I'm not exactly sure what your application of the FFT is for how ever,
    in one of my apps, I calculate a group, use only the middle results,
    shifted the original samples over and added to the samples and recalculated.
    You may want to look for "Continuous FFT" coding.
     
  12. joseph2k

    joseph2k Guest

    What do you mean by "flick up"? The graph provided has no "flick up".
    What the heck are you blathering on about?
     
  13. Ben Jackson

    Ben Jackson Guest

    I'm not sure what is causing that, but it reminds me of the FFT graphs
    I get from LTspice.

    BTW, what are you using to make that graph?
     
  14. Andrew Holme

    Andrew Holme Guest

    My C program outputs the data to a CSV file which I then paste into
    Microsoft Excel to plot the graph.
     
  15. Andrew Holme

    Andrew Holme Guest

    My C++ program generates 1e6 samples of aperiodic data, sampled at Ts = 1
    MHz i.e. duration = 1 second; and I want to analyse the frequency content.
    I'm using an FFT; but I'm getting a strong response in the FFT output at 1
    Hz. This would be correct if the same 1e6 samples repeated, but they don't.
    Is there any way to reduce this effect, or is it a fundamental limitation of
    the FFT?
     
  16. Paul Russell

    Paul Russell Guest

    This is probably just spectral leakage from the DC bin - my guess is
    that you are not applying an appropriate windowing function to the data
    prior to the FFT ?

    Paul
     
  17. Andrew Holme

    Andrew Holme Guest

    Eliminating the DC component did not help. I am not using a windowing
    function at the moment. Can you suggest one? I don't mind sacrificing
    frequency resolution.
     
  18. Paul Russell

    Paul Russell Guest

    As a rule of thumb you almost always need to use a windowing function
    prior to an FFT. There are plenty to choose from but the Hann or
    "Hanning" window is a good choice unless you have any very specific
    requirements which might dictate an alternate function.

    <http://en.wikipedia.org/wiki/Window_function#Hann_window>

    Paul
     
  19. Andrew Holme

    Andrew Holme Guest

    Thanks, Paul. The Hann window works well. I still get a large response at
    1 Hz, which I would expect; but there's no spillage into 2 Hz and above.
     
  20. MooseFET

    MooseFET Guest


    Before you do any windowing, take out the DC and the trend. If the
    data has either, the windowing tends to make new problems. Chances
    are when you take out the DC and the trend, the problem will be much
    less without windows.

    I've had good luck with 1.5 - cos(T) - 0.5*cos(2*T)

    It depends a lot on what your data looks like and what you want to get
    out of it.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-