Giter Site home page Giter Site logo

stepjue / ahkab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahkab/ahkab

0.0 2.0 0.0 11.23 MB

a SPICE-like electronic circuit simulator written in Python

Home Page: https://ahkab.github.io/ahkab/

License: GNU General Public License v2.0

ahkab's Introduction

#Monkeying around ahkab

a SPICE-like electronic circuit simulator written in Python

The code should be easy to read and modify, the main language is Python 2.x and it is platform-independent.githalytics.com alpha

News!

  • Ahkab v0.10 released, including several bugfixes and improvements. Check out the release notes for more!
  • The whole codebase has been going through a (yet incomplete) refactoring and documenting effort. The new documentation is available on RTD.
  • Tests have been added to the code base, to weed out bugs and have a consistent way to check for regressions. If you have tests you would like to suggest, please send a PR my way.
  • My resources are limited these days, so the much-needed work is proceeding slowly, albeit hopefully steadily. If you are interested and you would like to contribute to refactoring or documenting a particular feature, it would be very welcome.

Build Status Coverage Status PyPi version GPLv2 license

Supported simulations:

  • Numeric:
    • Operating point, with guess computation to speed up the solution. See example: Downscaling current mirror
    • DC sweep
    • Transient analysis, available differentiation formulas: implicit Euler, trapezoidal, gear orders from 2 to 5. See for example the simulation of a Colpitts Oscillator.
    • AC analysis
    • PZ analysis (git-tree only)
    • Periodic steady state analysis of non-autonomous circuits, time domain shooting and brute-force algorithms.
  • Symbolic:

The results are saved to disk, plotted or printed to stdout and can be read/processed by the most common tools (eg. Octave, gnuplot, Matlab, gwave and others)

##Install##

The program requires:

  • the Python 2 interpreter (at least v.2.6, and Python3 is in the works),
  • numpy, matplotlib and sympy.

If you need more information about the dependencies, check the Install notes.

##Usage##

  • ahkab can be run within Python scripts as a library.

###Example###

Example schematic: a 5th order 1kHz band-pass Butterworth filter

from ahkab import new_ac, run
from ahkab.circuit import Circuit
from ahkab.plotting import plot_results # calls matplotlib for you
import numpy as np

# Define the circuit
cir = Circuit('Butterworth 1kHz band-pass filter')
cir.add_vsource('V1', 'n1', cir.gnd, dc_value=0., ac_value=1.)
cir.add_resistor('R1', 'n1', 'n2', 50.)
cir.add_inductor('L1', 'n2', 'n3', 0.245894)
cir.add_capacitor('C1', 'n3', 'n4', 1.03013e-07)
cir.add_inductor('L2', 'n4', cir.gnd, 9.83652e-05)
cir.add_capacitor('C2', 'n4', cir.gnd, 0.000257513)
cir.add_inductor('L3', 'n4', 'n5', 0.795775)
cir.add_capacitor('C3', 'n5', 'n6', 3.1831e-08)
cir.add_inductor('L4', 'n6', cir.gnd, 9.83652e-05)
cir.add_capacitor('C4', 'n6', cir.gnd, 0.000257513)
cir.add_capacitor('C5', 'n7', 'n8', 1.03013e-07)
cir.add_inductor('L5', 'n6', 'n7', 0.245894)
cir.add_resistor('R2', 'n8', cir.gnd, 50.)

# Define the analysis
ac1 = new_ac(2.*np.pi*.97e3, 2.*np.pi*1.03e3, 1e2, x0=None)

# run it
res = run(cir, ac1)

# plot the results
plot_results('5th order 1kHz Butterworth filter', [('|Vn8|',"")], res['ac'],
             outfilename='bpf_transfer_fn.png')

Example: AC simulation resultsr

  • or stand-alone with a netlist file, the syntax being:

    $ python ahkab -o graph.dat <netlist file>

See ahkab --help for command line switches.

###Documentation###

Refer to the netlist syntax page for how to write the netlist files that describe the circuit. Experience with running SPICE or other commercial simulators can be useful.

The latter option is shown briefly in the Python API wiki page. The code comes with docstrings associated with most functions, type help(ahkab.function_name).

How this project was born

This project was born when I was an enthusistic undergrad, apparently with plenty of free time, attending "Simulazione Circuitale" (Circuit Simulation) taught by Prof. A. Brambilla back in Italy at the Polytechnic University of Milan.

I am grateful to prof. Brambilla for teaching one of the most interesting courses of my university years. -GV

Contributors

Giuseppe Venturini, Ian Daniher, Rob Crowther.

Bugs and patches

Note that I often add new functionality at the expense of breaking stuff. Most likely I will introduce a new feature even if that means breaking a couple of others. It should get fixed soon, but if you have a bit of time to spare, you can send me a pull request or a patch. :)

Does it work? Bugs? Do you have patches? Did you run some noteworthy simulation? Let me know! Feedback is very welcome, my email address is available after a captcha.

ahkab's People

Contributors

ggventurini avatar itdaniher avatar mightyiam avatar endolith avatar

Watchers

James Cloos avatar Stephen Jue avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.