Electronic – Inserting an unused voltage source in LTspice messes up transient results

ltspicespicetransient

This took me three days to figure out. Consider this simple circuit in LTspice:

enter image description here

Looks pretty innocent. The output is a 1V sine wave, as expected. Going to View->FFT, setting number of data points to 5000, Start Time 50u, End Time 100us. No filtering. This is the output:

enter image description here

An output like this does not quite make sense for a sine wave output and/or a weakly nonlinear system in which the harmonic should fall gently.

Now delete V6 and re-run. Voila, the spectrum makes more sense.

LTspice does not allow for "commenting out" certain blocks and does not even remember the parameters. So if I switch between sin and pulse input, I always have to recreate and memorize the entire parameter set. Hence it makes sense to place all the sources on the schematic and just connect the one with which I am working right now.

I have the suspicion that it has to do with the discrete-time timesteps which are enfored by merely placing a pulse source.

My question is:

  • What did I do wrong?
  • How can this be avoided? In other words, how can I trust the output of a transient analysis?
  • Unfortunately LTspice seems so spartan: Are there any options to enfore a fixed sample step? Any options to resample the transient output such that it is suitable for a DFT?

Best Answer

There is nothing wrong with what you did, but it can be improved. As per the comments and @HKOB's answer, the extra source has a 1ps rise/fall times, compared to its duty cycle of 0.5us. While the PULSE sources are internally fixed valued per timestep -- that is, throughout the simulation, at any time, LTspice knows what values are at what times -- the solver still needs to reduce its timestep in order to accomodate the very sharp rise/fall times. This is, in this case, mostly due to the very smooth nature of the signals (sine input, sine output). This, together with your imposed timestep of 10ns for a period of 1us, makes LTspice generate additional noise, despite .opt plotwinsize=0, but also notice that the values of the induced noise are very small, comparable to the ones for the missing source.

BTW, you can add a 0 to the beginning of the pulse, followed by a comment: 0;pulse ..., this will make the source be zero valued. Or, you can prepare it to be ready for a .step like this: pulse {-a*0.8} {a*0.8} 0 {1p*a} {1p*a} {0.5u*a} {1u*a}, where a can be .step param a list 1 0, for example. Here's the result with these settings:

comp

Notice that the noise (until 100MHz) is actually less than the harmonics due to relatively large timestep, which means it's safe to ignore them, or improve the simulation: simply make the timestep 1ns (1000x less than the period), and re-run.

less

You can go lower, but for the amount of time you're simulating it will get very slow for little added benefit, which means you can reduce the total simulation time to 8-10 periods or similar (unless you really mean to capture the very low frequencies, too) and the result will be faster and with the same relevance.

Unfortunately (and, at least to my knowledge), there is no SPICE simulator that has a true fixed timestep and that is due to the nature of the solver. What timestep you impose only has the effect of restricting the solver to the maximum of those timesteps, but it will go lower if it needs to.