Distortion measurements with LTSPICE

LTSPICE is offering good capabilities for distortion analysis and simulations. All you have to do is to run transient analysis and then right click on the signal plot and use FFT command from view section of submenu. Or use .FOUR command and look for results in SPICE error LOG file from View menu. Though, you have to change a couple of default settings to be able to simulate and analyze harmonics, lower than – 60dB.

I was really surprised, when tried to use FFT analysis to evaluate nonlinear distortions of one of my circuits. The circuit showed unexpectedly low performance. It just could not be that bad. So, I decided to check distortions of voltage source itself. I put voltage source in the schematic and tried to measure it’s harmonics by using both FFT command and dot FOUR. Here is what I got:

Schematic of distortions simulation, used in LTSPICE

Schematic of distortions simulation

I used Maximum Timestep of 1uS to get predictable time resolution, not overridden by nobody knows what autotimestep.

FFT analysis, 131072 data points, no Windowing function (because 10mS corresponds to integer numbers of 1KHz periods)

FFT analysis, 131072 data points, no Windowing function

No Windowing function was used because 10mS corresponds to integer numbers of 1KHz periods.

Log file content after .FOUR command

Log file content after .FOUR command

Quite discouraging results, taking into account that it is just signal source and I was looking for distortions simulations, capable of analyzing at least -130dB.

I started to look for solution. First thought was to increase time resolution by decreasing Maximum Timestep to 10nS.

FFT with increased time resolution

FFT with increased time resolution, Maximum Timestep is set to 10nS


.FOUR with increased time resolution, Maximum Timestep is set to 10nS

.FOUR log file with increased time resolution

Well, this is much better, but that small number of Maximum Timestep could cause very long simulation time of complex circuits.

Let’s see what else could be done to improve resolution while, may be, using bigger timestep to speedup simulation.

LTSPICE control panel has a special section, dedicated to data compression. Intuitively, I felt that this may be related to resolution of FFT, because we are speaking about big range of data representation. 200dB represents data ratio of 10000000000 and this is very demanding requirement. Help describes this compression as: “LTspice compresses the raw data files as they are generated. A compressed file can be 50 times smaller than the un-compressed one. This is a lossy compression.”

After disabling compression and restoring max timestep to original 1uS the simulation looks like:

FFT with disabled compression and max timestep 1uS

FFT with disabled compression and max timestep 1uS


.FOUR log file with disabled compression and max timestep 1uS

.FOUR log file with disabled compression and max timestep 1uS

The main drawback of disabling compression through control panel is that you have to do this every time you are restarting LTSPICE.

More convenient way is to add  .OPTIONS plotwinsize=0 to your LTSPICE schematic. In fact, I used this option to generate previous results.

So, results look very promising and are good enough for most kinds of applications. It is hard to imagine any practical and physically realizable circuit, that will have harmonics better than -160dB.
However, it is possible to improve resolution even better by switching to double precision calculations by using .OPTIONS numdgt=7. Any number more than 6 will force LTSPICE to switch to double precision math on dependent variables.


FFT with disabled compression, double precision math and max timestep 1uS

FFT with disabled compression, double precision math and max timestep 1uS


.FOUR log file with disabled compression, double precision math and max timestep 1uS

.FOUR log file with disabled compression, double precision math and max timestep 1uS

Quite impressive.

You can get even more by decreasing Maximum Timestep to 10nS, but this will significantly increase your simulation time in any practical case.


FFT with disabled compression, double presigion math and max timestep 10nS

FFT with disabled compression, double precision math and max timestep 10nS


.FOUR log file with disabled compression, double precision math and max timestep 10nS

.FOUR log file with disabled compression, double precision math and max timestep 10nS

You can download LTSPICE schematic and play with this options by yourself.


