diyAudio

diyAudio (http://www.diyaudio.com/forums/)
-   Software Tools (http://www.diyaudio.com/forums/software-tools/)
-   -   LTSPICE THD Analyzer (http://www.diyaudio.com/forums/software-tools/202522-ltspice-thd-analyzer.html)

Eugene Dvoskin 14th December 2011 10:28 PM

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 http://www.diyaudio.com/forums/softw...tml#post133313

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.

http://www.audio-perfection.com/wp-c...s/THD_Vout.png
http://www.audio-perfection.com/wp-c...s/THD_Freq.png
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.

ChocoHolic 17th December 2011 08:54 PM

2 Attachment(s)
Hi Eugene,
that's going to become luxury simulation :D
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.

Eugene Dvoskin 18th December 2011 01:52 PM

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

ChocoHolic 18th December 2011 02:48 PM

Great, many thanks !

Aucosticraft 20th December 2011 04:12 AM

Eugene, Thanks, I was looking for this kind of solution for a long time. Let me try this out.

TerrySt 24th December 2011 02:25 AM

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

Eugene Dvoskin 30th December 2011 05:34 PM

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.

pha0001 24th January 2012 11:51 AM

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?

studiostevus 28th January 2012 04:23 PM

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?

Eugene Dvoskin 29th January 2012 05:10 PM

Quote:

Originally Posted by pha0001 (Post 2875996)
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.


All times are GMT. The time now is 02:31 PM.


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