def nparalel(el, n, d, lbl): nr = n//2 nl = n - nr # right part dr = schemdraw.Drawing() dr.push() for i in range(nr): dr.add(elm.Line(d="right")) dr.push() dr.add(el(d="right", rgtlabel=lbl[i+nl])) #dr.add(elm.Dot(color="black")) dr.add(elm.Line(d="left")) dr.pop() dr.pop() for i in range(nl): if n > 1: dr.add(elm.Line(d="left")) dr.push() dr.add(el(d="right", rgtlabel=lbl[nl-1-i])) #dr.add(elm.Dot(color="black")) if n > 1: dr.add(elm.Line(d="right")) if i == 0: xy=dr.here dr.pop() d.add(elm.ElementDrawing(dr)) return d, xy
def nand(d, inp=[]): pfet = elm.PFet nfet = elm.NFet n = len(inp) d, xy = nparalel(pfet, n, d, inp) d = nserie(nfet, n, d, xy, inp) d.push() d.add(elm.Line(at=xy, l=((n//2)+1)*3, rgtlabel="out")) return d
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())
self.segments.append((Segment([[0.068,0.068],[-0.068,-0.068]]))) d = schemdraw.Drawing() ########### LEFT PART ###################### M5a = d.add(pmos( lftlabel = 'M5a', color = 'black')) l54a = d.add(smallseg('right', at = M5a.drain)) smallseg1 = d.add(smallseg('left',at = [0,0.13])) M4a = d.add(pmos('right', at = l54a.end, lftlabel = 'M4a', color = 'black')) vcascp1 = d.add(srccircle(at = M4a.gate, rgtlabel='$V_{cascp}$', color = 'black')) l43a = d.add(elm.Line('down', at = M4a.drain)) d.add(fullcircle(at = l43a.center)) vout1 = d.add(smallseg('down', at = l43a.center)) voutp = d.add(blankcircle(at = [-0.543,-3],rgtlabel='Vout+')) # M3a = d.add(nmos('right', at = l43a.end, lftlabel = 'M3a', color = 'black')) vcascn1 = d.add(srccircle(at = M3a.gate,flip=True, botlabel='$V_{cascn}$', color = 'black')) l32a = d.add(smallseg('right', at = M3a.drain)) # d.add(elm.Dot(at = l32a.center)) d.add(fullcircle(at=l32a.center)) # d.add(elm.Line('right', at = l32a.center)) linetomid1 = d.add(midseg('up', at = l32a.center))
# 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
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()
mosfet_number = int(file.read()[-1]) - 1 colors = ['blue' for i in range(0, 6)] colors[mosfet_number] = 'red' # In[28]: d = schemdraw.Drawing() left_mosfet = d.here mosfets_label_color = 'blue' # Drawing The Supply d.add(elm.Line) d.add(elm.Line).add_label('VDD', color='blue', fontsize=10) d.add(elm.Line()) # Drawing the right mosfet right_mosfet = d.here d.add(elm.Line('right', l=d.unit / 8, at=left_mosfet)) x = d.here mosfetm5a = PMOS(anchor='source', at=x) d.add(mosfetm5a).add_label("M5a", color=colors[4], loc='lft', fontsize=10) d.push() mosfet4a = PMOS(anchor='source', at=(mosfetm5a, 'drain')) d.add(mosfet4a).add_label("M4a", color=colors[3], loc='lft', fontsize=10) d.add(Bias(bias=True, at=(mosfet4a, 'gate'))).add_label("Vcascp", color=mosfets_label_color, loc='rgt', fontsize=10)
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