23 Responses to Distortion measurements with LTSPICE

  1. Ed Grimley says:

    Very helpful, thanks!

  2. Tom Field says:

    Well done, and extremely helpful. Thanks to your pioneering, we have meaningful harmonic analysis. We appreciate you taking the time to publish it here.

  3. Paulo Oliveira says:

    How did you plot the FFT result?

    • Eugene says:

      After you completed transient analysis, right click on the waveform, select View (last item on dropdown menu) and FFT from submenu. Then select appropriate options.

  4. Andrew Redwood says:

    I would like to generate the table showing the relative levels of HD1-10.

    Is anyone able to tell me what I need to do to see this?



  5. Andrew Redwood says:

    That is certainly a very cool plug-in, Eugene, which I will load in soon.

    However, I first want to get the simple table of THDs, so I can get the circuit’s THD profile.

    I thought that this was simply a matter of ‘right clicking’ on top of the frequency graph and then selecting ‘FFT’ from the ‘View’ option in the drop-down … but I don’t get the table I want?



  6. Eugene says:

    No, you have to put .FOUR command in schematic and after simulation you have to open log file by right clicking, going down menu. Of just from nenu. This table will be in the log file

  7. Andrew Redwood says:

    Thank you, Eugene. You’ll probably think me dumb but I cannot see any command that allows me to insert ‘.FOUR’ onto my schematic.

    And ‘.FOUR’ does not appear in the LTSpice Help menu?


  8. Eugene says:

    .FOUR command is added manually through .OP menu button. It is the last right button in menu bar. And make a search in help to find .four format

  9. Andrew Redwood says:

    Thanks, Eugene,

    I added “.FOUR 1kHz” to the schematic.
    I also added “.TRAN 3”.

    The ‘Running Man’ generated a green-filled graph above the schematic – however, going to “View=>Spice Error Log” I see an error window with:

    “Direct Newton iteration for .op point succeeded.
    tnom = 27
    temp = 27
    method = modified trap
    totiter = 403021
    traniter = 403014
    tranpoints = 134925
    accept = 86976
    rejected = 47949
    matrix size = 36
    fillins = 2
    solver = Normal”

    What I *don’t* see is the 10-line table shown repeatedly, above?

    Are you able to tell me what I need to do now, to get this 10-line THD table?



  10. Andrew Redwood says:

    OK, some more time playing around (and putting the options specified in your link: “LTSPICE schematic“) gives me some nice sine waves in the “Run” window from various points on the circuit.

    These are the options I have specified:
    .TRAN 0 10m 0 10n
    .FOUR 1kHz 10 V(OUT)
    .OPTIONS plotwinsize=0 numdgt=7

    However, I still can’t see how to generate the table of Harmonic Number 1-10?

    Are you able to advise how this is done?



  11. Eugene says:

    Do you have node, named “OUT” on your schematic? If not, right click on the net and place corresponding label.

    • Andrew Redwood says:

      Thanks, Eugene.

      No, I don’t have the word ‘OUT’ on my schematic. So I right-clicked on the schematic … this brought up a window with 14 commands on it, divided into 4 groups. The first command is ‘Run’; the last command is ‘View’.

      I looked at each command (and its drop-down menu, if it had one) which wasn’t greyed out but couldn’t see anything referring to putting “OUT” on the schematic. Or is this simply a text box which I locate at the end of the circuit?



  12. Eugene says:

    Ok, I can see what is the problem. Before right click, move your coursor to the net you want to name. At the moment when one part of the cross changes colour moving over the net, press right click. It is content related. If you will do it while crossing the net-you can label the net. When, after writing the name, you will be placing the label, place it at the net you want to assign the name to. To make sure that you attached it to the right net, try to move the name afterwards. You will see that it can’t move independently.

  13. Andrew Redwood says:

    Thank you, Eugene. Yes, I now have an ‘OUT’ box at the end of the circuit.

    Clicking ‘Run’ produces a nice sine curve (as it did before). Right-clicking on the sine wave, selecting ‘View’ down the bottom of the resulting drop-down window and selecting ‘FFT’, then accepting the FFT window that came up … delivers a nice graph which:
    * starts at -190dB @ 100Hz
    * drops to -210dB @ 1Khz, with a spike at 1KHz which jumps up 70dB (peak at -140dB)
    * then keeps on dropping with the same slope, with increasing frequency
    * and has a second spike of 5dB @ 2Khz.

    So that looks good! :-))

    But I still can’t see how to generate the “Fourier components of Vout” table which you show underneath each graph, above?

    Any suggestions?



  14. Andrew Redwood says:

    Hi Eugene,

    Further to my above post, after some more playing around with LTSpice this weekend, I found that when I:
    * right-click on the sine wave,
    * select ‘View’
    * select ‘Spice Error Log’ (instead of ‘FFT’)

    … I get a window which says:
    Direct Newton iteration for .op point succeeded.
    .fourier quantity “V(out)” not present in data.

    And yet the ‘.fourier’ statement which I entered onto my circuit schematic is as follows: .FOUR 1kHz 10 V(OUT)

    So I’m wondering why I get that error message – because that seems to be the key to my not getting the list of 10 HD levels?



  15. Eugene says:

    Yes, you right. You may not placed label “OUT” properly. Have tryed my example?

  16. Andrew Redwood says:

    Thanks, Eugene,

    Well, I used the .tran and .FOUR statements exactly as you specify in that link.

    However, my .OPTIONS statement has both ‘plotwinsize=0’ and ‘numdgt=7’ on the same line. Is this an error?

    Which leaves the position of my ‘OUT’ box? Your link shows this sitting right next to – but on top of – the signal input generator.

    Whereas my ‘OUT’ box is:
    * right next to – but below – the output of the circuit, and
    * I chose the Port Type ‘output’ when I created the OUT box – so the box surrounding the word ‘OUT’ has an arrow (like this: ‘>’) on the output side, not a straight line.

    So have I made a mistake with this?

    Can I send you my LTSpice schematic, so you can see what I’ve done?



  17. Andrew Redwood says:

    Aah, I have been able to get some assistance from another helpful person … and now I have the HD table. :-))

    It seems my “OUT” box was not actually attached to the point in the circuit – even though it was right next door.



  18. Be Msk says:

    Thanks for the info and great explanation. My problem is that I have 80% distortion!!! For a fixed transconductance circuit. How can I decrease the distortion?

  19. minime says:

    You can even go a little bit better by disabling the binomial smoothing functionality in the FFT plot window.

  20. Teodor Vasile says:

    Thank you also for the information you provide us here!
    I am able now to understand the .tran analysis better, and I was happy to implement your THD analyzer into my simulation and to see it works. I’ve compared this THD results to the real measurments I have made with my mic preamp and it is “close enough” I would say. It cannot really measure the THD for the low frequencies, but maybe this has to do with my particular circuit (used opamps etc) or with my simulation settings. For a faster simulation I have also set the ‘Reltol’ to 0.01 and ‘Gmin’ to 1e-019 and ‘Solver’ to Alternate. With these setting to the default value maybe I could get a better result. I guess you need a really powerfull computer for that.

    With these been said I still have some theoretical questions regarding the .tran analysis
    Is it possible to calculate or to read the noise value of the circuit from these analysis?
    Or is the .tran analysis only for THD calculations?
    I am asking this because in a simple test I have fed the circuit with 1kHz.
    having 10ms .tran duration and
    5ms .tran duration……and for this two measurements I do get two different noise floor for my circuit.

    On the other hand I have tried the .noise analysis which is meant to calculate exclusively noise density at the output. I am not really sure how to use this analysis right for my particular circuit where I am having differential entry signals and single-ended output signal.

    Do you have any suggestions?

    Txs in advance for your answer!