Esempio n. 1
0
 def DrawNE555(self):
     d = schemdraw.Drawing()
     IC555def = elm.Ic(pins=[
         elm.IcPin(name='TRG', side='left', pin='2'),
         elm.IcPin(name='THR', side='left', pin='6'),
         elm.IcPin(name='DIS', side='left', pin='7'),
         elm.IcPin(name='CTL', side='right', pin='5'),
         elm.IcPin(name='OUT', side='right', pin='3'),
         elm.IcPin(name='RST', side='top', pin='4'),
         elm.IcPin(name='Vcc', side='top', pin='8'),
         elm.IcPin(name='GND', side='bot', pin='1'),
     ],
                       edgepadW=.5,
                       edgepadH=1,
                       pinspacing=2,
                       leadlen=1,
                       label='555')
     T = d.add(IC555def)
     BOT = d.add(elm.Ground(xy=T.GND))
     d.add(elm.Dot)
     d.add(elm.Resistor(endpts=[T.DIS, T.THR], label='Rb'))
     d.add(elm.Resistor('u', xy=T.DIS, label='Ra', rgtlabel='+Vcc'))
     d.add(elm.Line(endpts=[T.THR, T.TRG]))
     d.add(
         elm.Capacitor('d',
                       xy=T.TRG,
                       toy=BOT.start,
                       label='C',
                       l=d.unit / 2))
     d.add(elm.Line('r', tox=BOT.start))
     d.add(elm.Capacitor('d', xy=T.CTL, toy=BOT.start,
                         botlabel='.01$\mu$F'))
     d.add(elm.Dot(xy=T.DIS))
     d.add(elm.Dot(xy=T.THR))
     d.add(elm.Dot(xy=T.TRG))
     d.add(elm.Line(endpts=[T.RST, T.Vcc]))
     d.add(elm.Dot)
     d.add(elm.Line('u', l=d.unit / 4, rgtlabel='+Vcc'))
     d.add(elm.Resistor('r', xy=T.OUT, label='330'))
     d.add(elm.LED(flip=True, d='down', toy=BOT.start))
     d.add(elm.Line('l', tox=BOT.start))
     return FigureCanvas(d.draw(show=False).getfig())
Esempio n. 2
0
 def __init__(self):
     QWidget.__init__(self)
     self.layout = QGridLayout(self)
     # # self.imgwidget = QLabel(self)
     # Plot RC filter
     rc = schemdraw.Drawing()
     rc.add(elm.Resistor(d='right', label='R', lftlabel='In', rgtlabel='Out'))
     rc.add(elm.Capacitor(d='down', label='C'))
     rc.add(elm.Ground(d='right'))
     rc.draw(show=False)
     rccanvas = FigureCanvas(rc.draw(show=False).getfig())
     self.layout.addWidget(rccanvas,0,0,2,1)
     self.layout.setMargin(0)
     self.layout.setSpacing(0)
     self.InputWidget=Opreator()
     self.layout.addWidget(self.InputWidget)
Esempio n. 3
0
# Draw circuit
# https://schemdraw.readthedocs.io/en/latest/index.html

import schemdraw
import schemdraw.elements as elm

d = schemdraw.Drawing()
d.add(elm.Line)
d.push()
d.add(elm.Capacitor(d='down', label='$C_0$'))
d.add(elm.Line(d='left'))
d.add(elm.SourceSin(d='up', reverse=True))
d.pop()
d.add(elm.RBox(d='right', label='$2R_1$'))
d.add(elm.Inductor(d='down', botlabel='$L_1$', l=2))
d.add(elm.Capacitor(label='$0.5C_1$', l=1))
d.add(elm.Line(d='left'))

d.draw()
# d.save('basic_rc.svg')

