THD from Spice simluation

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Prune,

Enter dot four command using “SPICE directive” button (keyboard shortcut is 'S').

Should look like:
.four 1kHz V(out)
(for the harmonics of 1kHz at the point marked as out).
Then you can see the THD and the levels of individual harmonics if you run the transient analysis and check log file under View > Spice Error Log.

LT SwCAD by default computes for the first 9 harmonics. You can define the number of harmonics you are interested for as well. Then the line should look like:
.four 1kHz 4 V(out)
(assuming you are interested for the first 4 harmonics only)

Pedja
 
You also need to click on "Tools", then on "Control Pannel", then on "Compression". Then uncheck the boxes, the calculation doesn't give reasonable values when applied to compressed data.

Next run the tansient analysis, then click on "View" while the schematic window is selected, then click on "Spice Error Log" and scroll down until you find what you are looking for.

Note that the frequency specified in the ".four" directive must be the same as specified in your signal source when you run the transiient. If you forget and change only one you will get spurious (usually dramaticly so) results.

I've read on the LT spice forum that you get more accurate results if you select "time stop" and "maximum time step" such that the transient spans a whole number of cycles, i.e., no fractional cycles.

I've found 5 cycles are enough to get what I want to know but a few more might help.

Some transient waveforms take a while to reach a steady state, such as when a cap has to charge before the pattern settles down. In this case you will need to specify a start time after the steady state is obtained.

Finally, be aware that the THD figures you will get from circuit you actually construct will not be as good as what you see in LT Spice. Thus "fine tunning" your circuit to get the last .0005% THD out may be educational and entertaining but unlikely to be of any significance when you actually construct the circuit.
 
"So I’m a bit worried here, since I got

Total Harmonic Distortion: -1.#IND00%
with the universal opamp, and then

Total Harmonic Distortion: 579.678388%
with one of the LT opamps.
is there a way to import someone else's opamps since I’m not familiar with LT's products."

I think you need to add code to the universal op amp.

Regarding the other - that sound like what you get when the freq specified in the .four statement is different from the freq specified in the transient analysis.
 
Current harmonics

Hi all,

I am trying to calculate the THD of the output current in Ltspice......(Id(M12)-Id(M13)).....but everytime getting a message that....the current is not present in data....I am attaching the netlist....PLz help..
 

Attachments

  • netlist.txt
    5.6 KB · Views: 71
a few things

this is a multiplier circuit so the appropriate freq for the .four is the fundamental of the output - which is 2x the input

.tran should have step size Tstep and max step dTmax much smaller than the period of anything going on in the circuit to give good resolution and "realistic" distortion # - I changed them to 10nS

an Arbitrary Behavioral source can be used for waveform arithmetic

after you Simulate you can rt click in the plot area
add trace - shows available vars
or even fft - shows the very low 1 MHz "leakage" in the output

modded lines:

.Tran 10ns 100us 0ms 10ns
BI1 0 0 I=(Id(M12)-Id(M13))
.Four 2Meghz I(BI1)

Error Log:

Circuit: ** Gilbert Cell **

Ignoring BSIM parameter XL
Ignoring BSIM parameter XW
Ignoring BSIM parameter XL
Ignoring BSIM parameter XW
Warning: Pd = 0 is less than W.
Warning: Ps = 0 is less than W.
Warning: Pd = 0 is less than W.
Warning: Ps = 0 is less than W.
Warning: Pd = 0 is less than W.
Warning: Ps = 0 is less than W.
.step a=1
Direct Newton iteration for .op point succeeded.
Fourier components of I(bi1)
DC component:-0.00022244

Harmonic Frequency Fourier Normalized Phase Normalized
Number [Hz] Component Component [degree] Phase [deg]
1 2.000e+06 5.348e-05 1.000e+00 58.06° 0.00°
2 4.000e+06 1.002e-06 1.873e-02 50.24° -7.81°
3 6.000e+06 2.637e-07 4.930e-03 -81.36° -139.42°
4 8.000e+06 1.029e-07 1.924e-03 83.78° 25.72°
5 1.000e+07 8.911e-08 1.666e-03 153.70° 95.64°
6 1.200e+07 1.154e-07 2.158e-03 -57.77° -115.82°
7 1.400e+07 1.058e-07 1.979e-03 82.26° 24.20°
8 1.600e+07 3.886e-08 7.267e-04 133.01° 74.95°
9 1.800e+07 4.831e-08 9.033e-04 -116.79° -174.85°
Total Harmonic Distortion: 1.979001%


.step a=2
Fourier components of I(bi1)
DC component:-0.000237197

