1
\$\begingroup\$

Overlay AC plots using text file

Error

I tried using PWL source and attaching transient simulation text file from other LTSpice schematic run this works good. But when I try AC simulation this is the error.

This is text file content

data

Keeping two schematic side by side and simulating might be one solution.

Can we overlay AC plots in LTSpice? What are the steps?

\$\endgroup\$
1
  • \$\begingroup\$ The message clearly tells you what is missing. Check your text file for correct time-data points. \$\endgroup\$ Commented Jun 12, 2020 at 15:20

1 Answer 1

2
\$\begingroup\$

As I tried to hint in the comment, you exported the results of an .AC analysis and tried to use that as an input for a PWL source, but, as the manual says (emphasis mine):

Syntax: Vxxx n+ n- PWL(t1 v1 t2 v2 t3 v3...)

Arbitrary Piece-wise linear voltage source.

For times before t1, the voltage is v1. For times between t1 and t2, the voltage varies linearly between v1 and v2. There can be any number of time, voltage points given. For times after the last time, the voltage is the last voltage.

That means it only works in time domain. If you want to "overlay" plots in .AC (i.e. two plots in the same window, the usual way), then you need to use the rather archaic FREQ source. Note that this requires the use of the [Misc]/EPOLY source (or GPOLY), it cannot be used with the regular voltage or current sources, but it can be used with behavioural (bv, bi, bi2) sources. Here's an example:

freq

As you can see in the link above, the FREQ source accepts data points in the form of data triplets (frequency, magnitude, phase), but, fortunately, it also accepts the format used for the export data, which you already have.

Now, if you only have a few data triplets, and you want to avoid editing one big line of text as the value for the source (e.g. E2 or B1), you can directly enter it in the form of a SPICE netlist, as seen for E1 (the block of text). But if you have some exported waveform, most likely you'll have tens or hundreds of lines, if not more, in which case you can write down the source as the same SPICE netlist style, but in a separate text, name it however you want (e.g. exported_data.txt), then include that file in the schematic:

.inc /path/to/exported_data.txt

Two things to remember:

  1. when exporting .AC data, the first line will be the header with the labels of the waveforms, as you can see in your post, too. That line will not be recognized by any SPICE programs (I dare say), so it must be either modified, or deleted.
  2. there will be a line break after each data triplet (freq, mag, phase) so, in order for all the data to belong to the first line, you must add a +<space> at the beginning of each line (except the first), which means the lines are concatenated. This can be easily achieved with a search & replace.

For example, here's how the first 5 lines of that exported_data.txt mentioned looked like before:

Freq. V(x)
1.00000000000000e+000   (-2.10000000000000e+001dB,1.80000000000000e+002°)
1.02305972984251e+000   (-2.10000000000000e+001dB,1.80000000000000e+002°)
1.04665121082543e+000   (-2.10000000000000e+001dB,1.80000000000000e+002°)
1.07078670498640e+000   (-2.10000000000000e+001dB,1.80000000000000e+002°)

...and after:

e3 w 0 freq {v(in)}
+ 1.00000000000000e+000 (-2.10000000000000e+001dB,1.80000000000000e+002°)
+ 1.02305972984251e+000 (-2.10000000000000e+001dB,1.80000000000000e+002°)
+ 1.04665121082543e+000 (-2.10000000000000e+001dB,1.80000000000000e+002°)
+ 1.07078670498640e+000 (-2.10000000000000e+001dB,1.80000000000000e+002°)
\$\endgroup\$
1
  • 1
    \$\begingroup\$ One thing I forgot to add: using the EPOLY/GPOLY is a bit useless, since, behind the scene, LTspice converts it to a B-source (for FREQ), a fact easily checked by verifying the expanded netlist in the error log: you'll see something like b§e1 .... \$\endgroup\$ Commented Jun 13, 2020 at 6:20

Your Answer

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

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