LTspice THD error log question

Aniol1349

Member
2014-12-03 8:26 pm
Hello good people of diyaudio!

I'm still in the process of learning LTspice and I have been trying the H2 Generator circuit by Mr. Pass.

I did manage to simulate the circuit and from a quick calculation of the 2nd harmonic I arrived at around 1% distortion which seems correct for this circuit.

I then used the THD calculation directive .four to confirm my math however the result in the error log is like 50% (80%)

could someone clarify for me why the THD level is so high compared to my manual calculation?

Thank you for your time!!
 

Attachments

  • Spice error log.jpg
    Spice error log.jpg
    292.5 KB · Views: 124
  • FFT.jpg
    FFT.jpg
    292.1 KB · Views: 123
  • H2 Generator.jpg
    H2 Generator.jpg
    296.4 KB · Views: 127
You have two .four statements. The first, ".four 1000 100(out)" doesn't make a lot of sense and has been ignored by LTspice. Perhaps you meant to write ".four 1000 100 V(out)"?

The other .four statement ".four 10e3 2 V(out)" calculates the 2nd harmonic distortion present in the 1kHz signal at node (out).

The readings from the fft window, from which I presume you have calculated the THD figure you quote, does not measure the fundamental and 2nd harmonic at node (out). It measures the fundamental at node (n006) and the 2nd harmonic at node (out). It doesn't make a lot of sense to calculate THD using the fundamental and 2nd harmonic present at different nodes. You need to plot only V(out) in the fft window and base your calculation on this.

The dark blue on black background of the fft window is very difficult to see. It would have been more helpful if you had posted the .asc file (as a zip file).
 

Aniol1349

Member
2014-12-03 8:26 pm
You have two .four statements. The first, ".four 1000 100(out)" doesn't make a lot of sense and has been ignored by LTspice. Perhaps you meant to write ".four 1000 100 V(out)"?

The other .four statement ".four 10e3 2 V(out)" calculates the 2nd harmonic distortion present in the 1kHz signal at node (out).

The readings from the fft window, from which I presume you have calculated the THD figure you quote, does not measure the fundamental and 2nd harmonic at node (out). It measures the fundamental at node (n006) and the 2nd harmonic at node (out). It doesn't make a lot of sense to calculate THD using the fundamental and 2nd harmonic present at different nodes. You need to plot only V(out) in the fft window and base your calculation on this.

The dark blue on black background of the fft window is very difficult to see. It would have been more helpful if you had posted the .asc file (as a zip file).

Ok, I deleted the first .four statement, its something I used from a YT tutorial and included along with other statements as I thought it was necessary.

Noted about the fundamental vs 2nd harmonic being from the same node, my manual calculation is still close to -40db (~1%) but very high in the spice error log.

As requested I'm attaching the .asc file (should be fine as .asc without compressing to .zip, right?) I used a LM317 model from someone so not sure if you would need that also.

You'll probably also need to increase your sample period. (The stop time in your .tran statement.)

I did experminet with different sample periods with same outcome?

Correct your .four statement.

Would you elaborate?

Thanks guys!
 

Attachments

  • 2nd Harmonic Generator.asc
    2.5 KB · Views: 17
Last edited:
I'm not sure what your .four statement is trying to do (I'm no SPICE expert), but if I change it to ".four 1khz V(out)" I get reasonable results.

(The spikes in the FFT are still fat because of your sample period, but I don't think that affects the THD report in the error log.)

Note also that you don't need a sample slice as short as 100n for audio. I normally use 10u, or 1u for an FFT.

Cheers,
Jeff.
 
Attached is a marginally reworked .asc file which does what I think you want it to do.

I don't have a model for LM317 so have replaced the power supply circuit with a 14V DC source.

The manually calculated THD and the result of the .four calculation now match up at -42.39dB, or 0.76%.
 

Attachments

  • 2nd Harmonic Generator (3).PNG
    2nd Harmonic Generator (3).PNG
    104.1 KB · Views: 105
  • 2nd Harmonic Generator (3).asc
    1.7 KB · Views: 21
Code:
[FONT=Courier New].four <frequency> [Nharmonics] [Nperiods] <data trace1> [<data trace2> ...][/FONT]


Parameters within '<' and '>' are necessary while parameters within '[' and ']' are optional.

These are possible .four commands:
Code:
.four 1000 9 9 V(n001)
.four 1000 V(n001)
.four 1000 V(n001) V(n006)
.four 1000 9 V(n007)