Distortion simulation with LTspice

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

has anyone successfuly simulated distortion measurements with ltspice? I've read somewhere an approximation could be obtained with fourier, though i do not know the procedure to accoplish this.
The goal is to simulate THD and, if possible, the distribution across the harmonics.

Thanks and regards,

Tiago
 
The one and only
Joined 2001
Paid Member
I haven't used LTSpice, but I am assuming that nothing radically
new has been developed in Spice algorithms for it.

I don't recommend trying to perform other than crude distortion
analysis with simulation. From my experience, you can't depend
on such numbers, and there are a few texts written that
address these issues, two being Kielkowski's "Spice: Practical
Device Modeling" or Tuinenga's "Spice: A Guide to Circuit
Simulation and Analysis using PSpice".

Both these books are fairly explicit about the limitations of
distortion analysis with Spice. If you really want to know, I
recommend that you build the circuit.
 
Hi tiagor,

There are two rather different points to consider:

1. How to get the THD etc. numbers in LTSpice simulation

2. How these numbers relate to the performance of the real circuit

The caveats of 2. were already addressed by Nelson.

OTOH, you can get some insigts about some sources of THD using SPICE simulation.

Ad 1.

Prerequisite:
- Always turn Compression of in LTSpice's control panel.
- Setup a transient analysis with the analysis time a multiple of your signal generator's period
- If your circuit needs some time to achieve steady state, you must also specify a non-zero start time

Method 1: Add a .fourier command using the "SPICE directive" button. Syntax is described in the online help. E.g. if your signal generator is set to 5k and you want to watch the node named "out" the command would be:
.fourier 5k V(out)
After running the sim, you can see the results using "View SPICE error log"

Method 2: Do a graphical FFT of the transient analysis' output and measure the peaks of the harmonics with the mouse

Method 3: Use Helmut Sennewalds utilities to convert the .raw files written in the transient analysis to ASCII and do further computations with the tool of your choice.

General advice:
-Read the fine online help.
-Join the mailing list http://groups.yahoo.com/group/LTspice/

Regards,
Peter Jacobi
 
I think LTSPICE's accuracy will be somewhat similar to that of PSPICE. Regarding the accuracy of the FFT (needed for THD analysis) within PSPICE I found the following:

http://www.orcadpcb.com/kb_articles/020019.asp?bc=F

an excerpt:

"Simulation Accuracy
Simulation accuracy is limited to about 3-3.5 digits (60-70dBc). The accuracy can be improved by tightening tolerances and taking the above considerations to extremes, but not by very much. This may not be considered sufficient for some applications, but keep in mind that even the best simulation models are probably not accurate enough to provide better results. "

So it is really the best to follow N.P.'s suggestion.

Regards

Charles
 
Hi phase_accurate, All,

phase_accurate said:
I think LTSPICE's accuracy will be somewhat similar to that of PSPICE. Regarding the accuracy of the FFT (needed for THD analysis) within PSPICE I found the following: [...]

After following some tips from the LTSpice mailing list, I see no practical limitation from the FFT accuracy (in LTSpice).

With compression off, alternative solver on, running
.tran 0 12m 0 .1u gives .fourier results down to 3E-6 (110dB dynamic range). The graphical FFT, selecting 65536 points and Hann window, gives a "noise floor" of -200dB. And if you join Bernhard's Church of the Merciless Noise Killing, he will most likely give you the setup for getting down to -300dB.

But these are only numbers in a theoretical game, as the active devices' models are not anywhere near this accuracy.

Regards,
Peter Jacobi
 
With regard to LT-Spice, more than squeezing out the last drop of THD+N, I would ne interested on whether and how .ac or some other analysis to create a Bode plot to be used to predict fairly accurately whether an amp circuit will be stable. I can generate curves that LOOK like a Bode graph and seem to behave to changes in component values in the right direction, but I'm not at all sure I'm using the software appropriately.
 
sam9 said:
With regard to LT-Spice, more than squeezing out the last drop of THD+N, I would ne interested on whether and how .ac or some other analysis to create a Bode plot to be used to predict fairly accurately whether an amp circuit will be stable.[...]

I'm not aware, how to do this (apart from exporting the metlist and re-running in AIMSpice).

You should ask at: http://groups.yahoo.com/group/LTspice/
 
Hi,

Apart from the accuracy of the models you need to know what the basics are behind performing FFT’s.

So start reading a good textbook what it is all behind a FFT. I.e. Spice programs don’t use windowing, which means the number of periods of your signal needs to fit exactly in the measurement time. Also you need to set up your measurement time to an exact multiple of the FFT length and so on. A work-around is to model windowing (i.e. Hamming, Blackman and so on) yourself in the circuit.

