Helmut Sennewald, 09/12/2006 V0.6 This program can plot the THD versus frequency. You need Perl on your PC to run this application. See the links at the end. Additionally I recommend the text editor "PSPad" for syntax highlighting. 1a. This Perl-script use the Unicode to ASCII converter program "ltsputil17raw4.exe". Copy ltsputil17raw4.exe into the folder of your design files(.asc, .net, .cir). Yuu can download it from https://groups.yahoo.com/neo/groups/LTspice/files/%20Util/ltsputil/ 1. Before you can run ltsputil_XVII.pl, you have to set the correct path to the LTspice executable "scad3.exe". This path has to be set in one of the first lines of the Perl-script "ltspdisto.pl". $ltspice = '"C:\Programme\LTC\LTspiceXVII\XVIIx64.exe" -b' Change it to your installation, e.g. as shown below. $ltspice = '"C:\programs\LTC\LTspiceXVII\XVIIx64.exe" -b' 2. Generate a netlist from your schematic. Therefore set the option to keep the netlist. Control panel -> set "Automatically delete .net files" to NO. Run one simulation with the schematic or use the View->SPICE netlist from the menu to generate the netlist file (.net). 3. Open a command window (cmd) in WIN7,8,10 Now run the Perl interpreter with the script. C:\tinyperl\tinyperl.exe ltspdisto.pl amplifier.net disto.cir DEC 20 20 20000 This example will generate 'disto.thd' and 'disto.raw' with the netlist 'amplifier.net', e.g. from the schematic 'amplifier.asc'. It could be any pure netlist too. The only requirement in the schematic/netlist is one line exactly written as shown below. -------------------------------------------------------------- Some more details how the program works. There is one specific param-line necessary in the netlist. .param F1= This line is altered from run to run by the Perl-script. 1. run: .param F1= 1000 2. run .param F1= 1137 3. run ... DEC 20 20 20000 means sweep from 20Hz to 20000Hz with 20 steps/decade A source in the schematic should use this parameter F1 as the frequency and a .FOUR command should use this parameter too. .FOUR {F1} V(out) V1 10 0 SINE(0 1 {F1}) The Perl-program performs multiple simulation runs while incrementing the parameter F1(normally frequency) from run to run. After every run, the result of the FOUR-analysis is read from the log-file and written to a text-file and at the end to a raw-file too. The advantage of this method is that you will get the full accuracy of the FOUR-analysis. The output text-file can be used with any other program like MS-Excel or OpenOffice-Calc. Another big feature is the raw-file. It allows you to use the waveform viewer to view the magnitude (and the phase) of the distortion. I have uploaded a screenshot to the 'Photos' section of this group. "Distortion plots with 'ltspdisto.pl'" There is also a screenshot for a short time frame available. Files > Temp > disto.raw The zipped version of this program together with an example is available from the Files section. Files > Util > ltspdisto_XVII.zip I am a novice with Perl. So please no bad comments about my Perl-style. Just improve the program by yourself. :-) There are free of charge Perl interpreters. I have used Perl 5.8.8. Msi(x86) from the next link. http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl A smaller Perl. http://tinyperl.sourceforge.net/ This THD-meter is not limited to step only the frequency. The parameter 'F1' can be used to vary any parameter in your circuit to plot e.g. THD versus some bias current, but then at a constant frequency. A detailed specifiaction can be found in the header of the Perl- program 'ltspdisto.pl'. Best regards, Helmut PS: The waveform viewer can format the result. Plot V(THD)/1V to remove the unit V. Plot I(k2)/1A*1deg to get the unit degree for the phase of k2