Electronic – How to collect data from LTspice

dataltspicesimulation

I am trying to collect data from a circuit and use that data for a regression analysis to get results. For my analysis purpose, one input needs to have different output (as the circuit I am using is the chaotic circuit).

My input is a sinewave with an amplitude of 3V and at 10k frequency. So when I export the data from LTspice, input changes very fast, and even I put very small max step time it doesn't give the same input values like for example for the 1st period of the sine wave the transient analysis collects data when input is at 0.01 then for the other period it's collecting at 0.0139 or something like that.

So, is there a way that I could collect the same input for all the periods of the sinewave?

The circuit I am using:
enter image description here

Thank you in advance, I couldn't get to upload an excel file but I am happy to explain more if needed.

Best Answer

LTspice (like most SPICEs) doesn't perform a .TRAN analysis with a fixed timestep, and that's because of the way the solver works. There are exceptions, though (e.g. see compumike's answer). But if you can tolerate an external utility, there exists one called ltsputil.exe. It can be found in the LTspice group (registration needed, to avoid spammers).

If you're using LTspice XVII, then you will have to first run ltsputil17raw4_1_1.zip because XVII uses UTF for the .raw files, then use the regular ltsputil_2_95a.zip. It will not magically re-calculate all the values to be exact, instead, it will interpolate such that the available data-time points will be evenly spaced. Therefore, as the others have pointed out, imposing a small(er) timestep and/or using .opt plotwinsize=0 will be needed for reliable results.

For your case, this is the command line that you could use:

/path/to/ltsputil.exe -e simulation.raw output.raw 1001

which converts the input file simulation.raw to the newly created output.raw which will have 1001 equidistant points. There are other options and examples, to make ASCII files, linear interpolation, etc; see the file ltsputil_help.txt from the archive. There is also a GUI mode in the folder I linked, I never used it (or if I have, I have already forgotten).


There are at least two other ways to do it:

  1. By perfoming FFT on the desired trace (.opt plotwinsize=0 & imposed timestep will help), then IFFT (FFT on the FFT), which will generate back the time domain response with equispaced samples. LTspice's proprietary algorithm allows for a non-power-of-2 FFT points, which means you can specify the desired number of samples easily. The catch is that the first FFT will be done on an internally quadratically interpolated waveform, so that will be similar to using ltsputil.exe, but slightly more convenient since you're not leaving LTspice's grounds. The drawback is the leakage if not enough points are chosen:

leak

  1. Export the waveform as a .wav file. The drawback is that the limits are +1 and -1, and anything beyond will be hard clipped. The advantage is that you can specify any number of bits (from 1 to 32) and any sample rate (from 1 to 4294967295).

As far as the original answer is concerned, you can improve the time resolution with a simple trick: add a PULSE() voltage source with PULSE 0 1 0 {tr} {T-tr} 0 {T}, where T is the period of the sampling, and tr is the rising time. A value for tr of ~100~1000x less than T is a good choice, which doesn't slow down the simulation too much while having a sufficiently small resolution. The time points for the source will be known to the solver, so for all the times tr is encountered the solver will be forced to reduce the timestep to accomodate the sharp transition, thus providing a cluster of small-spaced points, something like this:

trick

This will help further processing with ltsputil.exe, by providing a denser information region to which to apply the interpolation.