Also DC-blocking capacitors and inductors cause DC drift over time, limiting dynamic range. So it is best to avoid capacitors and inductors in the circuit.

With the proper set-up I managed to simulate harmonics below –160 dB. But anyway the results of simulated distortion have limited use. With some luck it will give only a crude indication what to expect in the real thing.

Cheers ;)
 
A beautifully asked question..... it brings tears to my eyes

sam9 said:
With regard to LT-Spice, more than squeezing out the last drop of THD+N, I would ne interested on whether and how .ac or some other analysis to create a Bode plot to be used to predict fairly accurately whether an amp circuit will be stable. I can generate curves that LOOK like a Bode graph and seem to behave to changes in component values in the right direction, but I'm not at all sure I'm using the software appropriately.

You are on the right track for stability analysis. What you what to simulate and then measure is the phase margin when the amp reaches
unity gain. This needs to be done with reactive loads the amp will see
rather than just a purely resistive load. Give this poster a gold star for
brevity along with stating exactly what he wants to know in clear terms that give an indication of his level of understanding so that replies can be right to the point.
 
Re: A beautifully asked question..... it brings tears to my eyes

Fred Dieckmann said:


You are on the right track for stability analysis. What you what to simulate and then measure is the phase margin when the amp reaches
unity gain. This needs to be done with reactive loads the amp will see
rather than just a purely resistive load. Give this poster a gold star for
brevity along with stating exactly what he wants to know in clear terms that give an indication of his level of understanding so that replies can be right to the point.

How do you know he is on the right track and knows what he is
doing?? He doesn't really say much about how he does it now.
I am not trying to claim he doesn't know, but from what he wrote
we do not know. He could be simulating just about anything that
gives a Bode plot. How
many do you think simulate the closed loop response when they
should really simulate the open loop response? Quite a number
of people I think. How many gets the open loop response right?
There has been whole threads on how to do this.

I also think he might be interested to know how and to what
extent a simulated response can be correlated to the real-world
behaviour of a circuit, which I see no hint at addressing in your
post. I certainly question that whenever I do such simulations,
don't you??? Certainly the notoriously bad component models
matter here??

Never trust a Spice simulation. Always interpret the results with
the understanding that it is the results of a simluation only.

By the way, never trust the results from any other computer
programs either unless the program has been formally proven
correct, something which is only very rarely done for some classified
or safety-critical aero-space, military and similar applications. This
includes not trusting what you measure with any test equipment
relying on a microprocessor!!
 
sam9 said:
(...)I would ne interested on whether and how .ac or some other analysis to create a Bode plot to be used to predict fairly accurately whether an amp circuit will be stable.(...)

Hi Sam,

There are two examples dealing with this that come with LTSpice. They use two variants of the so-called "Middlebrook technique" for looking at the loop gain, which gives you the gain and phase margins. The simplified Middlebrook technique is shown in the audioamp.asc file in the examples\educational folder. The simplified technique is very easy to use, but is approximate. It's exact in the case where the current in the voltage source V4 is zero. You can enforce the condition with the circuit I've shown below. The injection point must be inside the innermost loop. Since there is only one loop in the audioamp.asc, you're fine.

But what about cases where you have, say, a capacitor from the VAS collector back to the inverting input of the amp to compensate for capacitive loads? You have two feedback loops now. What do you do? In this case, you must use the "full-up" Middlebrook technique, breaking the loop inside the amp itself, in the innermost loop. The full-up technique is described in the loopgain.asc file in the examples folder. It's significantly more complicated than the simplified technique. You can see in this example that the schematic must be drawn twice. You can get around this using subcircuit replication as I've described here http://www.diyaudio.com/forums/showthread.php?postid=333970#post333970 . You draw the circuit with the loop broken, and two named nodes. Then you make a .asy file with the same file name as the .asc file containing the schematic, with pins having the same name as the node names you supplied in the schematic (LG1 and LG2 in the picture). Then you make a third file for computing the loop gain. The three files must all be in the same folder. When you make the third file and you want to add the two replicated subcircuits, begin by pressing F2 to add a component. Then instead of choosing the components in the normal way, go to the drop-down combo box at the top that says "Top Directory". Choose the current working directory containing your .asc file and .asy file you previously created. You'll see the added .asy file in the list. This is your subcircuit for replication. Do this a second time and you're ready to add the voltage and current sources like the loopgain.asc file has. Also, add the "middlebrook" formula to your plot.defs file per my referenced post. When you do your first plot, do a Plot Settings, save plot settings and save to a file. Later, when you want to do this again, you can do a plot settings, open plot settings file and get your middlebrook expression into your plot instantly (like the plot in my third post in the reference above). You can see in that plot that the CFP has a phase margin of about 60 degrees.

