LTSPICE THD Analyzer - diyAudio
Go Back   Home > Forums > Design & Build > Software Tools

Software Tools SPICE, PCB CAD, speaker design and measurement software, calculators

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 14th December 2011, 10:28 PM   #1
diyAudio Member
 
Join Date: Feb 2008
Location: Denver, CO
Default LTSPICE THD Analyzer

I created an LTSPICE add-on to automate THD measurements and plot result in the form of THD vs. Amplitude and THD vs. Frequency graphs.
I was inspired by "jfet_amp_disto_plot" by Helmut Sennewald, "Audio Distortion Analyser" by Tony Casey and "Fundamental Null Distortion Residual" by jcx from Spice simulation

How it works:
It outputs sinusoidal signal with amplitude or frequency stepping sweep into device under test (DUT). Output signal from DUT is feed into analyzer input. After waiting some time for signal to become steady state, analyzer restores fundamental and subtracts it from input signal. This subtraction allows to increase resolution or reduce measurement time for the same resolution. You can monitor residual components at “Notch output”.
Residual signal is then fed into synchronous filters and detector. Each harmonic is filtered and measured separately. Maximum of 10 harmonics are analyzed. Amount of harmonics could be easily increased by adding corresponding filters and possessing.

Click the image to open in full size.
Click the image to open in full size.
How to use LTSPICE Audio THD Analyzer:

Place THD_Analyzer.asy symbol and Analyser_Controls.txt files in the same directory, where you are saving schematic (DUT schematic),
that you would like to analyze.

Put SPICE directives “.inc Analyzer_Controls.txt” and “.tran 0 {AnalysisTime} {SettlingTime} {MaxTimestep}” in DUT schematic .

Edit “Analyzer_Controls.txt“ to enable (uncomment) appropriate sweep (amplitude or frequency ) and save this file.

Setup “.param Ag=xxx” as amplitude for frequency sweep or “.param Fg=xxx” as frequency for amplitude sweep.

Run the simulation.

After simulation is complete, go to View menu and open SPICE Error Log or use Ctrl+L command.

Click with right mouse button on opened Log file.

Execute “Plot .step’ed .meas data” command. Right mouse button click on opened plot and use Add Trace or Ctrl+A and select the data that you want to plot.

You may want to double click on axis to change axis limits or switch to logarithmic scale.

Notch output shows residual components, after fundamental removal.

Please note that fundamental may not be removed completely. This is not necessarily affecting resolution of measurements as soon as additional synchronous filtering is used to measure amplitude of harmonics.

Increasing SettlingTime and StrobeLength, or (and) decreasing MaxTimestep would likely improve fundamental rejection.

Generator output is DC coupled and has 0 Ohm output impedance. Use external AC coupling and appropriate series resistor if required, to ensure proper operation of simulated circuit.

THD_Analyzer.zip contains all necessary files and example. Unzip all files in the same directory, open “Example_BJT_THD_TEST.asc” and run simulation.
You can monitor analysis progress in the left lower corner of LTSPICE window. After simulation and analysis is complete (including completion of .MEASURE), follow the instructions to display
results.
__________________
Audio Perfection
  Reply With Quote
Old 17th December 2011, 08:54 PM   #2
diyAudio Member
 
Join Date: Dec 2003
Location: Munich
Hi Eugene,
that's going to become luxury simulation
Let the computer work for a night and watch results next morning.
At least I guess that will be the way in case of simulation of class D amps.

Anyway - cool.
Still struggling a little bit with parametrization.
For some reason, when I change to the frequency sweep I see that it simulates different frequencies, but the plot in the end shows the result still as a function of the fundamental amplitude.
I guess, I missed one check/uncheck item in the text file.
Attached Images
File Type: png parameters.png (147.9 KB, 1009 views)
File Type: png graph.png (97.9 KB, 985 views)
  Reply With Quote
Old 18th December 2011, 01:52 PM   #3
diyAudio Member
 
Join Date: Feb 2008
Location: Denver, CO
Hello,
You made all modifications correct.
To display distortion vs. frequency plot:
Double click on horizontal axis label of your distortion plot.
Put fg label name instead of Fundamental_Out_V_RMS
Set frequency limits and log scale. You may have to do this twice for log to be applied.

Eugene
__________________
Audio Perfection
  Reply With Quote
Old 18th December 2011, 02:48 PM   #4
diyAudio Member
 
Join Date: Dec 2003
Location: Munich
Great, many thanks !
  Reply With Quote
Old 20th December 2011, 04:12 AM   #5
diyAudio Member
 
Join Date: Nov 2009
Location: Pune
Eugene, Thanks, I was looking for this kind of solution for a long time. Let me try this out.
__________________
There is always a first time....
  Reply With Quote
Old 24th December 2011, 02:25 AM   #6
diyAudio Member
 
Join Date: Jul 2011
Eugene,
Thanks for this. I have been playing around with this and it is very nice. I changed slightly how I use it. I made three versions of your "Analyzer_Controls.txt" file: One called "Amplitude Sweep, another "Frequency Sweep" and another is "No_Sweep". This way I can just have all three .inc XXXX.txt directives and comment out all but one of them. I found this easier than editing the Analyzer_Controls.txt file to change from amplitude to frequency sweep. I also like having no sweep so that I can quickly look at a transient simulation.
I of course left all of the credit information in the text files. I hope you don't mind me making the changes. This is a really nice tool. Thanks for providing it.

Terry
  Reply With Quote
Old 30th December 2011, 05:34 PM   #7
diyAudio Member
 
Join Date: Feb 2008
Location: Denver, CO
Hello,
You are welcome to modify it the way that is more convenient for you. I wanted to make an example of what is possible to do with LTSPICE.
Though, it is relatively slow and requires careful selection of steps for analysis. It may also require some adjustment of timing to measure very small (few ppm) numbers.
__________________
Audio Perfection
  Reply With Quote
Old 24th January 2012, 11:51 AM   #8
diyAudio Member
 
Join Date: Dec 2011
In the example you are analyzing the output(out_e) with respect to ground. Let say my signal is with respect to another node(not ground). Is there a quick trick to do this?
  Reply With Quote
Old 28th January 2012, 04:23 PM   #9
diyAudio Member
 
Join Date: Oct 2009
Location: Brunei
I am a beginner in LTSpice and tried to get this to work... unfortunately the log file shows the measurements FAIL'ed.... any ideas what could be wrong?
  Reply With Quote
Old 29th January 2012, 05:10 PM   #10
diyAudio Member
 
Join Date: Feb 2008
Location: Denver, CO
Quote:
Originally Posted by pha0001 View Post
In the example you are analyzing the output(out_e) with respect to ground. Let say my signal is with respect to another node(not ground). Is there a quick trick to do this?
You can use voltage controlled voltage sourse with gain of 1. Inputs - to floating voltages of interest, outputs - to Analyzer input and ground.
__________________
Audio Perfection

Last edited by Eugene Dvoskin; 29th January 2012 at 05:14 PM.
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
THD vs output power in LTspice Tekko Solid State 7 4th January 2012 01:40 PM
LTSpice how to measure THD+N ? sameerdhiman Software Tools 6 1st November 2011 06:31 AM
THD in LTSpice ? Tekko Solid State 74 30th November 2010 01:37 PM
Chip THD% Analyzer jackinnj Equipment & Tools 1 27th December 2007 09:28 PM


New To Site? Need Help?

All times are GMT. The time now is 08:21 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright ©1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2