Audio Total Harmonic Distortion Analyzer for LTSPICE, making THD vs. Amplitude and Frequency sweeps in LTSPICE

FFT capabilities integrated into LTSPICE simulator are nice and flexible. However, if you would like to evaluate frequency or amplitude dependence of distortions, you have to take these measurements point by point and then manually plot them.

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.

How my LTSPICE Audio THD Analyzer 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.

This is how waveforms look after analysis is completed:

Analysis Waveforms after Amplitude Sweep

Analysis Waveforms after Amplitude Sweep

Total Harmonic Distortions vs. Output Amplitude plot looks like this:

Total Harmonic Distortions vs. Output Amplitude

Total Harmonic Distortions vs. Output Amplitude

Total Harmonic Distortions vs. Frequency plot looks like this:

Total Harmonic Distortions vs. Frequency

Total Harmonic Distortions vs. Frequency

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 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.

Comments

12 Responses to Audio Total Harmonic Distortion Analyzer for LTSPICE, making THD vs. Amplitude and Frequency sweeps in LTSPICE