S-Parameter Simulation with KiCad/ngspice

This is a first test of using the new S parameter feature in upcoming ngspice. Still it is a pure development action, as the full integration of the new feature has not happened yet.

So to run this tests (tested on Windows only), you will need

KiCad 10.99 (nightly build from https://downloads.kicad.org/kicad/windows/explore/nightlies)

ngspice compiled as shared library (source from from git development branch pre-master-48 https://sourceforge.net/p/ngspice/ngspice/ci/pre-master-48/tree/), e.g. ngspice.dll under Windows.

Python installed with matplotlib and pyplot.

Replace ngspice.dll in C:\Program Files\KiCad\10.99\bin by the newly compiled dll.

Four small KiCad 10.99 projects are attached. Principally Eeschema is used. Paths for reading or writing files are hard-coded, thus need to be adapted by the user.

filter137MHz\AC_TRAN_Sim\fi137MHz_origsim.kicad_sch
contains the 137 MHz LC bandpass filter with 50 Ohm dive and 50 Ohms load. Ac and transient simulation are available with Eeschema plotting the results.

filter137MHz\AC_TRAN_Sim\fi137MHz_extrasim.kicad_sch
Again the original circuit, KiCad op sim just to start the ngspice script which does ac and tran sim and then usues pyplot to display the results.

filter137MHz\Create_S_Param\fi137MHz_Spar_create.kicad_sch
Here we create S parameters from the LC filter circuit, by the already integrated SP (S parameter) analysis. A small script on the Eeschema canvas writes Touchstone files when the simulation has finished.

filter137MHz\AC_TRAN_Sim_S_Param\fi137MHz_nport.kicad_sch
This is the S parameter simulation project. The LC filter has been replaced by an nport (here using 2 ports) in the circuit diagram. Its symbol is made locally, just derived from something available. The spice subcircuit model for the symbol is located in file fisub.lib. NPORT reads its input from the file given in Sim.Params. The simulation seqence is:
Start op from KiCad, just as a dummy. After it has finished, the ngspice script from the Eeschema canvas is started:
pre_snp : read S parameters from filt137m.s2p, vector fit, create and write filt137m.nport.
tran : run the transient simulation
pyplot: plot the results
ac : run the ac simulation
pyplot: plot the results

The results from orig and nport simulation are equal.

Currently the internal tran and ac sims cannot be used, as pre_snp has to come first. This has to be integrated into Eeschema, as well as a mopre comfortable file path handling.
