Label, Resistor, Pin, Source, Wire) from inform import Error, error, os_error from quantiphy import Quantity from math import pi except ImportError: print('Run `pip install --user -r requirements.txt`', 'to install missing packages.') raise SystemExit Quantity.set_prefs(map_sf=Quantity.map_sf_to_greek, prec=2) globals().update(Quantity.extract(__doc__, predefined={'π': pi})) try: with Schematic(filename='mfed.svg', line_width=2, background='none'): vin = Source(name='Vin', value='1 V', kind='sine') Ground(C=vin.n) rs = Resistor(name='Rs', value=Rref, n=vin.p, xoff=25) Wire([vin.p, rs.n]) c1 = Capacitor(name='C1', value=C1, p=rs.p, xoff=25) Ground(C=c1.n) l2 = Inductor(name='L2', value=L2, n=c1.p, xoff=25) Wire([rs.p, l2.n]) c3 = Capacitor(name='C3', value=C3, p=l2.p, xoff=25) Ground(C=c3.n) l4 = Inductor(name='L4', value=L4, n=c3.p, xoff=25) Wire([l2.p, l4.n]) c5 = Capacitor(name='C5', value=C5, p=l4.p, xoff=25) Ground(C=c5.n) rl = Resistor(name='Rl', value=Rref, p=c5.p, xoff=100, orient='v') Ground(C=rl.n)
#!/usr/bin/env python3 from svg_schematic import (Schematic, Amp, Dot, Ground, Label, Pin, Resistor, Source, Wire) from inform import Error, error, os_error try: with Schematic(filename="noninverting.svg", line_width=2): vin = Source(kind='sine') Label(C=vin.p, name='Vin', loc='n') Ground(C=vin.n) amp = Amp(pi=vin.p, xoff=100, kind='oa') Label(C=amp.ni, xoff=-25, name='Vf', loc='n') Wire([vin.p, amp.pi]) out = Pin(C=amp.o, xoff=50, name='out', w=2) Wire([amp.o, out.C]) oj = Dot(C=amp.o, xoff=25) r1 = Resistor(p=amp.ni, off=(-25, 50), name='R1', orient='v') Wire([r1.N, amp.ni], kind='|-') r2 = Resistor(C=amp.C, yoff=75, name='R2') Wire([r1.p, r2.W], kind='|-') Wire([oj.C, r2.E], kind='|-') fj = Dot(C=r2.W, xoff=-25) Ground(C=r1.n) except Error as e: e.report() except OSError as e: error(os_error(e))
from svg_schematic import Schematic, Source, Label from inform import Error, error, os_error try: with Schematic(filename = 'source.svg'): s = Source(kind='empty', name='Ve') Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='vdc', name='Vd', C=s.C, xoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='idc', name='Id', C=s.C, xoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='sine', name='Vs', C=s.C, xoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='sum', name='S', yoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='mult', name='M', C=s.C, xoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2) Label(C=s.n, name='n', loc='w', kind='dot', color='blue', w=2) s = Source(kind='cv', name='Vc', C=s.C, xoff=150) Label(C=s.p, name='p', loc='w', kind='dot', color='blue', w=2)
# Generates schematic as an .svg file. # Requires svg_schematic: # git clone https://github.com/KenKundert/svg_schematic.git # cd svg-schematic # python3 setup.py --user --upgrade install from svg_schematic import (Schematic, shift, shift_x, shift_y, midpoint, Box, Ground, Label, Source, Wire) with Schematic(filename="msnm.svg"): v = Source(kind='noise', value='S(f)', orient='v') Ground(C=v.n, orient='v') m = Source(C=shift_x(v.p, 200), kind='mult') Wire([v.p, m.W]) wm = Wire([m.S, shift_y(m.S, 25)]) Label(C=wm.e, loc='S', name='m(t)') Label(C=midpoint(v.p, m.W), loc='N', name='stationary noise') wo = Wire([m.E, shift_x(m.E, 210)]) Label(C=wo.e, kind='arrow', loc='NW', name='cyclostationary noise') Box(C=shift(v.C, 100, -3), w=5.5, h=3.2, line_width=0.5, background='none', stroke_dasharray="4 2")
l = Label(C=rf_bpf.S, loc='s', name='fc=1380MHz') Label(C=l.S, name='BW=320MHz') Wire([rf_preamp2.o, rf_bpf.i]) # First RF amplifier rf_amp1 = Amp(i=rf_bpf.o, xoff=25, kind='se', name='RF Amp1') Label(C=rf_amp1.S, loc='s', name='A<=20dB') Wire([rf_bpf.o, rf_amp1.i]) # Second RF amplifier rf_amp2 = Amp(i=rf_amp1.o, xoff=25, kind='se', name='RF Amp2') Label(C=rf_amp2.S, loc='s', name='A<=20dB') Wire([rf_amp1.o, rf_amp2.i]) # RF mixer rf_mixer = Source(W=rf_amp2.o, xoff=25, kind='mult') Label(C=rf_mixer.N, loc='n', name='DSB') Wire([rf_amp2.o, rf_mixer.W]) # RF local oscillator rf_lo = Source(p=rf_mixer.S, yoff=50, kind='sine', name='fo=1230MHz', value='P=10dBm') Ground(t=rf_lo.n) Wire([rf_mixer.S, rf_lo.N]) # IF band-pass filter if_bpf = Box(i=rf_mixer.E, xoff=25, name='IF BPF') l = Label(C=if_bpf.S, loc='s', name='fc=190MHz')
try: with Schematic(filename='pipeline-adc.svg', line_width=2): # Stage 1 i = Pin(kind='in', name='in') s1 = Box(NW=i.t, off=(25, -62.5), w=10.5, h=4.5, background='lightgray') Label(C=s1.SE, loc='nw', name='Stage 1') adc = Box(W=i.t, off=(75, 100), name='2 bit', value='Flash') dac = Box(i=adc.o, xoff=50, name='2 bit', value='DAC') sh = Box(C=with_x(i.t, midpoint(adc.C, dac.C)), name='SAH') sum = Source(W=with_x(i.t, dac.E), xoff=25, kind='sum', orient='h|') Label(C=sum.W, loc='nw', name='+') Label(C=sum.S, loc='se', name='−') amp = Amp(i=sum.E, xoff=25, kind='se', name='4×') Wire([i.t, sh.i]) Wire([sh.o, sum.W]) Wire([sum.E, amp.i]) Wire([shift_x(i.t, 50), adc.i], kind='|-') Wire([adc.o, dac.i]) Wire([dac.o, sum.S], kind='-|') # Stages 2, 3, 4 s2 = Box(N=dac.S, off=(25, 75), name='Stage 2') s3 = Box(W=s2.E, xoff=50, name='Stage 3') s4 = Box(W=s3.E, xoff=50, name='4 bit', value='Flash') Wire([s2.o, s3.i])
Wire([ll.n, c.p]) Wire([lr.n, c.n]) # gain stage ml = MOS(d=ll.n, yoff=75, orient='|') mr = MOS(d=lr.n, yoff=75, orient='') Wire([ll.n, ml.d]) Wire([lr.n, mr.d]) Wire([ ml.g, shift_y(ml.g, -25), shift(ml.g, 50, -75), shift_y(lr.n, 50) ]) Wire([ mr.g, shift_y(mr.g, -25), shift(mr.g, -50, -75), shift_y(ll.n, 50) ]) Wire([ml.s, shift_y(ml.s, 12), shift_y(mr.s, 12), mr.s]) Source(p=midpoint(ml.s, mr.s), yoff=12, kind='idc', value=r'$I_{\rm ss}$') except Error as e: e.report() except OSError as e: error(os_error(e))
#!/usr/bin/env python3 from svg_schematic import Schematic, Amp, Box, Label, Pin, Source, Wire, shift_x from inform import Error, error, os_error try: with Schematic( filename = "feedback.svg", font_size=16, font_family='serif' ): summer = Source(kind='sum') amp = Amp(W=summer.E, xoff=25, name='$a$', kind='se') fb = Box(C=amp.C, yoff=100, name='$f$', h=1, orient='|') Label(C=summer.W, name='$+$', loc='nw') Label(C=summer.S, name='$-$', loc='sw') i = Pin(C=summer.W, xoff=-50, name='in', kind='in') o = Pin(C=amp.E, xoff=50, name='out', kind='out') Wire([i.C, summer.W]) Wire([summer.E, amp.i]) Wire([amp.E, o.C]) Wire([shift_x(amp.E, 25), fb.i], kind='|-') Wire([summer.S, fb.W], kind='|-') except Error as e: e.report() except OSError as e: error(os_error(e))