Exemple #1
0
    def test_RC1(self):
        """Lcapy: check RC network

        """
        a = Circuit()
        a.add('R1 1 2')
        a.add('C1 2 0')

        self.assertEqual2(a.impedance(1, 2),
                          R('R1').impedance, "Z incorrect for R1.")
        self.assertEqual2(a.impedance(2, 0),
                          C('C1').impedance, "Z incorrect for C1.")
        self.assertEqual2(a.impedance(1, 0), (R('R1') + C('C1')).impedance,
                          "Z incorrect for R1 + C1.")

        self.assertEqual2(a.admittance(1, 2), R('R1').Y, "Y incorrect for R1.")
        self.assertEqual2(a.admittance(2, 0), C('C1').Y, "Y incorrect for C1.")
        self.assertEqual2(a.admittance(1, 0), (R('R1') + C('C1')).Y,
                          "Y incorrect for R1 + C1.")
        self.assertEqual2(a.Isc(1, 0), I(0).Isc, "Isc incorrect")
        self.assertEqual(a.R1.Z, expr('R1'), "Z incorrect")
        self.assertEqual(a.R1.R, expr('R1'), "R incorrect")
        self.assertEqual(a.R1.X, 0, "X incorrect")
        self.assertEqual(a.C1.Y, expr('j * omega * C1'), "Y incorrect")
        self.assertEqual(a.C1.G, 0, "G incorrect")
        self.assertEqual(a.C1.B, expr('-omega * C1'), "B incorrect")
Exemple #2
0
    def test_VRC1(self):
        """Lcapy: check VRC circuit

        """
        a = Circuit()
        a.add('V1 1 0 {V1 / s}')
        a.add('R1 1 2')
        a.add('C1 2 0')

        # Note, V1 acts as a short-circuit for the impedance/admittance
        self.assertEqual2(a.impedance(1, 2), (R('R1') | C('C1')).Z,
                          "Z incorrect across R1")
        self.assertEqual2(a.impedance(2, 0), (R('R1') | C('C1')).Z,
                          "Z incorrect across C1")
        self.assertEqual2(a.impedance(1, 0), R(0).Z, "Z incorrect across V1")

        self.assertEqual2(a.admittance(1, 2), (R('R1') | C('C1')).Y,
                          "Y incorrect across R1")
        self.assertEqual2(a.admittance(2, 0), (R('R1') | C('C1')).Y,
                          "Y incorrect across C1")
        # This has a non-invertible A matrix.
        # self.assertEqual2(a.admittance(1, 0), R(0).Y, "Y incorrect across V1")

        self.assertEqual2(
            a.Voc(1, 0).s,
            V('V1 / s').Voc.s, "Voc incorrect across V1")
        self.assertEqual(a.is_ivp, False, "Initial value problem incorrect")
        self.assertEqual(a.is_dc, False, "DC incorrect")
        self.assertEqual(a.is_ac, False, "AC incorrect")
Exemple #3
0
    def test_RC1(self):
        """Lcapy: check RC network

        """
        a = Circuit()
        a.add('R1 1 2')
        a.add('C1 2 0')

        self.assertEqual2(a.Z(1, 2), R('R1').Z, "Z incorrect for R1.")
        self.assertEqual2(a.Z(2, 0), C('C1').Z, "Z incorrect for C1.")
        self.assertEqual2(
            a.Z(1, 0), (R('R1') + C('C1')).Z, "Z incorrect for R1 + C1.")

        self.assertEqual2(a.Y(1, 2), R('R1').Y, "Y incorrect for R1.")
        self.assertEqual2(a.Y(2, 0), C('C1').Y, "Y incorrect for C1.")
        self.assertEqual2(
            a.Y(1, 0), (R('R1') + C('C1')).Y, "Y incorrect for R1 + C1.")
        self.assertEqual2(a.Isc(1, 0), I(0).Isc, "Isc incorrect")
Exemple #4
0
    def test_VC_dc2(self):
        """Lcapy: check VC dc network

        """

        a = Vdc(4) + C(2, 0)

        self.assertEqual(a.initial_value_problem, True,
                         "initial_value_problem incorrect")
        self.assertEqual(a.is_ac, False, "AC incorrect")
        self.assertEqual(a.is_dc, False, "DC incorrect")
        self.assertEqual(a.i, 0, "Open circuit terminal current not zero")
Exemple #5
0
from lcapy import R, C
n = C(2) | (R(3) + (C(4) | (R(5) + (C(6)))))
n.draw(__file__.replace('.py', '.png'), form='ladder')

