I would like to load a table (for table instead of editing the table manually) into LT spice, but it's very large (180x2 items). Is there a way that I can load a table into LT spice from an external file?

(I know I can load a PWL file from a csv into a voltage source, that isn't what I want to do, I want to do interpolation from a table)

  • \$\begingroup\$ Is your table a .csv file, or similar? LTspice can only import simple pairs of numbers. Extension doesn't matter. \$\endgroup\$ Mar 10 at 18:20
  • \$\begingroup\$ It's nebulous right now, I can make it any format I want \$\endgroup\$
    – Voltage Spike
    Mar 10 at 18:50
  • \$\begingroup\$ Can you give an example of a few pairs of data as input and a draw or some other suggestive description of how the output data should be? What sort of interpolation do you expect? Linear, quadratic, fleur de lis? \$\endgroup\$ Mar 10 at 20:52
  • \$\begingroup\$ Thermistor data, there isn't a high fidelity way to convert from temperature to resistance with good numerical accuacy, the Stienhart-hart equations are not good for this especially the inverse equations. \$\endgroup\$
    – Voltage Spike
    Mar 10 at 21:06
  • \$\begingroup\$ Then, if linear basic interpolation is acceptable, LTspice will do with a PWL. Do you intend to export the interpolated data? As in use LTspice as in intermediary, only? Because other interpolations may be better (Octave's interp1() comes to mind). \$\endgroup\$ Mar 10 at 21:12

As long as the contents of the file has time-value pairs separated by comma or spaces, with or without newline (be it Linux/Unix, Mac, or Windows), it doesn't matter what extension it has. The pairs may or may not be enclosed within parenthesis. The time values must be incremental.

Examples of valid files:

1 2
3 4
5 6
1 2, 3
4, 5 6
1 2 3 ,4 5 , 6 ...
(1 2) (3, 4),(+0.1 -20) ...

All these will work. The spaces and commas are mostly as delimiters, their position doesn't seem to matter much (there may be exceptions, some caution applies). Don't forget that if there are sharp edges, instead of writing (e.g.) 12m 3 12.000001m 4 it's easier to use the relative increment 12m 3 +1n 4. The minus (-) is also available, but only for the values. As far as I know, there is no limit to the file size except your memory (I've worked with tens of thousands of pairs, it was relatively slow, but it worked). Also, it's not limited to PWL(), FREQ() triplets are also welcome.

table() can also be used, but a different approach is needed. By itself, it has no option to load external data, but it can be used as a SPICE netlist:

B1 out 0 v=table(   ; or VCVS, VCCS, etc
+ <data-data pairs>  ; '+' is needed to concatenate the lines
+ ...

This can be placed in a new file, then included in the schematic with .inc /path/to/some.file, or the extra lines can be appended to the already existent file with data. The advantage is that table() is not restricted to strictly increasing increments for the first elements in the data pairs. The disadvantage is the more cumbersome way of loading it. table(), too, has only linear interpolation.

  • \$\begingroup\$ My question has more to do with how do you call the external file and treat it as a table? I'd like to do interpolation from a file \$\endgroup\$
    – Voltage Spike
    Mar 10 at 20:01
  • \$\begingroup\$ The usual PWL file=/path/to/filename.bla will do (or wavefile=... for .wav files, limited to +/- 1). But if what you want is to load the file and rely on LTspice to apply some interpolation other than a simple linear fit, you will be disappointed; linear is the only one it knows. If you want the quadratic interpolation available for the FFT, it will not be visible to the user, it's only applied internally before FFT. But, if linear is what you want, that's the way to go. You may or may not need .opt plotwinsize=0. \$\endgroup\$ Mar 10 at 20:14
  • \$\begingroup\$ I've updated my answer to include the more cumbersome table(). When you said table I thought you meant a spreadsheet. \$\endgroup\$ Mar 10 at 21:46
  • \$\begingroup\$ So it isn't possible, I didnt' think it was, sounds like it's time for a feature request. \$\endgroup\$
    – Voltage Spike
    Mar 10 at 21:51
  • \$\begingroup\$ I wish you good luck, no sarcasm, but I doubt they'll implement it. At any rate, Octave may be more fruitful for this task. \$\endgroup\$ Mar 10 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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