THD vs frequency

LuckyLuka

Member
2019-12-23 10:02 pm
Hi all

I've found this link: Audio Total Harmonic Distortion Analyzer for LTSPICE, making THD vs. Amplitude and Frequency sweeps in LTSPICE | Audio Perfection


I'm trying to understand how to use this script properly.
Can someone tell me how I can plot the THD vs freq graph?
After I've simulated the given example , I went to the error log (CTRL-L) and than I right clicked the log window.
THD vs output amplide graph appear after I select "plot selected meas data"
I have even changed the analyzer_controls.txt commenting the amplitude sweep and uncommenting the freq sweep but the result doesn't change: I cannot display the THD vs freq graph I'm looking for.
Cheers
 
If there is another method to achieve a thd vs freq graph it's ok for me.

I find the Audio Perfection tool attractive in principle but opaque and difficult to use in practice. It relies on the .meas statement, but .meas cannot make use of .four results, which is why the Audio Perfection tool is so complicated - it needs to find a way to calculate THD without using the built-in .four command.

Do you have Excel? I developed a method which uses the text in the Error Log in LTspice to produce plots like these:

THD_Frequency.PNG THD_Power.PNG

These plots are those of a high quality class B amp with non-switching output devices.

To get up and running with this tool, download the attached zipped file "THD Sweep Plots.zip" and unzip it. There's a text file in there "READ_ME_FIRST.txt" which explains how to use the spreadsheet "THD_sweep_plots.xlsm".

Most of the work is automated with a macro, which has been written using Excel 2016. I'm not familiar enough with Calc to attempt to tweek the coding for a Calc version; anyone who wishes to do so is welcome to try (shouldn't be difficult).

View attachment THD Sweep Plots.zip

Have fun.
 
Those looks like plots of total harmonic power, not distortion. Distortion is a ratio and wouldn't scale with power like that. In the real world THD+N falls as the power increases due to noise. Spice doesn't simulate noise and signal in the same directive so you'd expect distortion to be constant with power to a first approximation.
 
The plots are definitely of THD readings obtained from .four analyses at different frequencies and output powers. I express distortion in terms of decibels in the plots, but that's just a personal preference which doesn't detract from the validity of the method. Both plots, incidentally, use exactly the same data.

Did you download and follow the example given in the zipped file? Try it and if you think the method is flawed, please explain to me why. As long as one accepts the commonly acknowledged limitations of Spice, I think the method is fine.

The OP asked how to obtain plots of THD vs. frequency and THD vs. power using LTspice, and I think I answered his question very adequately. Spice gets quite a lot of stick in this forum for giving optimistic results, but this is the software section of the forum, and Spice is, to the best of my knowledge, easily the best predictor in software of the performance of electronic circuits. LTspice is certainly the software of choice for many contributors to this forum who are interested in electronics.

It may be the case that the Spice Fourier analysis tells us little about the noise generated by a circuit. There are, however, countless posts in DIYA in which THD results from .four analyses are quoted. I'm not aware of anyone claiming THD+N results from Fourier analyses, I certainly didn't make that claim; moreover, I wouldn't expect or ask for any more credibility than that ascribed to other posts/posters that make use of LTspice's .four command. I do, however, wish to stress that the plots are nothing more or less than the results of .four commands at various frequencies and power levels; the only difference is that I have developed a way automatically to present many such results in a useful graphical format.