Circuit Simulation In Python

Using SPICE to simulate an electrical circuit is a common enough practice in engineering that “SPICEing a circuit” is a perfectly valid phrase in the lexicon. SPICE as a software tool has been around since the 70s, and its open source nature means there are more SPICE tools around now to count. It also means it is straightforward enough to use with other software as well, like integrating LTspice with Python for some interesting signal processing circuit simulation.

[Michael]’s latest project involves simulating filters in LTspice (a SPICE derivative) and then using Python/NumPy to both provide the input signal for the filter and process the output data from it. Basically, it allows you to “plug in” a graphical analog circuit of any design into a Python script and manipulate it easily, in any way needed. SPICE programs aren’t without their clumsiness, and being able to write your own tools for manipulating circuits is a powerful tool.

This project is definitely worth a look if you have any interest in signal processing (digital or analog) or even if you have never heard of SPICE before and want an easier way of simulating a circuit before prototyping one on a breadboard.

22 thoughts on “Circuit Simulation In Python

  1. The problem with LTspice is its license is tied to non-commercial use.

    A free alternative to LTspice is QUCS.
    https://en.wikipedia.org/wiki/Quite_Universal_Circuit_Simulator

    QUCS has some extra features, including a lot of RF tools, and can also run Octave scripts natively (Octave is the free alternative to Matlab).

    Both LTspice and QUCS are using the same SPICE engine, so they are compatible in parts libraries and simulation models, just that the IDE/GUI/tools are slightly different.

    LTspice has more comfort but less freedom.
    QUCS might seem cumbersome at first, but is free for all and has more RF goodies.

    Both LTspice and QUCS are great tools for simulating electronic circuits, use them both.
    :o)

    1. LTspice and Qucs do not use the same engine.

      LTspice uses a modified version of berkely SPICE3 that is optimized for dealing with the transients found in switchmode power supplies, and as a consequence it is missing some spice3 circuit models.

      Qucs uses qucsator which is incompatible with many of the models from SPICE3, but supports rf/digital work you mentioned.

      There is however a fork of QUCS called Qucs-S which can run any SPICE you have access too (ngspice, etc). As far as I know it is not possible to use the modified version of SPICE3 that comes with LTspice outside of LTspice, but in principal you could export the netlists from Qucs-S into LTspice as long as you don’t use any models that are unsupported by LTspice.

      I personally use Qucs since I usually do rf work, but for switchmode work it is hard to beat LTspice. Outside of those use cases I would recommend Qucs-S

      1. So where does QucsStudio fit in? Link:

        http://dd6um.darc.de/QucsStudio/about.html

        From the QucsStudio “About” page:

        “QucsStudio is mainly a circuit simulator that has evolved out of the project Qucs, but isn’t compatible with it. The simulation engine is even a complete new creation. It’s meant to be a test project to create a complete development environment for electrical engineers… More follows.”

    2. LTSpice is not open source, but I’m pretty sure you can use it for free even for commercial purposes. The only thing you can’t use it for is in marketing or promotion if you are a competing semiconductor manufacturer. Do you have a source for this?

    3. It is not true to say that LTspice is restricted to non-commercial use.

      The only (negotiable!) restriction is:

      “This program is specifically not licensed for use by semiconductor manufacturers in the design, promotion, demonstration, development, or sale of their products. Specific permission must be obtained from Analog Devices for the use of LTspice for these applications.”

      as stated on:

      https://www.analog.com/en/analog-dialogue/articles/get-up-and-running-with-ltspice.html

  2. My open-source SPICE-alike (text input) circuit simulator FoxySim – Web-application (written in Go) intended for online simulation DC & AC electric circuits. This app may be used in teaching theoretical electrical engineering.
    Live simulator running on address: http://sim.foxylab.com/
    GitHub: https://github.com/Dreamy16101976/FoxySim
    When teaching theoretical electrical engineering, much attention is paid to the calculation of linear circuits of sinusoidal current in the steady state. In SPICE, the calculation of this mode is not convenient, but for my simulator this is the native mode. Divide the circuit into elements, number the nodes, enter the netlist, press the button Go! and get the currents, voltages, power, readings of ammeters, voltmeters, wattmeters etc.
    Supported elements: voltage source, current source, VCVS, CCCS, VCCS, CCVS, resistor, inductance (with inductive coupling), capacitance, complex impedance, RG-line, RGLC-line, Ampermeter, voltmeter, wattmeter, varmeter, phasemeter.
    Brief help – http://sim.foxylab.com/help
    Hackaday: https://hackaday.io/project/167846-foxysim

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.