Finally, I've found that by using tricks such as the cap from VAS collector to inverting input, you can get excellent phase margin, yet strange quirks in transient with a square wave. These quirks usually show up when you have a square wave having a baseline of zero volts, and the output voltage is near the zero volt level. In this case, the open-loop output impedance is highest (lowest output current), so the transient oddities seem to show up at this level worse than at the peak of the square wave. So the frequency domain stuff only tells part of the story.
 

Attachments

  • modifiedfb.gif
    modifiedfb.gif
    2.8 KB · Views: 1,290
Hi Pjotr,

Pjotr said:
[...]
I.e. Spice programs don’t use windowing, which means the number of periods of your signal needs to fit exactly in the measurement time. Also you need to set up your measurement time to an exact multiple of the FFT length and so on.
[...]

I agree with your advice about learning about the fourier transformation before using it.

Some nitpicking:

It's 'tapering', not 'windowing', according to my textbooks, but the use of 'windowing' is so widespread by now, that it's somewhat oberlehrerhaft to insist on the correct term.

LTSpice does tapering, with a fine choice of tapers, in its graphical FFT.

Regards,
Peter Jacobi
 
The one and only
Joined 2001
Paid Member
Re: Re: A beautifully asked question..... it brings tears to my eyes

Christer said:

Never trust a Spice simulation. Always interpret the results with
the understanding that it is the results of a simluation only.

By the way, never trust the results from any other computer
programs either unless the program has been formally proven
correct, something which is only very rarely done for some classified or safety-critical aero-space, military and similar
applications. This includes not trusting what you measure with
any test equipment relying on a microprocessor!!

You're right, of course, but even non-trivial aerospace and military
software is not formally proven. The space shuttle for example,
uses multiple computers which have to agree, and a backup
system written by an entirely different software team. And then
they still have a pilot.

I usually trust my simulator when I am assuming linearity. This
is great for working out filters and such, but I don't even bother
to try to predict distortion - even if Spice is perfect, the models
are not.
 
Re: Re: Re: A beautifully asked question..... it brings tears to my eyes

Nelson Pass said:

You're right, of course, but even non-trivial aerospace and military
software is not formally proven. The space shuttle for example,
uses multiple computers which have to agree, and a backup
system written by an entirely different software team. And then
they still have a pilot.

Yes, I am not sure if anything formally verified has actually made
into a working application yet, but I think there are such cases.
However, this is a very difficult thing to do and a lot of research
is going on about how to do such verification. The space shuttle
is very old now, so when designed it was far beyond the possible
to do any such verification. Incidentally, I remember reading about
the early plans for shuttle back in the 70s and orignally the idea
was to write the program in three different versions, using three
different progamming languages. Obviously that idea was later
dropped. The original idea was very sound, especially since
different languages "invite" to different types of errors and since
compilers are not to be trusted (I have experience of that).


I usually trust my simulator when I am assuming linearity. This
is great for working out filters and such, but I don't even bother
to try to predict distortion - even if Spice is perfect, the models
are not.

I suppose that the more experience one has and the better
test equipment one has, the less useful Spice is. I use Spice
mainly as a learning tool. I can verify my understanding of
theory against simulations -- if they agree I probably understood
it right, otherwise either I or Spice is wrong (or maybe both).

It is also useful for complex circuits where the mathematics would
be very involved and complicated. For things like distorsion
analysis, it would obviously be very dangerous to trust a simulation
to predict reality numerically. However, I think it can have some
value for qualitative or coarse quantitative studies. In the simplest
case, if it simulates bad it probably also measures bad, but the
converse is not a safe assumption. I also think, but this is based
on assumptions, that Spice can have some value to make
comparative studies between similar topologies. For instance,
how does the distorsion spectrum change if we make a certain
change to a component value, or a minor modification to the
topology? One shouldn't care too much about the numerical
values, but the relative changes may perhaps say something
interesting if big enough. For instance, we had a thread starting
from a discussion where Pavel Macura said he preferred to use
CFPs as output stage of diamond buffers. I made some simulations
of this, comparing ordinary diamond buffers to CFP ones. I will
skip the details here to cut it short, but the simulation results
indicated that the CFP version would give a considerably lower
distorsion, but a spectrum where the higher harmonics doesn't
fall off as quickly as in the ordinary case. This, if true, would be
an interesting qualitative observation regardless of what the
actual distorsion figures are. Whether this is true or not is
impossible to judge from just a simulation, but in this case it
seemed to correlate to Pavels Measurements and I recently
saw somebody make a similar claim about CFPs in another
unrelated thread (but no reference was given).

