3
\$\begingroup\$

I have used the file _>export facility to generate txt /csv file for subsequent analysis in Matlab. The problem is that the exported waveform time steps are not uniform and the waveform is quantized. Is there a way to avoid this happening to get uniform time steps? As it is I can't use the exported txt waveform.

\$\endgroup\$
1
  • \$\begingroup\$ What do you mean "the waveform is quantized"? If you expexc something continuos coming out from a digital simulation, I have bad news for you. The graphing tool interpolates the data points, but even then the resulting graph is quantized because of your screen or machine precision. If you want it continuos you can draw it by hand on a piece of paper. \$\endgroup\$ Aug 7, 2014 at 8:25

4 Answers 4

3
\$\begingroup\$

LTspice, by default, uses a variable step size which has large values when nothing critical happens (e.g. steady-state) and it tightens them for transients and such. For a specific time-step you can use the builtin maximum simulation step, for example:

.TRAN 0 {final_time} {start_saving_data_optional} {time_step}

Adding an options card such as: .OPT plotwinsize=0 will force the compression to be turned off, as well. There are more options to play around, see the help file or, if you have more intimate questions, ask in the Yahoo's LTspice group (I hope this doesn't count as advertising)

\$\endgroup\$
4
  • 2
    \$\begingroup\$ just to be clear, ALL spice simulators operate in this adaptive manner to speed up the calculations. \$\endgroup\$ Sep 28, 2012 at 0:20
  • 1
    \$\begingroup\$ @rawbrawb I won't contradict you, I haven't used that many SPICE simulators, but I do know this one better than others :) \$\endgroup\$
    – Vlad
    Sep 28, 2012 at 7:50
  • 1
    \$\begingroup\$ wasn't criticizing, just noting a fact, Hop it didn't seem that way. I think SPICE 1 was not adaptive but certainly SPICE 3 is and all modern SPICE derivatives are based off of Version 3F5. \$\endgroup\$ Sep 28, 2012 at 14:35
  • 1
    \$\begingroup\$ @rawbrawb Oh no, far from me that thought, rest assured. \$\endgroup\$
    – Vlad
    Sep 29, 2012 at 7:05
1
\$\begingroup\$

use the .wave ltspice command to produce a .wav file.

wav files can be read using matlab's Audioread command

http://ltwiki.org/LTspiceHelp/LTspiceHelp/_WAVE_Write_selected_nodes_to_a_wav_file_.htm

.WAVE -- Write Selected Nodes to a .Wav File.

LTspice can write .wav audio files. These files can then be listened to or be used as the input of another simulation.

Syntax: .wave <filename.wav> <Nbits> <SampleRate> V(out) [V(out2) ...]

example: .wave C:\output.wav 16 44.1K V(left) V(right)

<filename.wav> is either a complete absolute path for the .wav file you wish to create or a relative path computed from the directory containing the simulation schematic or netlist. Double quotes may be used to specify a path containing spaces. <Nbits> is the number of sampling bits. The valid range is from 1 to 32 bits. <SampleRate> is the number of samples to write per simulated second. The valid range is 1 to 4294967295 samples be second. The remainder of the syntax lists the nodes that you wish to save. Each node will be an independent channel in the .wav file. The number of channels may be as few as one or as many as 65535. It is possible to write a device current, e.g., Ib(Q1) as well as node voltage. The .wav analog to digital converter has a full scale range of -1 to +1 Volt or Amp.

Note that it is possible to write .wav files that cannot be played on your PC sound system because of the number of channels, sample rate or number of bits due to limitations of your PC's codec. But these .wav files may still be used in LTspice as input for another simulation. See the sections LTspice=>Circuit Elements=>V. Voltage Source and I. Current source for information on playing a .wav file into an LTspice simulation. If you want to play the .wav file on your PC sound card, keep in mind that the more popularly supported .wav file formats have 1 or 2 channels; 8 or 16 bits/channel; and a sample rate of 11025, 22050, or 44100 Hz.

insert this into your scematic using the edit->spice directive menu option

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Do emphasize the part where it says The .wav analog to digital converter has a full scale range of -1 to +1 Volt or Amp, because that is the main drawback. \$\endgroup\$ Nov 11, 2018 at 7:24
  • 1
    \$\begingroup\$ I'm just quoting the manual. you can probably say 3*V(node7) etc if you need some gain. \$\endgroup\$ Nov 11, 2018 at 8:13
  • \$\begingroup\$ I know, the same way you can also use an E-source, or similar tricks, but those would only be tricks since they come with a loss of precision. I am only saying this because, most of the time, the need to export with a true equidistant time samples is needed for external FFT analysis, and, alas, the amplification does not recover the floating point precision, which some might find undesirable. Please don't take this as criticism, but as a suggestion, nothing more. \$\endgroup\$ Nov 11, 2018 at 11:34
  • \$\begingroup\$ You can export 32-bit WAV files so there's no real loss of precision. That's a dynamic range of 193 dB. It would of course be more flexible if they output float format WAV files. \$\endgroup\$
    – endolith
    May 27, 2020 at 5:04
1
\$\begingroup\$
.param T=100n
.meas tran result find V(Out) at = T
.step param T 0 1500n 12.5n

This will sample the signal V(Out) with 12.5ns. Open Error Log to view the result. This will look like this:

...
Measurement: result
step    v(out)  at
1  0.000333577  0
2    -0.191173  1.25e-008
3    -0.180665  2.5e-008
4    -0.169657  3.75e-008
...

Keep in mind, that the parametric sweep (.param T=100n) leads to repeation of the transient simulations. Depending on the circuit this can take much time. A workaround is to specify the sampled timesstamps by separate measure-commands. This commands can be generated easily by e.g. sublimetext with text pastry plugin (automatic numer increment at multiple cursors).

.meas tran result0 find V(Out) at = 0u
.meas tran result1 find V(Out) at = 1u
...
.meas tran result10 find V(Out) at = 10u
\$\endgroup\$
1
\$\begingroup\$

The best way to get uniformly sampled data points out of LTSPice is to take the FFT of the data, then take the FFT again of the FFT´d data. This returns the time domain data quantized in uniform steps. This leverages the fact that LTSpice interpolates the data when performing the FFT.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.