1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to use FFT in LTspice

Discussion in 'Circuit Simulation & PCB Design' started by carbonzit, Jul 29, 2011.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    The time step is the the time interval between calculations that LTS uses to do its maths, so smaller the interval means more calculations over the plot period, so higher the accuracy, which is recommended for FFT work.

    EDIT:
    01 image is 1uSec time step and 02image is 'blank' time step.
     

    Attached Files:

    Last edited: Aug 3, 2011
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    ONLINE
  3. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    [/quote]

    All moot points because, as I pointed out, LTspice is smart enough to normalize the other harmonics to the fundamental, so the THD calculation comes out correct.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13

    Eric, do you know what the default time step is? I've searched through the online help and can find no mention of this.

    It should be pointed out that decreasing the time step (to a smaller interval) makes LTspice run slower, since it has to do more calculations. But it does result in a much more accurate FFT plot.
     
  6. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    OK, to sum up so far, with this new information courtesy of E. Gibbs, we now know how to get more detailed (and presumably more accurate) FFT plots from LTspice. So we have learned something today, which is good.

    AG's amp does appear to be the winner, with a THD (measured at 1KHz) of 0.06%.

    However, my original li'l 3-transistor amplifier (with a couple modifications) isn't too shabby itself, with a THD of only 0.73% (same conditions).

    Just as a general question, what is the recognized convention for how long a period to sample an amplifier to measure THD? For this comparison, I ran the simulation for 1 second and only sampled the last 50mS to come up with the measurement. Would this be considered "cherry picking"?
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    ONLINE
    cz,
    I have never seen any documentation regarding the auto time step.

    If you want to increase the number of steps for the FFT, increase the 'Number of data point samples in time' from the default of 209712, to a higher value , click OK and LTS recalc the FFT.
     

    Attached Files:

  8. MRCecil

    MRCecil Member

    Joined:
    Mar 25, 2008
    Messages:
    301
    Likes:
    8
    Location:
    Pacific Northwest
    AG,

    By reducing the time the signal is sampled to 4ms, a virtual filter is created, which reduces the period of the harmonics being sampled. This changes the THD displayed in the Error file, but the data is invalid since the sample time of the harmonics does not allow a proper sample for evaluation.

    Changing just that one parameter from 4ms to 850ms (1s-0.150ms vice .154ms-0.150ms) in the .trans directive, an entire different set of solutions, which are believable, can be seen. A distortion analyser doesn't take a 4ms snapshot of a 1khz fundamental. The table below illustrates the point using your amplifier to collect the data.

    Code (text):

    Hz      4ms Sample    850ms Sample

    100 –  425.297374%     1.233825%
    200 –   33.200019%     1.494789%
    300 –    0.075567%     1.443281%
    400 –    0.032813%     1.456873%
    500 –    0.037357%     1.397510%
    600 –    0.031557%     1.430020%
    700 –    0.039201%     1.401760%
    800 –    0.059831%     1.518350%
    900 –    0.057344%     1.388321%
    1k –     0.054832%     1.460078%
    2k –     0.323067%     1.451333%
    3k –     0.910536%     1.466899%
    4k –     1.371580%     1.423875%
    5k –     1.398053%     1.631628%
    6k –     1.563918%     1.518657%
    7k –     1.591595%     1.467026%
    8k –     1.569369%     1.569287%
    9k –     1.626325%     1.626347%
    10k –    1.628571%     1.628092%
    15k –    1.638349%     1.638320%
    20k -    1.576804%     1.576864%
    BTW, the high THD of your amp is a result, in part, of high odd order harmonics.
     
    Last edited: Aug 5, 2011
  9. audioguru

    audioguru Well-Known Member Most Helpful Member

    Joined:
    Mar 16, 2004
    Messages:
    32,572
    Likes:
    950
    Location:
    Canada, of course!
    ONLINE
    First i changed the frequency so that only a few cycles are shown instead of many cycles all jammed together.
    Then I changed the value in the startup file so that only a few cycles are clearly shown which made the distortion much less.
    i don't know how to "zoom" on the cycles to display fewer of them.

    I think that many "high order odd harmonics" are caused by crossover distortion.
     
    Last edited: Aug 5, 2011
  10. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    I think you might just have a basic misunderstanding of how LTspice works. No harm, no foul: just a little while ago I knew practically nothing about it myself.

    Anyhow, it doesn't matter what you see on-screen in the waveform viewer: what matters is the time period you select in the .tran statement (the "time to start saving data" and the total length of the run govern this).

    To zoom in (or out), just use the zoom tools in the waveform viewer toolbar. When you're viewing a waveform and you have the crosshairs cursor, just click and drag to outline the new area you want to view (zoom in); the cursor will change to a a zoom magnifying glass.

    You need more than just a few cycles of output waveform to do THD analysis. Otherwise, as Mr. Cecil points out, you're basically cherry-picking by filtering the output.
     
    Last edited: Aug 5, 2011
  11. MRCecil

    MRCecil Member

    Joined:
    Mar 25, 2008
    Messages:
    301
    Likes:
    8
    Location:
    Pacific Northwest
    Changing the .tran statement to reduce the sampling period is one way of getting a clear display of the trace(s) to be plotted, but it can yield invalid THD results as shown in the table in my previous post.

    To change the X-axis scaling, place the cursor on the X-axis, and when the ruler appears left click and then adjust the value to that desired in the dialog box. The limits must be within the time domain limits set in the .tran statement.

    Regarding the "crossover distortion", that would be a design issue if it's the cause of the higher odd order harmonics would it not?
     
  12. MRCecil

    MRCecil Member

    Joined:
    Mar 25, 2008
    Messages:
    301
    Likes:
    8
    Location:
    Pacific Northwest
    No where did I claim AG was "cherry-picking" for a favorable solution. Please, do not try to paraphrase my words in such a manner or attempt to modify my intent.

    Thank You,
    M. R. Cecil
     
  13. audioguru

    audioguru Well-Known Member Most Helpful Member

    Joined:
    Mar 16, 2004
    Messages:
    32,572
    Likes:
    950
    Location:
    Canada, of course!
    ONLINE
    It is an extremely simple circuit that does not have an adjustment for the idle current in the output transistors to eliminate crossover distortion. The design "guesses" that the voltage of the two diodes provides enough idle current in the output transistors.
     
  14. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    And the distortion measured is proof that such is not the case?
     
  15. audioguru

    audioguru Well-Known Member Most Helpful Member

    Joined:
    Mar 16, 2004
    Messages:
    32,572
    Likes:
    950
    Location:
    Canada, of course!
    ONLINE
    Distortion at the harmonics around 8kHz is only 0.01% which is very small.
     
  16. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    What do the harmonics have to do with it? The distortion is measured from the fundamental. If you're measuring distortion from a harmonic you're espousing snake juice!
     
    Last edited: Aug 5, 2011
  17. audioguru

    audioguru Well-Known Member Most Helpful Member

    Joined:
    Mar 16, 2004
    Messages:
    32,572
    Likes:
    950
    Location:
    Canada, of course!
    ONLINE
    Of course I know that a pure sine-wave has no harmonics. Distortion adds harmonics.
    Crossover distortion is higher frequency odd harmonics that sound something like a buzz.
     
  18. MRCecil

    MRCecil Member

    Joined:
    Mar 25, 2008
    Messages:
    301
    Likes:
    8
    Location:
    Pacific Northwest
    Yes, but what about the first odd harmonic at 3khz? It is just ~38db below the fundamental, which in and of itself is greater than 1% of the THD. The harmonic at 8khz is ~61db below the fundamental, which is an ~0.01% contributor to the TDH , but THD, TOTAL harmonic distortion, is a summation of ALL the contributing harmonics sampled for evaluation. The totality of the harmonics sampled yields the TOTAL harmonic distortion, and cannot be reliably taken from a single contributory harmonic.
     
  19. audioguru

    audioguru Well-Known Member Most Helpful Member

    Joined:
    Mar 16, 2004
    Messages:
    32,572
    Likes:
    950
    Location:
    Canada, of course!
    ONLINE
    I don't know which simulation you are looking at. The 3rd harmonic at -38dB is pretty bad distortion (more than 1%). Half-decent amplifiers have the total of all harmonics at 0.05% or less. -60dB is 0.1% distortion, not 0.01%.

    -80db is 0.01% distortion.
     
  20. MRCecil

    MRCecil Member

    Joined:
    Mar 25, 2008
    Messages:
    301
    Likes:
    8
    Location:
    Pacific Northwest
    I'm looking at the THD results of your circuit within a valid time domain for a proper analysis; a 850ms sample, used to demonstrate a single parameter change with greatly different and more accurate results, and not an invalid 4ms sample you employed, of which I posted the results in post #47.

    Actually, I measured the third harmonic from the FFT with the cursor, but the actual measurement below the fundamental from the error log was 1.074e-02 below the normalized value of 1.000e+00. When calculated, the actual value is –39.4db rather than the approximate (~) 38db below the fundamental. That is still greater than 1% distortion for just that single harmonic, to which all the other harmonics would add.

    So from your own opinion/analysis, the amp you presented under the valid and proper conditions tested with LTSpice is NOT a half-decent amplifier based on your critique when properly evaluated.

    Well, you did get me on a typo. You are correct that –60db is 0.1% distortion. Every 20db reduction moves the decimal point one place to the right. So your declaration in post #54 stating, "Distortion at the harmonics around 8kHz is only 0.01% which is very small.", to which I responded, was also in error because –61db, as measured by LTSpice with a valid measurement domain at 8.358e-04V, is NOT 0.01% but rather 0.08%. And what are the other harmonics of a 1khz fundamental "around" 8khz? Were you referring to 7khz and 9khz?
     

Share This Page