Tutorial¶
Simple example - RC low-pass filter¶
Find transfer function from V1 to V(2,0):
import numpy, pylab
from pycircuit.circuit import *
from pycircuit.post.functions import *
## Create circuit
cir = SubCircuit()
cir['VS'] = VS(1, gnd, vac=1.0)
cir['R1'] = R(1, 2, r=1e3)
cir['C1'] = C(2, gnd, c=1e-12)
## Run AC analysis
ac = AC(cir)
result = ac.solve(freqs=numpy.logspace(6,9))
## Plot voltage between net 2 and ground
v2 = db20(result.v(2, gnd))
v2.semilogx()
pylab.grid(True)
(Source code, png, hires.png, pdf)
And now symbolically using a symbolic ac analysis:
import numpy, pylab
from pycircuit.circuit import *
## Create circuit
cir = SubCircuit(toolkit=symbolic)
cir['VS'] = VS(1, gnd, vac=1)
cir['R1'] = R(1, 2, r=Symbol('R1'))
cir['C1'] = C(2, gnd, c=Symbol('C1'))
## Run symbolic AC analysis
ac = AC(cir)
result = ac.solve(freqs=Symbol('s'), complexfreq=True)
## Print transfer function from the voltage source to net 2
simplify(result.v(2, gnd) / result.v(1, gnd))
\[\frac{1.0}{C_{1} R_{1} s + 1}\]
Calculate ABCD parameters:
import numpy, pylab
from pycircuit.circuit import *
## Create circuit
cir = SubCircuit(toolkit=symbolic)
## n1,n2 = nodes('1','2')
cir['R1'] = R(1, 2, r=Symbol('R1'))
cir['C1'] = C(2, gnd, c=Symbol('C1'))
## Run symbolic 2-port analysis
twoport_ana = TwoPortAnalysis(cir, Node('1'), gnd, Node('2'), gnd)
result = twoport_ana.solve(freqs=Symbol('s'), complexfreq=True)
## Print ABCD parameter matrix
ABCD = Matrix(result['twoport'].A)
ABCD.simplify()
ABCD
\[\begin{split}\left[\begin{matrix}C_{1} R_{1} s + 1 & R_{1}\\C_{1} s & 1\end{matrix}\right]\end{split}\]