The important thing to keep in mind is that no simulation is
better than its models, and the device models are usually
bad. There are also a lot of things we usually don't include
in simulations, like the electrical properties of the PCB, of
component leads etc. etc. It is interesting to ask how good
Spice would predict a real circuit if we had near-perfect component
models, took care to model all parasitics of components, PCB
etc. etc. It is hardly worth doing for any practical purposes, but
I suspect Spice would actually give a very good prediction. Don't
forget that Spice is originally developed to simulate ICs with
the intention of giving better predictions than breadboading
protorypes with discrete components. The big difference here
is that in an IC you have very good control over most parameters,
while simulation of discrete designs introduces many more
parameters which make accurate simulations much more
difficult. (I admit I don't know how many IC manufacturers actually
use Spice, though. I know that some use other simulators, but
then, those are also simulators.)
 
To: Andy_C
Thanks for long explanation and sample. This is the weekend, so I won't be able to dig infor a couple of days. I expect it will take a couple of re-readings for it to sink in.

To: others

What I'm trying to predict is the likelyhood of stability in a power amp. (Leaving aside the effects of stray capacitances and possible malevolent induction from poor PCB layout!) Not one specificly, but to understand using LT-spice for this purpose so I can apply it to any amp design. Also, I'm more than a little aware that Spice simulations are indicators and the real world is likely different. Also .ac is, I understand, just a static calculation; it does not derive from the transient analysis and thus is not really a simulation run.
The comment on open loop vs. closed loop is germaine and part of what I want to know. Or more specifically, I hope, given a generalized Lin topology where is stimulous (AC signal) inserted and from which output node should the results be taken?
 
LTspice or Pspice

Hi Nelson,
You're right, of course, but even non-trivial aerospace and military
software is not formally proven. The space shuttle for example,
uses multiple computers which have to agree, and a backup
system written by an entirely different software team. And then
they still have a pilot.

I usually trust my simulator when I am assuming linearity. This
is great for working out filters and such, but I don't even bother
to try to predict distortion - even if Spice is perfect, the models
are not.

The Simulator it´s agood aprox: 65% of the devolopents the aprox.
But whent you put in side the diferents resistors or capacitors you
can see at my friend Michael percy oy Erno Borbuly or Peter Moncryeff.

The Majority of the people can listening the chance of basic componets
only one resistor or capacitors Nelson.
When a minimalist designer


The Best Regards.

Jesús
 
Andy_c,

I remember you advocating the Middlebrook technique in some
of our earlier discussions. Although I don't doubt it migh be a
better way to do the analysis, it has so far seemed overly
complex to me to be worth the trouble, especially considering
the accurace limitations of a simulations. However, in your recent
post you gave a good argument why it may be useful or even
necessary for certain feedback topologies. Thanks for this added
understanding of this technique.
 
Christer said:
I remember you advocating the Middlebrook technique in some
of our earlier discussions. Although I don't doubt it migh be a
better way to do the analysis, it has so far seemed overly
complex to me to be worth the trouble, especially considering
the accurace limitations of a simulations.(...)

Hi Christer,

As far as I know, both the simple technique of audioamp.asc and the complex technique of loopgain.asc are referred to as the Middlebrook technique. Hopefully I didn't encourage anyone to use the full technique when the much easier one would do. If I did, that's my error for using imprecise terminology. The simplified Middlebrook technique is no more difficult than a simple frequency response simulation, while the full technique is really a pain to set up. That said, it does help to understand the derivation of the full technique in order to understand the limitations of the approximate technique. If anybody's interested in the derivation of the full technique, Jim Thompson does this at his site in the file http://www.analog-innovations.com/LoopGain.zip. There's a similar analysis at http://www.spectrum-soft.com/news/spring97/loopgain.shtm, but they pull some results out of a hat, while Thompson starts from scratch. For the case of the CFP I referenced in my earlier post, I don't think that circuit can be done with the simple technique, as the internal impedance levels don't allow for it.
 
The one and only
Joined 2001
Paid Member
Re: Re: Re: Re: A beautifully asked question..... it brings tears to my eyes

Christer said:
Yes, I am not sure if anything formally verified has actually made............butthen, those are also simulators.)

Couldn't agree more. Probably the space shuttle software is
more provable because it's pretty simple compared to say,
Windows. ;)
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.