“Ye cannae change the laws of physics,” so the saying goes. As a regular LTspice user, whenever I get time, I take a look at the excellent LTspice page on EngineerZone https://ez.analog.com/design-tools-and-calculators/ltspice/ for insights and inspiration. Some EZ posts are quite amusing, or alarming, depending on your perspective, proclaiming that LTspice, “… breaks Ohm’s Law,” or, “… doesn’t respect one of Kirchhoff’s Laws,” or, “adds noise to my signal.” You can read my previous post here.
One would be hard-pressed to create a simpler circuit as shown in Figure 1. It’s just a current source and a resistor:
Figure 1. A simple circuit
LTspice File: SimlatorOptions.zip
Our circuit insight tells us that we would expect to see a 20mV peak waveform sitting on a negative 9V DC offset but what we actually get looks like nonsense:
Figure 2. Strange Output
What you see here is an artifact of LTspice’s lossy compression of the raw data file—not unlike a JPEG (lossy) vs. TIFF (lossless) image. LTspice uses compression by default, so the trick is to turn it off and see what happens. Although you can do this in the simulator options (Tools > Control Panel > Compression), compression settings are reset to default values when you restart LTspice. To ensure your schematic preserves your compression settings, use the SPICE directive, ‘.options plotwinsize=0’ to turn off compression. Now we get what we are expecting.
Figure 3. Output as Expected
Precision always comes with trade-offs, so the size of the .raw file in this case inflates from 7kb to 72kb. Simulation speed and waveform display time are relatively insignificant in this case, but for more involved simulations, turning off compression can lead to very large .raw files, which are slow to display, so proceed with caution with this tip.
Top Tip #1: If you get strange-looking waveforms, use .options plotwinsize=0 to turn off compression.
There are many questions on EngineerZone about FFT (Fast Fourier Transform) simulations. Rather than pick out a specific example, here is another simple circuit to show some of the pitfalls.
Figure 4. Another Simple Circuit
LTspice File: FFT.zip
After we run the transient simulation, to look at the FFT from the plot pane, click View > FFT, then select V(output) and click OK.
Figure 5. Strange-Looking FFT
We expect a nice sharp peak at 1kHz but the peak is wide and there is a lot of mess in the spectrum. Part of the problem is that there’s not enough information to generate a good FFT. We can increase the simulation time from 10ms to 50ms to give us more data. The results are shown in Figure 6 below. Now we have a sharper spike, but we have still got some wiggles in the noise floor but now they look worse than before.
Figure 6. Longer Simulation Time
Something else we can do is to increase the number of data points for the FFT by reducing the timestep. Right-click on the simulation command and set the Maximum Timestep to 10ns. The simulation will take more time to complete because of the increased amount of data saved.
Figure 7. Adjusting the Maximum Timestep
Now we have a lower noise floor but there are still some high-frequency spikes. What could be causing those? Is LTspice adding noise to our pure 1kHz sine wave signal?
Figure 8. FFT With Compression
By now your intuition will have kicked in and you are starting to think that these are perhaps compression artifacts. Let’s see what happens when we disable compression using the .options plotwinsize=0 directive.
Figure 9. FFT Without Compression
Well, it looks better but it is not the pure 1kHz sine wave we were expecting. However, we’ve still one more tool in our armory that can help. By default, LTspice uses single-precision calculations but we can ask the simulator to use double-precision numbers with the numdgt option, setting this to a number >6.
Figure 10. Using Double-Precision
At last, a pure sine wave centered at 1kHz with no hash in the noise floor!
Top Tip #2: If you still get strange-looking waveforms, use .options numdgt=15 to use double-precision
I have shared a couple of handy tips to improve the accuracy of our simulations when we need that accuracy to display a sensible waveform. Does LTspice break the laws of physics? I would say rather that LTspice solves problems for engineers and the results you get are usually close enough for all practical purposes. Find the last blog post in this series here.