# 기본 l값 3
# Capacitor, Line ,Resigster, Inductor, RBox
# tox => 두가지 더함
def DirectCoupled_C_Coupled_ShuntResonators(gi, RS, RL, f0, BW, Lres, fstart,
                                            fstop, npoints):
    Nres = len(gi) - 2  # Number of resonators
    bw = BW / f0

    # Calculation of w1, w2, w - 8.11-1 (15)
    f1 = f0 - BW / 2
    f2 = f0 + BW / 2

    w1 = 2 * np.pi * f1
    w2 = 2 * np.pi * f2

    w0 = np.sqrt(w1 * w2)
    w = (w2 - w1) / w0

    # Calculation of GA and GB
    GA = 1 / RS
    GB = 1 / RL

    # Draw circuit
    schem.use('svg')
    d = schem.Drawing(inches_per_unit=0.3)
    _fontsize = 8

    # Network
    rf.stylely()
    freq = rf.Frequency(start=fstart, stop=fstop, npoints=npoints, unit='MHz')
    line = rf.media.DefinedGammaZ0(frequency=freq)

    # Component counter
    count_C = 0
    count_L = 0
    count_gnd = 0

    params = {}
    params['Xres'] = Lres
    params['gi'] = gi
    params['N'] = Nres
    params['ZS'] = RS
    params['ZL'] = RL
    params['f1'] = f1
    params['f2'] = f2
    Cseries, Lres, Cres = synthesize_DC_Filter_C_Coupled_Shunt_Resonators(
        params)

    # Source port
    # Drawing: Source port and the first line
    d += elm.Line(color='white').length(2).linewidth(0)
    d += elm.Dot().label('ZS = ' + str(RS) + " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    d += elm.Line().length(1).linewidth(1)

    # Network: Port 1
    connections = []  # Network connections
    L = []
    C = []
    ground = []
    Port1 = rf.Circuit.Port(frequency=freq, name='port1', z0=RS)

    # First coupling capacitor
    # Drawing
    d += elm.Capacitor().right().label(getUnitsWithScale(
        Cseries[0], 'Capacitance'),
                                       fontsize=_fontsize).linewidth(1)
    d += elm.Line().right().length(1).linewidth(1)

    # Network
    count_C += 1
    C.append(line.capacitor(Cseries[0], name='C' + str(count_C)))

    connections.append([(Port1, 0), (C[0], 0)])

    for i in range(0, Nres):
        # Resonator

        # Drawing
        d.push()
        d += elm.Line().down().length(1).linewidth(1)
        d.push()
        d += elm.Line().left().length(1.5).linewidth(1)
        d += elm.Capacitor().down().label(getUnitsWithScale(
            Cres[i], 'Capacitance'),
                                          fontsize=_fontsize).linewidth(1)
        d += elm.Ground().linewidth(1)

        d.pop()
        d += elm.Line().right().length(1.5).linewidth(1)
        d += elm.Inductor2(loops=2).down().label(
            getUnitsWithScale(Lres[i],
                              'Inductance'), fontsize=_fontsize).linewidth(1)
        d += elm.Ground().linewidth(1)

        # Network
        count_C += 1
        C.append(line.capacitor(Cres[i], name='C' + str(count_C)))
        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        count_L += 1
        L.append(line.inductor(Lres[i], name='L' + str(count_L)))
        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        # Next coupling capacitor
        # Drawing
        d.pop()
        d += elm.Line().right().length(1.5).linewidth(1)
        d += elm.Capacitor().right().label(getUnitsWithScale(
            Cseries[i + 1], 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)
        d += elm.Line().right().length(1.5).linewidth(1)

        # Network
        count_C += 1
        C.append(line.capacitor(Cseries[i + 1], name='C' + str(count_C)))

        # Connections
        connections.append([(C[2 * i], 1), (C[2 * i + 1], 0),
                            (C[2 * i + 2], 0), (L[i], 0)])
        connections.append([(C[2 * i + 1], 1), (ground[2 * i], 0)])
        connections.append([(L[i], 1), (ground[2 * i + 1], 0)])

    # Drawing
    d += elm.Dot().label('ZL = ' + str(float("{:.2f}".format(RL))) + " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    d += elm.Line(color='white').length(2).linewidth(0)
    # Network
    Port2 = rf.Circuit.Port(frequency=freq, name='port2', z0=RL)

    # Connections
    connections.append([(C[-1], 1), (Port2, 0)])

    return d, connections
def DirectCoupled_C_Coupled_SeriesResonators(params, port_match):
    gi = params['gi']
    f1 = params['f1']
    f2 = params['f2']
    fstart = params['f_start']
    fstop = params['f_stop']
    npoints = params['n_points']
    RS = params['ZS']
    RL = params['ZL']

    Nres = len(gi) - 2  # Number of resonators

    w1 = 2 * np.pi * f1
    w2 = 2 * np.pi * f2

    w0 = np.sqrt(w1 * w2)
    w = (w2 - w1) / w0

    # Draw circuit
    schem.use('svg')
    d = schem.Drawing(inches_per_unit=0.3)
    _fontsize = 8

    # Network
    rf.stylely()
    freq = rf.Frequency(start=fstart, stop=fstop, npoints=npoints, unit='MHz')
    line = rf.media.DefinedGammaZ0(frequency=freq)

    # Component counter
    count_C = 0
    count_L = 0
    count_gnd = 0

    syn_params = {}
    syn_params['gi'] = params['gi']
    syn_params['N'] = params['N']
    syn_params['ZS'] = params['ZS']
    syn_params['ZL'] = params['ZL']
    syn_params['f1'] = float(params['f1']) * 1e6
    syn_params['f2'] = float(params['f2']) * 1e6
    syn_params['Xres'] = [float(i) * 1e-9
                          for i in params['Xres']]  # Resonator inductance
    Match_source, Match_load, Cinv, Lres, Cres = synthesize_DC_Filter_C_Coupled_Series_Resonators(
        syn_params)

    # Source port
    # Drawing: Source port and the first line
    d += elm.Line(color='white').length(2).linewidth(0)
    d += elm.Dot().label('ZS = ' + str(RS) + " \u03A9",
                         fontsize=_fontsize,
                         loc='bottom').linewidth(1)
    d += elm.Line().length(1).linewidth(1)

    # Network: Port 1
    connections = []  # Network connections
    L = []
    C = []
    ground = []
    Port1 = rf.Circuit.Port(frequency=freq, name='port1', z0=RS)

    # First coupling

    if (port_match[0] == 'C'):
        # Drawing
        d += elm.Capacitor().right().label(getUnitsWithScale(
            Match_source, 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)
        d += elm.Line().right().length(1).linewidth(1)

        # Network
        C.append(line.capacitor(Match_source, name='C' + str(count_C)))
        connections.append([(Port1, 0), (C[0], 0)])

    else:
        # Drawing
        d += elm.Inductor2(loops=2).right().label(
            getUnitsWithScale(Match_source,
                              'Inductance'), fontsize=_fontsize).linewidth(1)
        d += elm.Line().right().length(1).linewidth(1)

        # Network
        L.append(line.inductor(Match_source, name='L' + str(count_L)))
        connections.append([(Port1, 0), (L[0], 0)])

    for i in range(0, Nres):
        # Resonator

        # Drawing
        d.push()
        d += elm.Capacitor().down().label(getUnitsWithScale(
            Cinv[i], 'Capacitance'),
                                          fontsize=_fontsize).linewidth(1)
        d += elm.Ground().linewidth(1)

        # Network
        count_C += 1
        C.append(line.capacitor(Cinv[i], name='C' + str(count_C)))
        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        d.pop()
        d += elm.Inductor2(loops=2).right().label(
            getUnitsWithScale(Lres[i],
                              'Inductance'), fontsize=_fontsize).linewidth(1)
        d += elm.Capacitor().right().label(getUnitsWithScale(
            Cres[i], 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)

        count_L += 1
        L.append(line.inductor(Lres[i], name='L' + str(count_L)))
        count_C += 1
        C.append(line.capacitor(Cres[i], name='C' + str(count_C)))

        # Connections
        if (port_match[0] == 'C'):
            connections.append([(C[2 * i], 1), (C[2 * i + 1], 0), (L[i], 0)])
            connections.append([(L[i], 1), (C[2 * i + 2], 0)])
            connections.append([(C[2 * i + 1], 1), (ground[i], 0)])
        else:  # There's one inductance too much and one capacitor too few
            if (i == 0):  # The first element must connect to the inductor
                connections.append([(L[0], 1), (C[2 * i], 0), (L[i + 1], 0)])
            else:
                connections.append([(C[2 * i - 1], 1), (C[2 * i], 0),
                                    (L[i + 1], 0)])
            connections.append([(L[i + 1], 1), (C[2 * i + 1], 0)])
            connections.append([(C[2 * i], 1), (ground[i], 0)])

    # Drawing
    d.push()
    d += elm.Capacitor().down().label(getUnitsWithScale(
        Cinv[-1], 'Capacitance'),
                                      fontsize=_fontsize).linewidth(1)
    d += elm.Ground().linewidth(1)

    count_C += 1
    C.append(line.capacitor(Cinv[-1], name='C' + str(count_C)))
    count_gnd += 1
    ground.append(
        rf.Circuit.Ground(frequency=freq,
                          name='ground' + str(count_gnd),
                          z0=RS))

    d.pop()
    if (port_match[1] == 'C'):
        d += elm.Capacitor().right().label(getUnitsWithScale(
            Match_load, 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)
        count_C += 1
        C.append(line.capacitor(Match_load, name='C' + str(count_C)))
    else:
        d += elm.Inductor2(loops=2).right().label(
            getUnitsWithScale(Match_load,
                              'Inductance'), fontsize=_fontsize).linewidth(1)
        count_L += 1
        L.append(line.capacitor(Match_load, name='L' + str(count_L)))

    # Load port
    # Drawing
    d += elm.Line().length(1).linewidth(1)
    d += elm.Dot().label('ZL = ' + str(float("{:.2f}".format(RL))) + " \u03A9",
                         fontsize=_fontsize,
                         loc='bottom').linewidth(1)
    d += elm.Line(color='white').length(2).linewidth(0)

    # Network
    Port2 = rf.Circuit.Port(frequency=freq, name='port2', z0=RL)

    # Connections
    if (port_match[1] == 'C'):
        connections.append([(C[-3], 1), (C[-2], 0), (C[-1], 0)])
        connections.append([(C[-2], 1), (ground[-1], 0)])
        connections.append([(C[-1], 1), (Port2, 0)])
    else:
        connections.append([(C[-2], 1), (C[-1], 0), (L[-1], 0)])
        connections.append([(C[-1], 1), (ground[-1], 0)])
        connections.append([(L[-1], 1), (Port2, 0)])

    return d, connections
def DirectCoupled_L_Coupled_SeriesResonators(params):
    gi = params['gi']
    RS = params['ZS']
    RL = params['ZL']
    f1 = params['f1']
    f2 = params['f2']
    f0 = params['fc']
    Magnetic_Coupling = params['Magnetic_Coupling']
    fstart = params['f_start']
    fstop = params['f_stop']
    npoints = params['n_points']

    w0 = 2 * np.pi * f0 * 1e6

    Nres = len(gi) - 2  # Number of resonators
    # Draw circuit
    schem.use('svg')
    d = schem.Drawing(inches_per_unit=0.3)
    _fontsize = 8

    # Network
    rf.stylely()
    freq = rf.Frequency(start=fstart, stop=fstop, npoints=npoints, unit='MHz')
    line = rf.media.DefinedGammaZ0(frequency=freq)

    # Component counter
    count_C = 0
    count_L = 0
    count_gnd = 0

    params['f1'] = params['f1'] * 1e6
    params['f2'] = params['f2'] * 1e6
    M, Lseries, Cres = synthesize_DC_Filter_L_Coupled_Series_Resonators(params)

    if (Magnetic_Coupling == 0):
        # Source port
        # Drawing: Source port and the first line
        d += elm.Dot().label('ZS = ' + str(RS) + " \u03A9",
                             fontsize=_fontsize).linewidth(1)
        d += elm.Line().length(1).linewidth(1)

        # Network: Port 1
        connections = []  # Network connections
        L = []
        C = []
        ground = []
        Port1 = rf.Circuit.Port(frequency=freq, name='port1', z0=RS)

        # First coupling inductor
        # Drawing
        d += elm.Inductor2(loops=2).right().label(
            getUnitsWithScale(Lseries[0],
                              'Inductance'), fontsize=_fontsize).linewidth(1)

        # Network
        count_L += 1
        L.append(line.inductor(Lseries[0], name='L' + str(count_L)))

        connections.append([(Port1, 0), (L[0], 0)])

        for i in range(0, Nres + 1):
            d.push()
            # Coupling
            # Drawing
            d += elm.Inductor2(loops=2).down().label(
                getUnitsWithScale(M[i], 'Inductance'),
                fontsize=_fontsize).linewidth(1)
            d += elm.Ground().linewidth(1)

            #Network
            count_L += 1
            L.append(line.inductor(M[i], name='L' + str(count_L)))
            count_gnd += 1
            ground.append(
                rf.Circuit.Ground(frequency=freq,
                                  name='ground' + str(count_gnd),
                                  z0=RS))

            d.pop()
            # Series resonator
            d += elm.Inductor2(loops=2).right().label(
                getUnitsWithScale(Lseries[i + 1], 'Inductance'),
                fontsize=_fontsize).linewidth(1)
            count_L += 1
            L.append(line.inductor(Lseries[i + 1], name='L' + str(count_L)))

            if (i < Nres):
                d += elm.Capacitor().right().label(
                    getUnitsWithScale(Cres[i], 'Capacitance'),
                    fontsize=_fontsize).linewidth(1)
                count_C += 1
                C.append(line.capacitor(Cres[i], name='C' + str(count_C)))

            # Connections
            if (i == 0):
                # Then, connect to the first inductor
                connections.append([(L[0], 1), (L[1], 0), (L[2], 0)])
                connections.append([(L[1], 1), (ground[i], 0)])
                connections.append([(L[2], 1), (C[i], 0)])
            else:
                # Then, connect to the previous capacitor
                connections.append([(C[i - 1], 1), (L[2 * i + 1], 0),
                                    (L[2 * i + 2], 0)])
                connections.append([(L[2 * i + 1], 1), (ground[i], 0)])
                if (i < Nres):
                    # The last iteration is the coupling for the load port
                    connections.append([(L[2 * i + 2], 1), (C[i], 0)])

        # Drawing
        d += elm.Line().length(1).linewidth(1)
        d += elm.Dot().label('ZL = ' + str(float("{:.2f}".format(RL))) +
                             " \u03A9",
                             fontsize=_fontsize).linewidth(1)
        # Network
        Port2 = rf.Circuit.Port(frequency=freq, name='port2', z0=RL)

        # Connections
        connections.append([(L[-1], 1), (Port2, 0)])
    else:
        # Magnetic coupling
        Lp = Lseries

        # Source port
        # Drawing: Source port and the first line
        d += elm.Line(color='white').length(2).linewidth(0)
        d += elm.Dot().label('ZS = ' + str(RS) + " \u03A9",
                             fontsize=_fontsize).linewidth(1)
        d += elm.Line().length(2).linewidth(1)

        # Network: Port 1
        connections = []  # Network connections
        L = []
        C = []
        ground = []

        count_L = 0
        count_C = 0
        count_gnd = 0

        Port1 = rf.Circuit.Port(frequency=freq, name='port1', z0=RS)

        for i in range(0, Nres):
            x = d.add(
                elm.Transformer(
                    t1=4, t2=4, loop=True, core=True,
                    fontsize=_fontsize).label(
                        getUnitsWithScale(Lp[i], 'Inductance'),
                        loc='left').label(
                            getUnitsWithScale(Lp[i + 1], 'Inductance'),
                            loc='right').label("k = " + str(
                                round(M[i] / np.sqrt(Lp[i] * Lp[i + 1]), 3)),
                                               loc='top').flip())
            d += elm.Ground().at(x.p1).linewidth(1)
            d += elm.Ground().at(x.s1).linewidth(1)
            d += elm.Line().at(x.s2).length(1)
            d += elm.Capacitor().right().label(getUnitsWithScale(
                Cres[i], 'Capacitance'),
                                               fontsize=_fontsize).linewidth(1)
            d += elm.Line().length(1)

            # Network: The transformer is simulated using the uncoupled lumped equivalen (Zverev, Fig. 10.4 (c))
            count_L += 1
            L.append(line.inductor(Lp[i] - M[i], name='L' + str(count_L)))
            count_L += 1
            L.append(line.inductor(M[i], name='L' + str(count_L)))
            count_L += 1
            L.append(line.inductor(Lp[i + 1] - M[i], name='L' + str(count_L)))

            count_gnd += 1
            ground.append(
                rf.Circuit.Ground(frequency=freq,
                                  name='ground' + str(count_gnd),
                                  z0=RS))
            count_C += 1
            C.append(line.capacitor(Cres[i], name='C' + str(count_C)))

            print("L[" + str(3 * i) + "] = ",
                  getUnitsWithScale(Lp[i] - M[i], 'Inductance'))
            print("L[" + str(3 * i + 1) + "] = ",
                  getUnitsWithScale(M[i], 'Inductance'))
            print("L[" + str(3 * i + 2) + "] = ",
                  getUnitsWithScale(Lp[i + 1] - M[i], 'Inductance'))
            print("C[" + str(i) + "] = ",
                  getUnitsWithScale(Cres[i], 'Capacitance'))

            # Connections
            if (i == 0):
                # Connect the first inductor to the source port
                connections.append([(Port1, 0), (L[0], 0)])
            else:
                # Connect the first inductor to the previous capacitor
                connections.append([(C[i - 1], 1), (L[3 * i], 0)])

            connections.append([(L[3 * i], 1), (L[3 * i + 1], 0),
                                (L[3 * i + 2], 0)])
            connections.append([(L[3 * i + 1], 1), (ground[i], 0)])
            connections.append([(L[3 * i + 2], 1), (C[i], 0)])

        x = d.add(
            elm.Transformer(
                t1=4, t2=4, loop=True, core=True, fontsize=_fontsize).label(
                    getUnitsWithScale(Lp[-2], 'Inductance'), loc='left').label(
                        getUnitsWithScale(Lp[-1], 'Inductance'),
                        loc='right').label(
                            "k = " +
                            str(round(M[-1] / np.sqrt(Lp[-2] * Lp[-1]), 3)),
                            loc='top').flip())
        d += elm.Ground().at(x.p1).linewidth(1)
        d += elm.Ground().at(x.s1).linewidth(1)

        # Network: The transformer is simulated using the uncoupled lumped equivalen (Zverev, Fig. 10.4 (c))
        count_L += 1
        L.append(line.inductor(Lp[-2] - M[-1], name='L' + str(count_L)))
        count_L += 1
        L.append(line.inductor(M[-1], name='L' + str(count_L)))
        count_L += 1
        L.append(line.inductor(Lp[-1] - M[-1], name='L' + str(count_L)))

        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        print("L[" + str(3 * Nres) + "] = ",
              getUnitsWithScale(Lp[-2] - M[-1], 'Inductance'))
        print("L[" + str(3 * Nres + 1) + "] = ",
              getUnitsWithScale(M[-1], 'Inductance'))
        print("L[" + str(3 * Nres + 2) + "] = ",
              getUnitsWithScale(Lp[-1] - M[-1], 'Inductance'))

        # Load port
        d += elm.Line().at(x.s2).length(2).linewidth(1)
        d += elm.Dot().label('ZL = ' + str(RL) + " \u03A9",
                             fontsize=_fontsize).linewidth(1)
        d += elm.Line(color='white').length(2).linewidth(0)

        Port2 = rf.Circuit.Port(frequency=freq, name='port2', z0=RL)

        # Connections
        connections.append([(C[-1], 1), (L[-3], 0)])
        connections.append([(L[-3], 1), (L[-2], 0), (L[-1], 0)])
        connections.append([(L[-2], 1), (ground[-1], 0)])
        connections.append([(L[-1], 1), (Port2, 0)])

    return d, connections
def DirectCoupled_QW_Coupled_ShuntResonators(gi, RS, RL, f0, BW, fstart, fstop,
                                             npoints):
    Nres = len(gi) - 2  # Number of resonators

    params = {}
    params['gi'] = gi
    params['N'] = Nres
    params['ZS'] = RS
    params['ZL'] = RL
    params['f1'] = f0 - BW / 2
    params['f2'] = f0 + BW / 2
    RS, RL, qw, Lres, Cres = synthesize_DC_Filter_QW_Shunt_Resonators(params)

    # Draw circuit
    schem.use('svg')
    d = schem.Drawing()
    _fontsize = 12

    # Network
    rf.stylely()
    freq = rf.Frequency(start=fstart, stop=fstop, npoints=npoints, unit='MHz')
    line = rf.media.DefinedGammaZ0(frequency=freq)

    # Component counter
    count_C = 0
    count_L = 0
    count_TL = 0
    count_gnd = 0

    # Source port
    # Drawing: Source port and the first line
    d += elm.Dot().label('ZS = ' + str(RS) + " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    d += elm.Line().length(1).linewidth(1)

    # Network: Port 1
    connections = []  # Network connections
    L = []
    C = []
    TL = []
    ground = []

    Port1 = rf.Circuit.Port(frequency=freq, name='port1', z0=RS)

    # Quarter wavelength line
    beta = freq.w / rf.c
    Z0_line = rf.media.DefinedGammaZ0(frequency=freq,
                                      Z0=RS,
                                      gamma=0 + beta * 1j)

    d += elm.Line().right().length(1).linewidth(1)

    for i in range(0, Nres):
        # Resonator

        # Drawing
        d.push()
        d += elm.Line().down().length(1).linewidth(1)
        d.push()
        d += elm.Line().left().length(1).linewidth(1)
        d += elm.Capacitor().down().label(getUnitsWithScale(
            Cres[i], 'Capacitance'),
                                          fontsize=_fontsize).linewidth(1)
        d += elm.Ground().linewidth(1)

        d.pop()
        d += elm.Line().right().length(1).linewidth(1)
        d += elm.Inductor2(loops=2).down().label(getUnitsWithScale(
            Lres[i], 'Inductance'),
                                                 fontsize=_fontsize,
                                                 loc='bottom').linewidth(1)
        d += elm.Ground().linewidth(1)

        # Network
        count_C += 1
        C.append(line.capacitor(Cres[i], name='C' + str(count_C)))
        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        count_L += 1
        L.append(line.inductor(Lres[i], name='L' + str(count_L)))
        count_gnd += 1
        ground.append(
            rf.Circuit.Ground(frequency=freq,
                              name='ground' + str(count_gnd),
                              z0=RS))

        # Coupling line
        # Drawing
        d.pop()
        d += elm.Line().right().length(2).linewidth(1)
        d += TransmissionLine().right().label(
            "l = " + getUnitsWithScale(qw, 'Distance'),
            fontsize=_fontsize,
            loc='bottom').label("Z\u2080 = " + str(RS) + " \u03A9 ",
                                loc='top').linewidth(1)
        d += elm.Line().right().length(2).linewidth(1)

        count_TL += 1
        TL.append(
            Z0_line.line(Z0_line.theta_2_d(90, deg=True),
                         unit='m',
                         name='TL' + str(count_TL)))

        if (i == 0):
            # Connect to the source port
            connections.append([(Port1, 0), (L[0], 0), (C[0], 0), (TL[0], 0)])
        else:
            # Connect to the previous TL
            connections.append([(TL[i - 1], 1), (L[i], 0), (C[i], 0),
                                (TL[i], 0)])

        connections.append([(C[i], 1), (ground[2 * i], 0)])
        connections.append([(L[i], 1), (ground[2 * i + 1], 0)])

    # Load port
    # Drawing
    d += elm.Dot().label('ZL = ' + str(float("{:.2f}".format(RL))) + " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    # Network
    Port2 = rf.Circuit.Port(frequency=freq, name='port2', z0=RL)

    # Connections
    connections.append([(Port2, 0), (TL[-1], 1)])

    return d, connections
Esempio n. 8
0
def draw(l,port="z11",rs=0,rl=oo):
    #example
    #l=[{type:"r",label:2,dirrection:"right",parallel:False]},{type:"l",label:100,dirrection:"down",parallel:True},{type:"c",label:56,dirrection:"right",parallel:True}] 
    with plt.xkcd():
        d ,F= schemdraw.Drawing(inches_per_unit=.5),0
        if port=='z11':
            a0=d.add(elm.Resistor(d='right', label=str(rs)+'$\Omega$',color="red")) 
        if port=='y22':
            a0=d.add(elm.Resistor(d='up', label=str(rl)+'$\Omega$',color="red"))
            d.add(elm.Line(d="right"))     
        for q in l:
            try:
                if q["label"]==int(q["label"]):
                    q["label"]=int(q["label"])
            except:
                pass        
            if q["dirrection"]=="down" and  q["parallel"]: 
                F=F+1  
                if F<2:
                    d.add(elm.Line(d='right'))
                    d.push()  
            elif q["dirrection"]=="down":
                d.push()
            elif q["parallel"] :
                F=F+1  
                if F<2:
                    d.push()          
            if q["type"]=="r":
                d.add(elm.Resistor(d=q["dirrection"], label=str(q["label"])+'$\Omega$'))
            elif q["type"]=="l":
                d.add(elm.Inductor(d=q["dirrection"], label=str(q["label"])+"H"))
            elif q["type"]=="c":
                d.add(elm.Capacitor(d=q["dirrection"], label=str(q["label"])+'$\mu$F')) 
            elif q["type"]=="w":    
                d.add(elm.Line(d=q["dirrection"]))
            if q["dirrection"]=="down" and  q["parallel"]:              
                if F<2:
                    pass
                else:
                    d.pop()
                    F=0    
            elif q["dirrection"]=="right" and  q["parallel"]:   
                if F<2:
                    d.pop()
                    d.add(elm.Line(d='down'))  
                else:
                    d.add(elm.Line(d='up'))
                    F=0                      
            elif q["dirrection"]=="down": 
                d.add(elm.Line(d='down')) 
                d.pop()
        d.add(elm.Line(d='right'))
        if port=='z11':
            d.add(elm.Resistor(d='down', label=str(rl)+'$\Omega$',color="red")) 
            d.add(elm.Line(d='down'))
            d.add(elm.Line('left', tox=a0.start)) 
            d.add(elm.SourceSin(d='up', label='10V')) 
            d.add(elm.Line(d='up'))
        if port=='y22':
            d.add(elm.Resistor(d='right', label=str(rs)+'$\Omega$',color="red")) 
            d.add(elm.SourceSin(d='down', label='10V')) 
            d.add(elm.Line(d='down'))
            d.add(elm.Line('left', tox=a0.start)) 
            d.add(elm.Line(d='up'))  
        d.draw()
Esempio n. 9
0
''' Test for using schemdraw in a script with interactive pyplot window  '''
import schemdraw
import schemdraw.elements as elm

d = schemdraw.Drawing()
d.add(elm.Resistor(label='1K'))
d.add(elm.Capacitor('d'))

d2 = schemdraw.Drawing()
d2.add(elm.Diode(fill=True))

d2.draw()
d.draw()

Esempio n. 10
0
def getCanonicalFilterSchematic(params):
    # Unpack the dictionary
    gi = params['gi']
    N = params['N']
    ZS = params['ZS']
    fc = params['fc']
    f1 = params['f1']
    f2 = params['f2']
    FirstElement = params['FirstElement']
    Mask = params['Mask']

    if (Mask == 'Bandpass' or Mask == 'Bandstop'):
        w1 = 2 * np.pi * f1 * 1e6  # rad/s
        w2 = 2 * np.pi * f2 * 1e6  # rad/s
        w0 = np.sqrt(w1 * w2)
        Delta = w2 - w1
    else:
        w0 = 2 * np.pi * fc * 1e6  # rad/s

    print(gi)
    ##################################################
    # Draw circuit
    schem.use('svg')
    d = schem.Drawing(inches_per_unit=0.3)
    _fontsize = 8

    # Draw the source port and the first line (if needed)
    d += elm.Line(color='white').length(2).linewidth(0)
    d += elm.Dot().label('ZS = ' + str(ZS) + " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    d += elm.Line().length(2).linewidth(1)

    # Draw the filter components
    for i in range(N):
        if (((i % 2 == 0) and (FirstElement == 1))
                or ((i % 2 != 0) and (FirstElement != 1))):
            d += elm.Dot()
            d.push()  # Save the drawing point for later

            # Mask-type transformation
            if (Mask == 'Lowpass'):
                d += elm.Capacitor().down().label(
                    getUnitsWithScale(gi[i + 1] / (ZS * w0), 'Capacitance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Ground().linewidth(1)
            elif (Mask == 'Highpass'):
                d += elm.Inductor2(loops=2).down().label(
                    getUnitsWithScale(ZS / (gi[i + 1] * w0), 'Inductance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Ground().linewidth(1)
            elif (Mask == 'Bandpass'):
                d.push()
                d += elm.Line().down().length(2).linewidth(1)
                d += elm.Dot()
                d.push()
                d += elm.Line().left().length(1).linewidth(1)
                d += elm.Capacitor().down().label(
                    getUnitsWithScale(gi[i + 1] / (ZS * Delta), 'Capacitance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Ground().linewidth(1)
                d.pop()
                d += elm.Line().right().length(1).linewidth(1)
                d += elm.Inductor2(loops=2).down().label(
                    getUnitsWithScale(ZS * Delta / (gi[i + 1] * w0 * w0),
                                      'Inductance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Ground().linewidth(1)
                d.pop()
            elif (Mask == 'Bandstop'):
                d += elm.Dot()
                d.push()
                d += elm.Inductor2(loops=2).down().label(
                    getUnitsWithScale(ZS / (gi[i + 1] * Delta), 'Inductance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Capacitor().down().label(
                    getUnitsWithScale(gi[i + 1] * Delta / (ZS * w0 * w0),
                                      'Capacitance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Ground().linewidth(1)
                d.pop()

            d.pop()  # Restore the drawing point
        else:
            # Mask-type transformation
            if (Mask == 'Lowpass'):
                d += elm.Inductor2(loops=2).label(
                    getUnitsWithScale(ZS * gi[i + 1] / w0, 'Inductance'),
                    fontsize=_fontsize).linewidth(1)
            elif (Mask == 'Highpass'):
                d += elm.Capacitor().label(getUnitsWithScale(
                    1 / (gi[i + 1] * w0 * ZS), 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)
            elif (Mask == 'Bandpass'):
                d += elm.Inductor2(loops=2).label(
                    getUnitsWithScale(ZS * gi[i + 1] / (Delta), 'Inductance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Capacitor().label(getUnitsWithScale(
                    Delta / (ZS * w0 * w0 * gi[i + 1]), 'Capacitance'),
                                           fontsize=_fontsize).linewidth(1)
            elif (Mask == 'Bandstop'):
                d.push()
                d += elm.Inductor2(loops=2).right().label(
                    getUnitsWithScale(gi[i + 1] * ZS * Delta / (w0 * w0),
                                      'Inductance'),
                    fontsize=_fontsize).linewidth(1)
                d.pop()
                d += elm.Line().up().length(2).linewidth(1)
                d += elm.Capacitor().right().label(
                    getUnitsWithScale(1 / (ZS * Delta * gi[i + 1]),
                                      'Capacitance'),
                    fontsize=_fontsize).linewidth(1)
                d += elm.Line().down().length(2).linewidth(1)

    # Draw the last line (if needed) and the load port
    d += elm.Line().right().length(2).linewidth(1)

    d += elm.Dot().label('ZL = ' + str(float("{:.2f}".format(ZS * gi[-1]))) +
                         " \u03A9",
                         fontsize=_fontsize).linewidth(1)
    d += elm.Line(color='white').length(2).linewidth(0)

    return d