Fast Fourier Transform in SPICE

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
I know most of you guys know SPICE inside and out. I am learning it with Linear Technologies version and have gotten all the basics down.

What am I looking at when I run fast Fourier transform? It gives a plot of dB vs frequency for a specific voltage or current through a component. What does it mean?
 
the "trick" is that 0 dB = 1 Vrms or 1 Arms

so a 1.414 V Sine gives a 0 dB output point on the fft plot

and a 1 V sine would be -3 dB

and since dB is suposed to be power ratio, other V or A rms amplitudes are displayed as 20*Log(x/1 Vrms), or 20*Log(x/1 Arms)

another trick is that LtSpice is optimized for very long runs of their switching regulators, to keep file size down the default setting is to use compression on the data - which adds distortion in simulated waveforms
for most audio circuits you will want to add a spice directive to the sheet:
.option plotwinsize=0

to turn off the data file compression
 
I have posted a few sims and discussed other LtSpice issues in audio simulations here so searching for posts by user "jcx" containing words: "LtSpice" or "photobucket" (where I host my images, ~ 80% will be LtSpice circuit drawing/wave/fft plots) might help you see what can be done with LtSpice sims, often the .asc files are attached as well (my older posts might be better for learning LtSpice sim tricks)
 
Two methods (for LTspice):
1. Use arbitrary behavioral voltage sources and plot them. They support waveform arithmetics.
2. In FFT window right click the plot title. This should open an "expression editor" window. Write expression, press enter.

Another useful command (besides turning compression off) is .fft
The results of using this command can be seen by viewing the spice error log.
 
thanh said:
I want to view FFT of V=Va-Vb. So how can I do ?
Thanks!

