• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

demo/H02-Dec-2017-5,2164,560

doc/H02-Dec-2017-11,7929,735

lcapy/H02-Dec-2017-16,92511,425

scripts/H02-Dec-2017-161118

.gitignoreH A D02-Dec-2017104 1816

BUGSH A D02-Dec-2017593 1813

LICENCEH A D02-Dec-201725.9 KiB503418

MANIFEST.inH A D02-Dec-2017114 64

READMEH A D02-Dec-20175.5 KiB188134

TODOH A D02-Dec-20175.3 KiB173114

setup.pyH A D02-Dec-2017859 1713

README

1Lcapy is a Python package for linear circuit analysis.  It uses SymPy
2for symbolic mathematics.
3
4Lcapy can analyse circuits described with netlists or by
5series/parallel combinations of components.
6
7From version 0.25.0, Lcapy performs more comprehensive circuit
8analysis using combinations of DC, AC, and Laplace analysis.  This
9added functionality has resulted in a slight change of syntax.
10cct.R1.V no longer prints the s-domain expression but the
11decomposition of a signal into each of the transform domains.
12
13Version 0.25.1 adds time-domain analysis for circuits without reactive
14components.
15
16Version 0.26.0 adds noise analysis.
17
18More comprehensive documentation can be found at http://lcapy.elec.canterbury.ac.nz
19
20
21Circuit analysis
22----------------
23
24The circuit is described using netlists, similar to SPICE, with
25arbitrary node names (except for the ground node which is labelled 0).
26The netlists can be loaded from a file or created at run-time.  For
27example:
28
29   >>> from lcapy import Circuit
30   >>> cct = Circuit()
31   >>> cct.add('Vs 2 0 {5 * u(t)}')
32   >>> cct.add('Ra 2 1')
33   >>> cct.add('Rb 1 0')
34
35The circuit can then be interrogated to determine branch currents,
36branch voltages, and node voltages (with respect to the ground node 0).
37
38   >>> cct[1].v
39   >>> cct[2].v
40   >>> cct.Ra.i
41   >>> cct.Ra.V(s)
42
43
44One-port networks
45-----------------
46
47One-port networks can be created by series and parallel combinations
48of other one-port networks.  The primitive one-port networks are the
49following ideal components:
50
51V independent voltage source
52I independent current source
53R resistor
54C capacitor
55L inductor
56
57These components are converted to s-domain models and so capacitor and
58inductor components can be specified with initial voltage and
59currents, respectively, to model transient responses.
60
61The components have the following attributes:
62
63Zoc open-circuit impedance
64Ysc short-circuit admittance
65Voc open-circuit voltage
66Isc short-circuit current
67
68The component values can be specified numerically or symbolically
69using strings, for example,
70
71from lcapy import Vdc, R, L, C
72
73   >>> R1 = R('R_1')
74   >>> L1 = L('L_1')
75   >>> a = Vdc(10) + R1 + L1
76
77Here a is the name of the network formed with a 10 V DC voltage source in
78series with R1 and L1.
79
80The s-domain open circuit voltage across the network can be printed with:
81   >>> a.Voc.s
82   10/s
83
84The time domain response is given by:
85   >>> a.Voc.transientresponse()
86   10*Heaviside(t)
87
88The s-domain short circuit current through the network can be printed with:
89   >>> a.Isc.s
90   10/(L_1*s**2 + R_1*s)
91
92The time domain response is given by:
93   >>> a.Isc.transientresponse()
94   10*Heaviside(t)/R_1 - 10*exp(-R_1*t/L_1)*Heaviside(t)/R_1
95
96
97Two-port networks
98-----------------
99
100One-port networks can be combined to form two-port networks.  Methods
101are provided to determine transfer responses between the ports.
102
103Here's an example of creating a voltage divider (L section)
104
105   >>> a = LSection(R('R_1'), R('R_2'))
106
107
108Limitations
109-----------
110
1111. Non-linear components cannot be modelled (apart from a linearisation around a bias point).
112
1132. High order systems can go crazy.
114
1153. Some two-ports generate singular matrices.
116
117
118Schematics
119----------
120
121LaTeX schematics can be generated using circuitikz from the netlist.
122Additional drawing hints, such as direction and size are required.
123
124   >>> from lcapy import Circuit
125   >>> cct = Circuit()
126   >>> cct.add('P1 1 0.1; down')
127   >>> cct.add('R1 3 1; right')
128   >>> cct.add('L1 2 3; right')
129   >>> cct.add('C1 3 0; down')
130   >>> cct.add('P2 2 0.2; down')
131   >>> cct.add('W 0 0.1; right')
132   >>> cct.add('W 0.2 0.2; right')
133   >>> cct.draw(filename='pic.tex')
134
135In this example, P denotes a port (open-circuit) and W denotes a wire
136(short-circuit).  The drawing hints are separated from the netlist
137arguments by a semicolon.  They are a comma separated list of
138key-value pairs except for directions where the dir keyword is
139optional.  The symbol label can be changed using the l keyword; the
140voltage and current labels are specified with the v and i keywords.
141For example,
142
143   >>> from lcapy import Circuit
144   >>> cct = Circuit()
145   >>> cct.add('V1 1 0; down')
146   >>> cct.add('R1 1 2; left, i=I_1, v=V_{R_1}')
147   >>> cct.add('R2 1 3; right, i=I_2, v=V_{R_2}')
148   >>> cct.add('L1 2 0.1; down, i=I_1, v=V_{L_1}')
149   >>> cct.add('L2 3 0.3; down, i=I_1, v=V_{L_2}')
150   >>> cct.add('W 0 0.3; right')
151   >>> cct.add('W 0 0.1; left')
152   >>> cct.draw(scale=3, filename='pic2.svg')
153
154The drawing direction is with respect to the positive node; i.e., the
155drawing is performed from the positive to the negative node.  Since
156lower voltages are usually lower in a schematic, then the direction of
157voltage sources and ports is usually down.
158
159By default, component (and current) labels are drawn above horizontal
160components and to the right of vertical components.  Voltage labels
161are drawn below horizontal components and to the left of vertical
162components.
163
164Node names containing a dot or underscore are not displayed.
165
166
167IPython Notebooks
168-----------------
169
170Lcapy can be used with IPython Notebooks (some example notebooks are
171in the notebooks directory).  Schematics are drawn inline using png
172(svg output is currently disabled due to problems with multiple svg
173files sharing the same namespace).  The transient and frequency
174response of a circuit can also be drawn inline using the magic command
175%matplotlib.
176
177
178Documentation
179-------------
180
181For additional documentation, see the Lcapy tutorial at
182http://lcapy.elec.canterbury.ac.nz
183
184Alternatively, the tutorial can be viewed in a web browser after
185running 'make html' in the doc directory.
186
187Copyright 2014--2017 Michael Hayes, UCECE
188