[Circuit x Python] How to enable the linear circuit analysis package Lcapy

What is Lcapy?

Lcapy is a Python package for analyzing linear circuits and uses sympy for symbol analysis.

Official documentation: Welcome to Lcapy ’s documentation!

Lcapy can perform numerical and symbolic analysis of circuits. Numerical analysis expresses the analysis result numerically, like the result output by the SPICE simulator. Symbol analysis is to express the transfer function and impedance of a circuit with symbols (mathematical formulas). By using this function, you can let the computer do the work of solving troublesome circuit equations.

Lcapy also has the ability to draw textbook-quality schematics on a command basis [^ 1].

As of October 31, 2020, there were no information about Lcapy on Qiita. When I searched on Google, the information was hardly hit not only in Japanese-speaking countries but also in English-speaking countries.

What can you do with Lcapy? You may want to read the Official Documentation Overview. Last but not least, my article on Lcapy may help you get to know the features of Lcapy.

This article describes how to enable Lcapy. We hope that the number of Lcapy users will increase and that we will be able to exchange useful information.

How to use

According to Installation of official documentation, the following python packages are required, so let's install them using pip. lcapy, sympy, numpy, matplotlib, networkx

If you don't use the schematic drawing feature, this is the end of the installation.

Try to move

After installation, let's check the operation on Jupyter-notebook. In Lcapy, the transfer function of the circuit can be obtained by various methods, and an example is shown below.

Circuit for finding the transfer function: image.png

Find the transfer function symbolically


from lcapy import Circuit, s
cct = Circuit("""
Vi 1 0 
R 1 2 RF
C 2 0 CF
""")

H = (cct.C.V(s) / cct.Vi.V(s)).simplify()
H

The execution result is as follows, and the transfer function of the circuit could be analyzed symbolically. $\frac{1}{C_{F} R_{F} s + 1}$

Allows you to create schematics

If you want to use the schematic drawing function, you need to install TeX.

According to the Official Documentation Installation, you need pdflatex, circuitikz, and ghostscript. I found that pdflatex is distributed in W32TeX [^ 2], and the circuitikz package seems to be installed as standard in that W32TeX [^ 3]. It seems that ghostscript can be installed by using W32TeX installer. In other words, if you install only W32TeX, you will have everything you need. W32TeX can be easily installed by using TeX Installer 3.

Try to move

Draw a schematic


from lcapy import Circuit
cct = Circuit("""
Vi 1 0_1 step; down
R 1 2; right, size=1.5
C 2 0; down
W 0_1 0; right
W 0 0_2; right, size=0.5
P1 2_2 0_2; down
W 2 2_2;right, size=0.5""")

cct.draw()

The execution result is as follows, and a beautiful circuit diagram is drawn. image.png

The above code is quoted from: https://github.com/mph-/lcapy/tree/master/doc/examples/notebooks

About circuit symbol analysis

I've been involved in circuit design-related work for several years, but until recently I didn't know the existence of tools that could analyze circuit symbols.

The following doctoral dissertations will be helpful for the types and tools of circuit analysis. About the mathematical behavior of electric circuits and their symbolic calculations

In Table 1.1 of the paper, SAPWIN and SCAM are used as circuit symbol analysis tools. 3443-scam-a-tool-for-symbolically-solving-circuit-equations), WASABI are introduced, but in addition to these, [QSapecNG] There seem to be tools such as (http://qsapecng.sourceforge.net/) and CircuitNAVI. I think it's best to choose the best tool for what you want to do.

In my case, what I wanted to do was:

  1. Symbolically analyze the transfer function of the circuit
  2. Expand the obtained transfer function (find the pole, etc.)
  3. Numerically calculate the obtained transfer function
  4. Display the result of numerical calculation in a beautiful graph. Python (Lcapy) was the best choice for doing this.

I have written the following article about Lcapy, so please have a look there as well. [Circuit x Python] How to find the transfer function of a circuit using Lcapy [Circuit x Python] How to expand and calculate transfer function using Lcapy [^ 1]: Lcapy cannot analyze non-linear devices such as diodes and MOS, but it can be drawn as a circuit diagram.

Recommended Posts

[Circuit x Python] How to enable the linear circuit analysis package Lcapy
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[Algorithm x Python] How to use the list
[Circuit x Python] How to expand and calculate transfer functions using Lcapy
How to get the Python version
[Python] How to import the library
How to package and distribute Python scripts
[Blender x Python] How to use modifiers
How to use the C library in Python
[Python] How to change the date format (display format)
Excel X Python The fastest way to work
How to erase the characters output by Python
How to get the files in the [Python] folder
How to use Ruby's PyCall to enable pyenv Python
[Blender x Python] How to make vertex animation
I tried to find out how to streamline the work flow with Excel x Python ②
[Python] How to remove duplicate values from the list
How to retrieve the nth largest value in Python
How to get the variable name itself in python
Think about how to program Python on the iPad
How to get the number of digits in Python
[For beginners] How to study Python3 data analysis exam
[Introduction to Python] How to iterate with the range function?
How to know the current directory in Python in Blender
[Blender x Python] How to create an original object
[Reintroduction to python] How to import via the parent directory
I tried to find out how to streamline the work flow with Excel x Python ⑤
How to use the Raspberry Pi relay module Python
[Python] How to specify the download location with youtube-dl
How to install python
[Python] How to use the graph creation library Altair
How to make a Python package using VS Code
I tried to find out how to streamline the work flow with Excel x Python ①
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 30. How to use the set
[Python] Summary of how to specify the color of the figure
How to use the model learned in Lobe in Python
[Introduction to Python] How to stop the loop using break?
[Python] How to rewrite the table style with python-pptx [python-pptx]
How to enjoy Python on Android !! Programming on the go !!
[Python] How to output the list values in order
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to simulate how the infection spreads with Python
Try to get the function list of Python> os package
[python] How to check if the Key exists in the dictionary
How to switch the configuration file to be read by Python
How to debug the Python standard library in Visual Studio
[python] How to use the library Matplotlib for drawing graphs
How to use the __call__ method in a Python class
[Hyperledger Iroha] Notes on how to use the Python SDK
How to deploy the easiest python textbook pybot on Heroku
How to make a Python package (written for an intern)
How to get the last (last) value in a list in Python
I didn't know how to use the [python] for statement
How to get into the python development environment with Vagrant
Meteorology x Python ~ From weather data acquisition to spectrum analysis ~
Ruby vs Python Performance. How to pick the right technology?
[Introduction to Python] How to get data with the listdir function
[2020.8 latest] How to install Python
How to install Python [Windows]
python3: How to use bottle (2)