Import target function for NGspice?

Good morning,

simulating /verifying eeschma circuits with ngspice is very useful. Thanks to all contributors!
I wonder if it might be possible to cross-check a circuit output vs. a given target curve/function.
(freq, mag, phase as .frd (txt) file) LOMID.frd (21.6 KB)

Is there a smart way to import this target function into eeschema, so that ngspice will be able to display it?


Hey, Frank. It is not normally possible to do a PWL (piecewise linear) source in the frequency domain. There is a quirky way to rig up such a setup into LTspice and PSpice, but I am unable to find a syntax which ngspice accepts without crashing or complaining. The trick is to use a behavioral voltage source with the FREQ keyword, which allows you to enter in the transfer function in a PWL fashion. Then you simply run the 1V AC source into it and plot the output. Maybe @holger might know more about if it’s possible to get this to work in ngspice, so I’ll attach the the .net that I got working in LTspice along with a screenshot of the plot I was able to acheive doing this. (26.8 KB)

Even if there’s a way to get it to work in ngspice, it still requires a little bit of massaging of the original text file along with sufficient knowledge of subcircuits to get it working within Eeschema. Therefore, may I suggest a different approach? It sounds like you want to overlay a plot of the ngspice simulation output with an output generated elsewhere (i.e. your FRD file). Perhaps you would be better served generating a 2nd text file (in a similar format) using ngspice, and then using a single plotting program (like a Microsoft Excel or something) to plot both files on the same plot pane for comparison. A good discussion on how to export simulation data to text files can be found here:

1 Like

You may try the XSPICE filesource (ngspice manual chapter 12.2.8 Filesource).

1 Like

Thanks, @holger. He needs the data to be imported as (frequency,magnitude,phase) triplets so he can compare it with an AC analysis of his circuit response. I can’t seem to find how to do that using cm_filesource. The manual says it can only take time domain data (in pairs), like you would with a traditional PWL source. LTspice and PSpice allow something called a “FREQ table” using the FREQ keyword, but neither syntax is accepted in ngspice so I’m assuming this is not supported?

If it’s in the manual, it is supported. If not, it’s not supported.

FREQ is not supported.

Indeed the independent variable in filesource is time.

If somebody would take their time to create another filesourceac, reading in frequency (instead of time) values I would be happy to add this to our codemodel selection.

1 Like

Gotcha. I wasn’t sure if I simply overlooked something.

Thanks Ste and Holger for contributing.

Overlaying pdf printouts of target curve and Spice response curve was a feasible workaround.

If a target function could be imported/generated and then be compared to the spice simulation of the Eescheme circuit:
The difference in the magnitude (and phase) of both target and spice transfer function could be retrieved.

And furthermore: this difference could be minimised (numerical solver?) by adjusting component values in Eescheme? Maybe off topic , now.


Optimization in ngspice, see
though still without Eeschema.