Harmonic Frequency Fourier Normalized Phase Normalized
Number [Hz] Component Component [degree] Phase [deg]
1 2.000e+06 6.595e-05 1.000e+00 61.12° 0.00°
2 4.000e+06 2.791e-06 4.232e-02 58.87° -2.25°
3 6.000e+06 6.872e-07 1.042e-02 -136.65° -197.77°
4 8.000e+06 3.385e-07 5.132e-03 -55.22° -116.35°
5 1.000e+07 7.404e-08 1.123e-03 4.35° -56.78°
6 1.200e+07 2.470e-07 3.745e-03 118.76° 57.64°
7 1.400e+07 7.445e-08 1.129e-03 -128.27° -189.39°
8 1.600e+07 9.548e-08 1.448e-03 -95.52° -156.64°
9 1.800e+07 3.556e-08 5.392e-04 -0.71° -61.83°
Total Harmonic Distortion: 4.409884%

.step a=3
Fourier components of I(bi1)
DC component:-0.000260279

Harmonic Frequency Fourier Normalized Phase Normalized
Number [Hz] Component Component [degree] Phase [deg]
1 2.000e+06 8.517e-05 1.000e+00 63.18° 0.00°
2 4.000e+06 5.828e-06 6.842e-02 56.42° -6.76°
3 6.000e+06 9.696e-07 1.138e-02 -158.36° -221.55°
4 8.000e+06 4.044e-07 4.748e-03 -118.82° -182.01°
5 1.000e+07 3.679e-07 4.320e-03 -49.24° -112.43°
6 1.200e+07 6.515e-08 7.650e-04 -66.15° -129.33°
7 1.400e+07 1.986e-07 2.331e-03 92.63° 29.45°
8 1.600e+07 1.101e-07 1.293e-03 127.05° 63.86°
9 1.800e+07 6.230e-08 7.315e-04 -144.66° -207.85°
Total Harmonic Distortion: 6.972069%

.step a=4
Fourier components of I(bi1)
DC component:-0.00029115

Harmonic Frequency Fourier Normalized Phase Normalized
Number [Hz] Component Component [degree] Phase [deg]
1 2.000e+06 1.106e-04 1.000e+00 63.98° 0.00°
2 4.000e+06 1.020e-05 9.228e-02 56.00° -7.98°
3 6.000e+06 1.204e-06 1.089e-02 -176.98° -240.97°
4 8.000e+06 7.661e-07 6.928e-03 -146.62° -210.60°
5 1.000e+07 2.604e-07 2.355e-03 -70.50° -134.48°
6 1.200e+07 3.601e-07 3.256e-03 -60.43° -124.41°
7 1.400e+07 5.367e-08 4.853e-04 -4.16° -68.15°
8 1.600e+07 1.433e-07 1.296e-03 81.93° 17.95°
9 1.800e+07 1.311e-07 1.186e-03 112.34° 48.36°
Total Harmonic Distortion: 9.327891%


Date: Thu Mar 19 16:45:49 2009
Total elapsed time: 17.004 seconds.

tnom = 27
temp = 27
method = modified trap
totiter = 37041
traniter = 37032
tranpoints = 13916
accept = 12375
rejected = 1541
matrix size = 28
fillins = 8
solver = Normal
Matrix Compiler1: 1.72 KB object code size 2.2/1.8/[1.4]
Matrix Compiler2: off [1.9]/2.0/2.1
 
Hi JcX,

Thanks for all that useful points...I am not aware of these things....One more point.....after simulating with these conditions i am getting THD of around 12% ......so i want to know.....what are the limits on the input voltage and frequency.....for simulating THD......and also what are the ways to reduce it......??I am attaching the IEEE paper which i am going to simulate....hope to see ur reply soon...
 
So, I have the THD simulations working for a frequency sweep and I have two questions:

1. Is it possible to add in a spice operative so that the transient plot doesn't graph? It's nice to see the multiple sine waves float across the screen, but I think it'd be faster without them.....

2. Is it possible to add a spice operative for windowing functions? I think that the fourier would be more accurate if there was a way to window the transient graph. I guess I could always increase the number of points of the FFT, or only do analysis on frequencies that would have harmonics that lie in a complete cycle within the transient, but it'd be nice to window it so I didn't have to worry as much.

Thanks all. This is a very clever group of people and I learn a lot from here.
 
off topic but wrt LTSpice,

When running analysis with a DN2540, using the supertex.lib file from supertex I get a long list of the following error:

Stray ".ends" card: .ends
quote marks inclusive.
This looks like it is complaining about a .ends following a model definition. However, I can find no .ends which is not associated with a .model line.
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.