eliot-des / CircuitLive

Implementation of the Modified Nodal Analysis Algorithmn for a real-time audio plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CircuitLive : An Audio plugin For Real-Time Emulation of Small Circuits.


This repository is just the implementation of the Modified Nodal Analysis for transient analysis of electronic circuit, into an audio plugin. This is a work in progress and this deposit serves as a test environnement. The aim is to create a functional program capable of loading a netlist in the form of a .txt file, where all the components of the circuit are referenced by their node connections, their values (Ohms, henrys, Farads...), and to simulate the behavior of the circuit for any input signal, and any location where we want to know the output voltage or current.

TO DO List


  • Add different models of diodes, transistors.
  • Avoid plugin crashes when loading/updating/writting an uncorrect netlist.
  • Adaptative font size when changing the size of the plugin's window.
  • Adding labels on the netlist controler sliders, when associated to components.
  • Improve the parsing algorithm (in fact, the algorithm implemented is one of the worst).
  • Add an option to make the computation with dense or sparse matrices.
  • Add an option to make the computation with a different algorithm (Nodal-DK method).

Plugin's GUI


CircuitLive plugin image

The GUI "style" is not my own, but an inspiration of the one seen on this repository.

Plugin's workflow

The plugin is structured around 4 different zones.

-Netlist Editor: text editing area for entering circuit information, commonly referred to as a netlist, on which each line represents a component. The first token defines the component type (e.g., voltage source, resistor), the following tokens specify the nodes connected to the component, and the last tokens indicate component values (e.g., resistance, capacitance, etc.).

-Netlist Controller: area with sliders that can be associated with parameterizable components (poten- tiometers, variable resistors), referenced in the netlist. For example, if you want to associate a potentiometer P1 of maximum value 200 kilo Ohms, for which the end terminals are connected to nodes 0 and 4 and the wiper terminal is connected to node 2, that you want to associate to the slider 3 of the netlist controller, you will have to write down in the netlist editor the following line : P1 0 4 2 200e3 3.

-Simulation Parameters zone: area allowing to control the number of Newton-Raphson iterations (this parameter is only used if your circuit contains non-linear components such as diodes or transistors), as well as the oversampling factor. The higher the number of Newton iterations, the more accurate the emulation. The higher the number of Newton steps, the more precise the emulation. The oversampling factor can be useful to avoid frequency aliasing for nonlinear circuits, and to emulate frequency response more faithfully for linear circuits that modify the transfer function close to Fs/2. In any case, oversampling implies a big drop in performance, the higher the factor and the bigger the circuit.

-Audio zone: controls input and output gain, as well as dry/wet percentage. Input gain is useful if your circuit is nonlinear, in which case it acts as a "drive" knob: the more you increase the gain value, the more likely you are to hear distortion/non-linear phenomena that give character to the sound.

Documentation


The Modified Nodal Analysis Algorithm (MNA) is quite well documented over different books/papers as the following ones :

  • Laurence W. Nagel - SPICE2: A computer program to simulate semiconductor circuits
  • Lawrence T. Pillage, Ronald A. Rohrer, Chandramouli Visweswariah - Electronic Ciruit And System Simulation Methods
  • Stefan Jahn, Michael Margraf, Vincent Habchi, Raimund Jacob - QUCS Technical Papers

Anyway, if you want a if you want a concise text on how the plugin works, you can have a look at the pdf on my repository.

Under the hood of the main algorithm (from QUCS technical papers)


Many different kinds of network element are encountered in network analysis. For circuit analysis it is necessary to formulate equations for circuits containing as many different types of network elements as possible. There are various methods for equation formulation for a circuit. These are based on three types of equations found in circuit theory:

  • equations based on Kirchhoff’s voltage law (KVL)
  • equations based on Kirchhoff’s current law (KCL)
  • branch constitutive equations

The equations have to be formulated (represented in a computer program) automatically in a simple, comprehensive manner. Once formulated, the system of equations has to be solved. There are two main aspects to be considered when choosing algorithms for this purpose: accuracy and speed. The MNA, has been proved to accomplish these tasks. MNA applied to a circuit with passive elements, independent current and voltage sources and active elements results in a matrix equation (linear system) of the form:

$$\mathbf{A}\cdot\mathbf{x} = \mathbf{b},$$

where $\mathbf{A}$ is a square Matrix, and where $\mathbf{x}$ and $\mathbf{b}$ are 1D column vectors (the way that both matrix and vectors are filled is really well documented in both 3 books that are referenced just above). The circuit can therefore be solved by a simple matrix manipulation:

$$\mathbf{x} = \mathbf{A}^{-1}\mathbf{b}$$

or LU decomposition for example. Though this may be difficult by hand, it is straightforward and so is easily done by computer.

Prerequisites


If you want to test this implementation, you will need to have the Eigen library to perform matrix operations.

Licences

The source code in this repository is licensed under the terms of the GPL 3.0 license.

JUCE is copyright © Raw Material Software.

The Raleway font is copyright (c) 2010-2011 Matt McInerney, Pablo Impallari, Rodrigo Fuenzalida and is licensed under the SIL Open Font License (also available with a FAQ at: http://scripts.sil.org/OFL).

The Carlito font is copyright (c) 2010-2014 Łukasz Dziedzic and is licensed under the SIL Open Font License (also available with a FAQ at: http://scripts.sil.org/OFL).

The Consolas font is copyright (c) 2018 Microsoft Corporation. All rights reserved.

About

Implementation of the Modified Nodal Analysis Algorithmn for a real-time audio plugin

License:GNU General Public License v3.0


Languages

Language:C++ 99.7%Language:C 0.3%Language:Objective-C++ 0.1%