from lcapy import Opamp, R, C, Series
import numpy as np
from matplotlib.pyplot import figure, savefig, show

# Create simple differentiator
Ci = 1e-6
Rf = 1e3

a = Opamp()

# Connect V+ to ground.
b = a.short_circuit(1)

# Add feedback resistor.
c = b.bridge(R(Rf))

# Add input capacitor to V-.
d = c.prepend(Series(C(Ci)))

print d.Vtransfer

f = np.logspace(1, 8, 1000)

fig = figure()
ax = fig.add_subplot(111)
Zf = d.Vtransfer.frequency_response(f)
ax.loglog(f, abs(Zf))
ax.grid(True)

show()
Exemple #7
0
from lcapy import C, L
n = (C('C1') | L('L1')) + (C('C2') | L('L2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #8
0
from lcapy import R, C, ladder
n = C('C1') | (R('R1') + (C('C2') | (R('R2') + (C('C3')))))
n2 = ladder(None, C('C1'), R('R1'), C('C2'), R('R2'), C('C3'))
n.draw(__file__.replace('.py', '.png'), layout='ladder')

Exemple #9
0
from lcapy import R, L, C, LSection, pprint, ZPK

C1 = C('C_1')
L1 = L('L_1')
R1 = R('R_1')

a = LSection(R1, C1 | L1)

Av = a.Vtransfer

pprint(Av.canonical())

pprint(Av.ZPK())

pprint(Av.poles())

pprint(Av.zeros())

Exemple #10
0
from lcapy import Vdc, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = R(10) + C(1e-4) + L(1e-3)

a.Z.canonical().pprint()
a.Z.ZPK().pprint()

f = np.logspace(0, 5, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.loglog(f, abs(a.Z.frequency_response(f)), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

show()

b = R('R') + C('C') + L('L')

b.Z.canonical().pprint()
b.Z.ZPK().pprint()
Exemple #11
0
from lcapy import R, C
n = C('C1') | (R('R1') + (C('C2') | (R('R2') + (C('C3') | R('R3')))))
n.draw(__file__.replace('.py', '.png'), form='ladder')

Exemple #12
0
from lcapy import R, C
n = (R('R1') | C('C1')) + (R('R2') | C('C2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #13
0
from lcapy import C, L
n = (C('C1') + L('L1')) | (C('C2') + L('L2'))
n.draw(__file__.replace('.py', '.png'))

Exemple #14
0
from lcapy import R, C, L

n = C('C1') | ((R('R1') + L('L1')) + (C('C2') | ((R('R2') + L('L2')) +
                                                 (C('C3') |
                                                  (R('R3') + L('L3'))))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')
Exemple #15
0
from lcapy import Vdc, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = R(0.1) + C(0.4) + L(0.2)

a.Z.pprint()

f = np.linspace(0, 1000, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(f, abs(a.Z.frequency_response(f)), linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)


show()
Exemple #16
0
Cms = 1.0e-3
S = 310e-4
Bl = 10.0

omegas = 2 * np.pi * fs
Rms = Qms / (omegas * Cms)

Rs = Bl**2 / Rms
Ls = Bl**2 * Cms
Cs = Mms / (Bl**2)

print Rms
print Rs
print Ls
print Cs

a = Series(R(Re) + L(Le)).chain(IdealTransformer(1 / Bl))
b = a.chain(Shunt(R(1 / Rms) | C(Mms) | L(Cms)))

f = np.logspace(0, 5, 2000)
Zin = b.open_circuit(2).Z.frequency_response(f)

fig = figure()
ax = fig.add_subplot(111)
ax.semilogx(f, Zin, linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Impedance (ohms)')
ax.grid(True)

show()
Exemple #17
0
from lcapy import Vstep, R, L, C, t
from matplotlib.pyplot import savefig
from numpy import linspace

a = Vstep(10) + R(0.1) + C(0.4) + L(0.2, 0)

vt = linspace(0, 10, 1000)
a.Isc(t).plot(vt)

savefig('series-VRLC1-isc.png')
Exemple #18
0
from lcapy import R, C, ladder

n = ladder(C(1), R(2), C(3), R(4))
n.draw(__file__.replace('.py', '.png'), layout='ladder')
Exemple #19
0
from lcapy import R, C, L
n = C('C1') | ((R('R1') + L('L1')) + (C('C2') | ((R('R2') + L('L2')) + (C('C3') | (R('R3') + L('L3')) + C('C4')))))
n.draw(__file__.replace('.py', '.png'), layout='ladder')

Exemple #20
0
 def network(self):
     return C(self.value)
Exemple #21
0
print('Series inductors')
L3 = L1 + L2
pprint(L3)
pprint(L3.simplify())
pprint(L3.norton().simplify())


print('Parallel inductors')
L4 = L1 | L2
pprint(L4)
pprint(L4.simplify())
pprint(L4.norton().simplify())


C1 = C(10)
C2 = C(20)

C3 = C1 + C2

print('Series capacitors')
pprint(C3)
pprint(C3.simplify())
pprint(C3.norton().simplify())


C4 = C1 | C2

print('Parallel capacitors')
pprint(C4)
pprint(C4.simplify())
Exemple #22
0
 def network(self):
     return LSection(C('C_block'), R('R_shunt'))
Exemple #23
0
from lcapy import R, C, L

((R(1) + L(2)) | C(3)).smodel().draw('pickup-s.png')
Exemple #24
0
from lcapy import Vdc, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a = (Vdc(5) + R(10)) | C(1)

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(t, a.V.impulse_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

show()
Exemple #25
0
Bl = 10.0

omegas = 2 * np.pi * fs
Rms = Qms / (omegas * Cms)

Rs = Bl**2 / Rms
Ls = Bl**2 * Cms
Cs = Mms / (Bl**2)

print Rms
print Rs
print Ls
print Cs

a = Series(R(Re) + L(Le)).chain(IdealGyrator(Bl))
b = a.chain(Series(R(Rms) + L(Mms) + C(Cms)))

f = np.logspace(0, np.log10(20e3), 2000)
Zin = b.short_circuit(2).Z.frequency_response(f)

fig = figure()
ax = fig.add_subplot(111)
#ax.semilogx(f, abs(Zin), linewidth=2)
ax.semilogx(f, Zin.real, linewidth=2)
#ax.semilogx(f, Zin.imag, linewidth=2)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Resistance (ohms)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
Exemple #26
0
from lcapy import Vdc, R, L, C, LSection, Shunt
import numpy as np
from matplotlib.pyplot import figure, savefig, show

a1 = LSection(L(10), C(1, 5))
b1 = a1.prepend(Shunt(Vdc(5))).load(R(5))

a2 = LSection(L(10), C(1e-10, 5))
b2 = a2.prepend(Shunt(Vdc(5))).load(R(5))

a1 = (Vdc(5) + L(10))
a2 = (Vdc(5) + L(10)) | C(1, 5)
b1 = a1.load(R(5))
b2 = a2.load(R(5))

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Voltage across R
ax.plot(t, b1.V.impulse_response(t), linewidth=2, label='without C')
ax.plot(t, b2.V.impulse_response(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Current through R
ax.plot(t, b1.I.impulse_response(t), linewidth=2, label='without C')
Exemple #27
0
from lcapy import R, C
N = (R(1) + ((R(2) + R(3)) | (C(6) + C(7) + C(8)))) | (R(4) + R(5))
N.draw(label_values=True)



Exemple #28
0
from lcapy import Vstep, R, L, C
import numpy as np
from matplotlib.pyplot import figure, savefig, show

# This is posed as an initial value problem so cannot
# determine result for t < 0.
a1 = Vstep(5) + L(10, 0)
a2 = a1 | C(1, 5)
b1 = a1 | R(5)
b2 = a2 | R(5)

t = np.linspace(-1, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
# Open-circuit voltage across R
ax.plot(t, b1.v.evaluate(t), linewidth=2, label='without C')
ax.plot(t, b2.v.evaluate(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

fig = figure()
ax = fig.add_subplot(111)
# Short-circuit current through R
ax.plot(t, b1.isc.evaluate(t), linewidth=2, label='without C')
ax.plot(t, b2.isc.evaluate(t), linewidth=2, label='with C')
ax.legend()
ax.set_xlabel('Time (s)')
ax.set_ylabel('Current (A)')
Exemple #29
0
from lcapy import R, C, L
(R(2, color='blue') + C(3, color='green')).draw('colors.png')
from lcapy import Istep, R, L, C
from matplotlib.pyplot import figure, savefig, show
import numpy as np

a = Istep(10) | R(0.1) | C(0.4) | L(0.2)

a.Voc.pprint()

t = np.linspace(0, 10, 1000)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(t, a.Voc.transient_response(t), linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Voltage (V)')
ax.grid(True)

savefig('parallel-IRLC1-voc.png')

show()