def Save_Schematic(circuit, voltages, currents, file_name): d = schemdraw.Drawing() elements = {} elements["0"] = d.add(elm.Ground) drawn = [] directions = ["up", "right", "down", "left"] direc = 0 for key, node in circuit.nodes.items(): if key != "0": for i, branch in enumerate(node.branches): if branch not in drawn: pos, neg = branch.pos_node, branch.neg_node el = None i = int(key) - 1 if branch.element_type == "R": el = elm.Resistor(directions[direc], lblofst = 1, label="Ω={z.real:+0.02f} {z.imag:+0.02f}j\nV={v.real:+0.02f} {v.imag:+0.02f}j" .format(z=branch.impedance, v=voltages[i]), to = elements[neg].start if neg in elements else None) else: el = elm.SourceV(label="V = {}".format(str(branch.voltage))) d.add(el) other_node = neg if key == pos else pos new_node = None if key not in elements: new_node = key elif other_node not in elements: new_node = other_node if new_node is not None: label = "Node {}\nI=".format(new_node) c = currents[int(new_node) - 1] label += "{c.real:+0.02f} {c.imag:+0.02f}j".format(c=c) if isinstance(c, complex) else "V-source" if directions[direc] in ("up", "bottom"): elements[new_node] = d.add(elm.Dot(lblofst = 1, lftlabel=label)) else: elements[new_node] = d.add(elm.Dot(lblofst = 1, botlabel=label)) if neg == "0" and i == len(node.branches) - 1: d.add(elm.Ground) drawn.append(branch) direc = (direc + 1) % 4 #d.draw() d.save('schematics/{}.png'.format(file_name.split("\\")[-1]))
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())
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
fontsize=10, loc='rgt', ofst=[0.6]) d.add(elm.Line('down', at=d.here, l=d.unit / 12)) mosfet2b = NMOS(anchor='drain', at=d.here, d='right') d.add(mosfet2b).add_label("M2b", color=colors[1], loc='rgt', fontsize=10) d.add(elm.Line(at=(mosfet2b, 'source'), l=d.unit / 8)) d.add(elm.Ground()) # biasing M2a and M2b d.add(elm.Line('right', at=(mosfet2a, 'gate'))) left_line = d.here d.add(elm.Line('left', at=(mosfet2b, 'gate'))) d.add(elm.Line('left', at=d.here)) d.add(elm.Dot(at=d.here)) d.add(elm.Line('down', at=d.here, l=d.unit / 6)) d.add(Bias(bias=True)).add_label("Vbiasn", color='blue', fontsize=10) # biasing M5a and M5b d.add(elm.Line('right', at=(mosfetm5a, 'gate'))) start_m6 = d.here # useful when drawing m6 d.add(elm.Line('left', at=(mosfetm5b, 'gate'))) d.add(elm.Dot(at=d.here)) left_line = d.here d.add(elm.Line('left', at=d.here)) d.add(elm.Line('down', at=left_line, l=d.unit / 6)) d.add(Bias(bias=True)).add_label("Vbiasp", color='blue', fontsize=10) # Drawing M6 branch
def redraw(self, elementName=None): # This function takes the element name to be colored in red # Input: # - elementName: the name of the element that need to be High lighted self.d = schemdraw.Drawing() VoltageSource = self.d.add(elm.Vdd(label='V$_{DD}$')) # the right side branch self.d.add(elm.Line(l=7)) # the right side Vdd self.d.add(elm.Arrow(d='down',l=1, botlabel='I$_{bias}$')) if(elementName == 'M5'): M5b = self.d.add(MosfetP(d='right', anchor='source', color='red', rgtlabel='M5b')) # M5b else: M5b = self.d.add(MosfetP(d='right', anchor='source', rgtlabel='M5b')) # M5b self.d.add(elm.Line(d='down', at=M5b.drain, l=1)) if(elementName == 'M4'): M4b = self.d.add(MosfetP(d='right', anchor='source', color='red', rgtlabel='M4b')) # M4b else: M4b = self.d.add(MosfetP(d='right', anchor='source', rgtlabel='M4b')) # M4b self.d.add(elm.Dot(open=True, at=M4b.gate, lftlabel='V$_{cascp}$')) M4bDotM3b = self.d.add(elm.LineDot(d='down', at=M4b.drain, l=1)) self.d.add(elm.Line(d='down', l=1)) if(elementName == 'M3'): M3b = self.d.add(MosfetN(d='right', anchor='drain', color='red', rgtlabel='M3b')) else: M3b = self.d.add(MosfetN(d='right', anchor='drain', rgtlabel='M3b')) self.d.add(elm.Dot(open=True, at=M3b.gate, lftlabel='V$_{cascn}$')) M3bDotM2b = self.d.add(elm.LineDot(d='down', at=M3b.source, l=1)) self.d.add(elm.Line(d='down', l=1)) if(elementName == 'M2'): M2b = self.d.add(MosfetN(d='right', anchor='drain', color='red', rgtlabel='M2b')) else: M2b = self.d.add(MosfetN(d='right', anchor='drain', rgtlabel='M2b')) self.d.add(elm.Line(d='down', at=M2b.source, l=1)) self.d.add(elm.Ground()) # the left side branch self.d.add(elm.Line(d='left',l=7,at=VoltageSource.end)) # the left side Vdd self.d.add(elm.Arrow(d='down',l=1, toplabel='I$_{bias}$')) if(elementName == 'M5'): M5a = self.d.add(MosfetP(d='right', reverse=True, anchor='source', color='red', lftlabel='M5a')) # M5a else: M5a = self.d.add(MosfetP(d='right',reverse=True, anchor='source', lftlabel='M5a')) # M5a self.d.add(elm.Line(d='down', at=M5a.drain, l=1)) if(elementName == 'M4'): M4a = self.d.add(MosfetP(d='right', reverse=True, anchor='source', color='red', lftlabel='M4a')) # M4a else: M4a = self.d.add(MosfetP(d='right',reverse=True, anchor='source', lftlabel='M4a')) # M4a self.d.add(elm.Dot(open=True, at=M4a.gate, rgtlabel='V$_{cascp}$')) M4aDotM3a = self.d.add(elm.LineDot(d='down', at=M4a.drain, l=1)) self.d.add(elm.Line(d='down', l=1)) if(elementName == 'M3'): M3a = self.d.add(MosfetN(d='right', reverse=True, anchor='drain', color='red', lftlabel='M3a')) # M3a else: M3a = self.d.add(MosfetN(d='right',reverse=True, anchor='drain', lftlabel='M3a')) # M3a self.d.add(elm.Dot(open=True, at=M3a.gate, rgtlabel='V$_{cascn}$')) M3aDotM2a = self.d.add(elm.LineDot(d='down', at=M3a.source, l=1)) self.d.add(elm.Line(d='down', l=1)) if(elementName == 'M2'): M2a = self.d.add(MosfetN(d='right', reverse=True, anchor='drain', color='red', lftlabel='M2a')) # M2a else: M2a = self.d.add(MosfetN(d='right',reverse=True, anchor='drain', lftlabel='M2a')) # M2a self.d.add(elm.Line(d='down', at=M2a.source, l=1)) self.d.add(elm.Ground()) # the middle branch self.d.add(elm.Arrow(d='down', at=VoltageSource.end, botlabel='2I$_{bias}$')) if(elementName == 'M6'): M6 = self.d.add(MosfetP(d='right', anchor='source', color='red', rgtlabel='M6')) # M6 else: M6 = self.d.add(MosfetP(d='right', anchor='source', rgtlabel='M6')) # M6 Vcmfb = self.d.add(elm.Dot(open=True, at=M6.gate, lftlabel='V$_{cmfb}$')) M6DotDrain = self.d.add(elm.LineDot(d='down', at=M6.drain, l=1)) # right of the middle branch self.d.add(elm.Line(d='right', l=2)) self.d.add(elm.Arrow(d='down', l=1, botlabel='I$_{bias}$')) if(elementName == 'M1'): M1b = self.d.add(MosfetP(d='right', reverse=True, anchor='source', color='red', lftlabel='M1b')) # M1b else: M1b = self.d.add(MosfetP(d='right', reverse=True, anchor='source', lftlabel='M1b')) # M1b self.d.add(elm.Line(d='down', xy=M1b.drain, toy=M3bDotM2b.end)) self.d.add(elm.Line(to=M3bDotM2b.end)) self.d.add(elm.Dot(xy=M1b.gate, open=True, rgtlabel='V$_{in-}$')) # left of the middle branch self.d.add(elm.Line(d='left', xy=M6DotDrain.end, l=2)) self.d.add(elm.Arrow(d='down', l=1, toplabel='I$_{bias}$')) if(elementName == 'M1'): M1a = self.d.add(MosfetP(d='right', anchor='source', color='red', rgtlabel='M1a')) # M1a else: M1a = self.d.add(MosfetP(d='right', anchor='source', rgtlabel='M1a')) # M1a self.d.add(elm.Line(d='down', xy=M1a.drain, toy=M3aDotM2a.end)) self.d.add(elm.Line(to=M3aDotM2a.end)) self.d.add(elm.Dot(xy=M1a.gate, open=True, lftlabel='V$_{in+}$')) # connections self.d.add(elm.Line(xy=M2b.gate, tox=M6DotDrain.end)) Vbiasn = self.d.add(elm.Dot) self.d.add(elm.Line(to=M2a.gate)) self.d.add(elm.LineDot(d='up', l=1, xy=Vbiasn.start, label='V$_{biasn}$')) self.d.add(elm.Line(xy=M5a.gate, d='right', l=2)) Vbiasp = self.d.add(elm.Dot) self.d.add(elm.Line(to=M5b.gate)) self.d.add(elm.LineDot(d='up', l=1, xy=Vbiasp.start, label='V$_{biasp}$')) # output voltage self.d.add(elm.LineDot(d='right', at=M4bDotM3b.end, rgtlabel='V$_{out+}$')) self.d.add(elm.LineDot(d='left', at=M4aDotM3a.end, lftlabel='V$_{out-}$')) # draw as a figure to handle it to the GUI canvas self.figure = self.d.draw(show=False)
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
# pip install schemdraw # (^ requires python 3.8) # conda install -c conda-forge pyspice # draw the schematic import schemdraw import schemdraw.elements as elm d = schemdraw.Drawing() d.add(elm.Dot().label('evaporator').color('red')) Reex = d.add(elm.Resistor().down().label('Re,ex')) d.add(elm.Dot().label('1', loc='left').color('red')) Rew = d.add(elm.Resistor().down().label('Re,w')) d.add(elm.Dot().label('2', loc='left').color('red')) d.add(elm.Resistor().down().label('Re,wk').color('orange')) d.add(elm.Dot().label('3', loc='left').color('red')) d.add(elm.Resistor().down().label('Re,inter').color('blue')) d.add(elm.Dot().label('4', loc='left').color('red')) d.add(elm.Resistor().right().label('Rv').color('blue')) d.add(elm.Dot().label('5', loc='bottom').color('red')) d.add(elm.Resistor().up().label('Rc,inter', loc='bottom').color('blue')) d.add(elm.Dot().label('6', loc='right').color('red')) d.add(elm.Resistor().up().label('Rc,wk', loc='bottom').color('orange')) d.add(elm.Dot().label('7', loc='right').color('red')) Rcw = d.add(elm.Resistor().up().label('Rc,w', loc='bottom')) d.add(elm.Dot().label('8', loc='right').color('red')) Rcex = d.add(elm.Resistor().up().label('Rc,ex', loc='bottom')) d.add(elm.Dot().label('condensor').color('red'))