When you run your transient analysis, a dialog box will come up. Click once on any voltage listed (or better yet, one that's part of the expression you want to use). Then press Alt and double-click (per the text you see on the dialog). This will bring up the expression editor dialog. If you have previously used F4 to name some nodes, say, a and b, enter the expression V(a)-V(b). If you haven't named the nodes this way, you can escape out and name them now, or you can escape out and hover the mouse over the nodes you want to measure. The status bar will say something like "this is node N025". Then you could memorize those names and use them in the expression. Another way is to start out plotting any old voltage. Then once you get the plot, switch back to schematic view. Click on one of the nodes you want to measure to get a probe. Then drag the probe to the other node. This will plot the difference. To eliminate an unused plot, just right-click on the expression at the top of the plot and choose "delete this trace". This is all in the help files under Waveform viewer, trace selection. To plot the FFT of the waveform, just right-click on the plot and choose "FFT".

If all you care about is a sine wave and its harmonics, just put a ".FOUR" SPICE directive on the schematic directly using the "S" key. It might look something like this:

.four 20kHz 19 v(out)

The frequency in the .FOUR directive must match the frequency of the source. The expression above says to use 19 harmonics to calculate THD. To see the results, run transient and do a "View, SPICE error log". The signal, its harmonics and the THD will be shown in text form in this file. See the help files under "LTSpice, Dot commands" for details of .FOUR.
 
You guys probably know all about this but to get the most out of the FFT you shoul think about this:

1. You have to wait for a steadystate situation in the transient run before you do the fft. (That is, don't do the fft on the data from the start (0s), wait a few periods)

2. Use EXACT numbers of periods of the fundamental frequency for THD sims. Two is enough.

3. For intermodulation sims you have to use the lowest periodic frequency. f2=f1*1.1 => lowest periodic frequency =0.1*f1 (10 times longer sim time!!!!!!!)

4. Use fixed timesteps in the trans sims. Timestep= [2^-n / (lowest periodic frequency)] is a good choise.

5. To improve accuracy change "rel tol", "V tol" and "I tol" in the control panel. Smaller numbers = better accuracy. Too small nubers will only make the sims very slow or you might get DC convergence problems.
(In LTS: Maybe you can switch off the compression here also as jcx suggested??? Or use .option plotwinsize=0 in the schematic)

What is wrong or what did I miss??

:D
 
FFT

So JCX, when SPICE performs an FFT on a circuit, it is varying the frequency of the input and calculating the log of the ratio of the output to input voltage, current or power? In other words if the simulated circuit has a sinusoidal input of 2vrms, the simulator would vary the frequency from x to y Hz and calculate 20log(Vout/Vin) for a particular node for each point from x to y Hz? The ideal amp would give a constant dB value over the entire frequency range? I will try the command you suggest to disable compression.
 
I'm a slow, and ignorant user of LTSpice.

I found the "gurus" on the yahoo groups list to be arrogant, impatient and loathe to answer "simple" questions... not a pleasant place to be for newbies with LT Spice... (like, why does someone feel the need to respond if one doesn't have the time or desire to actually help answer the question(s) posted?? I do not get it at all. :mad: )

So, I wonder is there a specific to LT Spice "for dummies" tutorial somewhere (forget the help file... that's if you start out with a clue), and/or a "generic" Spice For Dummies tutorial downloadable or online??

How about a (gasp) book??

Yes, I have gotten mine to work, and do stuff, but per the post above about not starting from "O" to do FFT, these subtle details do make a big difference in the results. GIGO rules.

Any ideas?

_-_-bear
 
bear said:
So, I wonder is there a specific to LT Spice "for dummies" tutorial somewhere (forget the help file... that's if you start out with a clue), and/or a "generic" Spice For Dummies tutorial downloadable or online??

How about a (gasp) book??

Are you looking for information only pertaining to the FFT in LTSpice or something more general? And for the FFT, do you only want to use it for harmonic distortion sims, or something else? If it's for harmonic distortion only, I think the easiest way to work with it is to use the "S" key to put a SPICE directive directly on the schematic. Here's an example for 20 kHz THD, 19 harmonics at the voltage v(out):

.four 20kHz 19 v(out)

Then, you run the transient sim with sine wave input and do a View, SPICE error log. In the "error log" (misleading name, as it often contains lots of useful info besides errors), you will see the components at each harmonic, with the fundamental normalized to 0 dB. I've found it helpful to set a small time step in the transient sim setup in order to get the best results. Do enough cycles of the sine wave so that any transient will have died out by the end of the sim. See the "dot commands" section in help for more info.

This assumes you know about the ".FOUR" directive, which is part of standard SPICE. I don't know any LTSpice-specific books, but I'd recommend "The SPICE Book" by Vladimirescu for general SPICE information.
 
LtSpice is 99% PSpice compatable I've looked up PSpice functionality in OrCad demo v9.1 documentation pdfs I have on my computer from years ago for use in LtSpice

http://en.wikipedia.org/wiki/SPICE

www.intusoft.com web site with lots of good info in news letters/app notes, some propritatry functionality but most works in LtSpice

the LtSpice Yahoo group is very specifically dedicated to LtSpice usability/bug reporting and detailed functionality - helping new spice users would dilute the useful LtSpice specific information to the point of making it functionally inacessable - searching the msg, file areas gets you many answers that would draw complaints if you start a new and redundant thread
 
I don't get it.
I tried to compute distortion measurements with LTSPice, but got very odd (=way to bad) numbers of known-good circuits.

I tried to track it down. The following minimal 'circuit' gives me an distortion (via error log) of 0.67 %!

What can I do to get it right? For dummies, if you don't mind, as I obviously wasn't able to exract the relevant bits out of the various threads concerning this theme.

thanks a lot,
Rüdiger
 

Attachments

  • dist.jpg
    dist.jpg
    10.7 KB · Views: 436
Hi Rüdiger,

looks like two basic things, in order of importance:

1) turn off data compression (can be done in control panel-->compression or include a ".opt plotwinsize=0" command. (EDIT: saw you did that already)

2) use a small maximum timestep in the .tran analysis, something like 1/1000th of the test freq period. This can easily be parametrized:
.param freq=20kHz
.param period=1/freq ncycles=2
.tran 0 {ncycles*period} 0 {pi/3.14*period/2e3}
.four {freq} xyz

that last value in the .tran is the max timestep, here about 1/2000 of the period length. I make it a little odd with the 3.14/pi stuff, to avoid some spurious harmonics from computation with exact integer multiples. If you want to sim at sub-ppm THD levels, you have go down to 1/10000 or even less.

3) use the alternate solver (also in control panel), this sometimes improves accuracy (ususally rather complex circuits).

".four" takes (by overridable default) only the last period (referring to the freq. it calculates the FFT upon), so usually 2 periods are enough to simulate (assuming that the circuit stabilizes quickly)


- Klaus
 
Klaus,
thanks *a lot*!

Now my distortion numbers are unbelievable low ;-)
(yes, I'm aware that this would most likley not match the real circuit performance)

with the attached arrangement I get 0.000058% harmonic distortion. No discussions regarding load and source impedances for now, please ;-)

Rüdiger
 

Attachments

  • fetfollow.jpg
    fetfollow.jpg
    44.7 KB · Views: 410
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.