Go Back   Home > Forums > >
Home Forums Rules Articles diyAudio Store Blogs Gallery Wiki Register Donations FAQ Calendar Search Today's Posts Mark Forums Read

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

LTspice THD error log question
LTspice THD error log question
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 6th November 2019, 03:30 PM   #1
Aniol1349 is offline Aniol1349
diyAudio Member
 
Join Date: Dec 2014
Default LTspice THD error log question

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!!
Attached Images
File Type: jpg Spice error log.jpg (292.5 KB, 68 views)
File Type: jpg FFT.jpg (292.1 KB, 68 views)
File Type: jpg H2 Generator.jpg (296.4 KB, 71 views)
  Reply With Quote
Old 6th November 2019, 04:00 PM   #2
Boisdechene is offline Boisdechene
diyAudio Member
 
Join Date: Nov 2017
Correct your .four statement.
  Reply With Quote
Old 6th November 2019, 05:00 PM   #3
Ludus Tonalis is offline Ludus Tonalis  Europe
diyAudio Member
 
Join Date: Dec 2009
Location: Southampton and Aegina
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).
  Reply With Quote
Old 6th November 2019, 05:05 PM   #4
JeffYoung is offline JeffYoung  Ireland
diyAudio Member
 
JeffYoung's Avatar
 
Join Date: Jul 2017
Location: Ireland
LTspice THD error log question
You'll probably also need to increase your sample period. (The stop time in your .tran statement.)
  Reply With Quote
Old 6th November 2019, 05:20 PM   #5
Aniol1349 is offline Aniol1349
diyAudio Member
 
Join Date: Dec 2014
Quote:
Originally Posted by Ludus Tonalis View Post
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.

Quote:
Originally Posted by JeffYoung View Post
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?

Quote:
Originally Posted by Boisdechene View Post
Correct your .four statement.
Would you elaborate?

Thanks guys!
Attached Files
File Type: asc 2nd Harmonic Generator.asc (2.5 KB, 7 views)

Last edited by Aniol1349; 6th November 2019 at 05:25 PM.
  Reply With Quote
Old 6th November 2019, 05:34 PM   #6
JeffYoung is offline JeffYoung  Ireland
diyAudio Member
 
JeffYoung's Avatar
 
Join Date: Jul 2017
Location: Ireland
LTspice THD error log question
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.
  Reply With Quote
Old 6th November 2019, 06:19 PM   #7
Ludus Tonalis is offline Ludus Tonalis  Europe
diyAudio Member
 
Join Date: Dec 2009
Location: Southampton and Aegina
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%.
Attached Images
File Type: png 2nd Harmonic Generator (3).PNG (104.1 KB, 58 views)
Attached Files
File Type: asc 2nd Harmonic Generator (3).asc (1.7 KB, 6 views)
  Reply With Quote
Old 6th November 2019, 06:37 PM   #8
edbarx is online now edbarx  Malta
diyAudio Member
 
Join Date: May 2018
Code:
.four <frequency> [Nharmonics] [Nperiods] <data trace1> [<data trace2> ...]


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)
__________________
Thanks for helping me design my first amplifier.
  Reply With Quote
Old 6th November 2019, 10:55 PM   #9
Aniol1349 is offline Aniol1349
diyAudio Member
 
Join Date: Dec 2014
Jeff, Ludus - thanks guys, I owe you a beer!!

Edbarx - thanks for clarifying

As I said I'm still very much learning the tool but I'm amazed how powerful LTspice is!
  Reply With Quote
Old 6th November 2019, 11:21 PM   #10
JeffYoung is offline JeffYoung  Ireland
diyAudio Member
 
JeffYoung's Avatar
 
Join Date: Jul 2017
Location: Ireland
LTspice THD error log question
  Reply With Quote

Reply


LTspice THD error log questionHide 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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
LtSpice missing components error? FriedMule Software Tools 15 22nd October 2019 05:45 PM
Ltspice error gmant123 Software Tools 3 22nd October 2019 04:51 AM
LTSpice Error? Hans Polak Software Tools 18 1st August 2016 07:15 PM
LTspice FFT display does not match spice error log FFT? RJM1 Software Tools 0 21st September 2015 12:56 PM
LTSpice Error Log THD values macplauder Software Tools 3 12th February 2015 08:21 PM


New To Site? Need Help?

All times are GMT. The time now is 10:28 PM.


Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 15.00%
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
Copyright ©1999-2019 diyAudio
Wiki