Пример #1
0
def _getphasors(freq, cv):
    """Return transfer functions for a given frequency."""
    s = 2 * np.pi * freq * 1j
    Zc = par(cv['Rc'], 1./(cv['Cc'] * s))
    Ze = par(cv['Re'], 1./(cv['Ce'] * s))
    Z = cv['R'] + 1./(cv['C'] * s)
    Zb = cv['hie'] + Ze*(1 + cv['hfe'])
    Rb = cv['Rb']
    hfe = cv['hfe']
    ib_vin = 1./(Z + par(Zb, Rb)) * Rb /(Zb + Rb) 
    vu_vin = - Zc * hfe * ib_vin # A(f) actually
    ic_vin = hfe * ib_vin
    vce_vin = -(Ze*(hfe + 1) + Zc*hfe) * ib_vin
    return vce_vin, ic_vin, ib_vin, vu_vin
Пример #2
0
def _solve_circuit(self):
    """Solve circuit, adding keys to cv dictionary."""
    
    cv = self.cv
    bv = eledp.bjt.get_transistor(cv['Q'])
    
    cv['Vbb'] = Vbb = (cv['R2'] * 1./(cv['R1']+ cv['R2'])) * cv['Vcc']
    cv['Rb'] = Rb = par(cv['R1'], cv['R2'])
    cv['IcQ'] = IcQ = (Vbb - bv['Vg']) * 1./cv['Re']
    cv['VceQ'] = VceQ = cv['Vcc'] - (cv['Rc'] + cv['Re'])*IcQ
    cv['IbQ'], cv['hfe'], cv['hie'] = IbQ, hfe, hie = \
                                      eledp.bjt.get_cp(VceQ, IcQ, cv['Q'])
    
    if IbQ < 0: # IbQ > 0
        print 'a'
        self._valid = False
        return
    if VceQ < bv['Vces']: # VceQ > Vces
        print 'b'
        self._valid = False
        return
    if 50 * Rb*IbQ > Vbb: # Rb * IbQ << Vbb
        print 'c'
        self._valid = False
        return
    if 50 * IbQ > IcQ: # IcQ >> IbQ
        print 'd'
        self._valid = False
        return
    
    cv['Rc_o'] = cv['R'] + par(Rb, hie + cv['Re']*(1 + hfe))
    cv['Rce_o'] = par(cv['Re'], (Rb + hie)*1./(1 + hfe))
    cv['Rce_c'] = par(cv['Re'], (par(Rb, cv['R']) + hie) * 1./(1 + hfe))
    cv['Rc_ce'] = cv['R'] + par(Rb, hie)
    cv['Rcc_o'] = cv['Rc']

    a1 = cv['C']*cv['Rc_o'] + cv['Ce']*cv['Rce_o']
    a2 = cv['C'] * cv['Ce'] * cv['Rce_o'] * cv['Rc_ce']
    b1 = cv['Cc'] * cv['Rcc_o']

    cv['fp1'] = - 1./(2*np.pi) * (-a1 - (a1**2 - 4*a2)**0.5) / (2*a2)
    cv['fp2'] = - 1./(2*np.pi) * (-a1 + (a1**2 - 4*a2)**0.5) / (2*a2)
    cv['fp3'] = 1./(2 * np.pi * cv['Cc'] * cv['Rcc_o'])
    cv['fz'] = 1./(2 * np.pi * cv['Re'] * cv['Ce'])

    # fp3 >> fp1,fp2,fz  ovvero separazione in banda
    if 100 * cv['fp1'] > cv['fp3']:
        print 'e'
        self._valid = False
        return
    if 100 * cv['fp2'] > cv['fp3']:
        print 'f'
        self._valid = False
        return
    if 100 * cv['fz'] > cv['fp3']:
        print 'g'
        self._valid = False
        return
    
    cv['Acb'] = - cv['Rc'] * hfe * (1./(1 + hie*1./Rb)) * \
                1./(par(hie, Rb) + cv['R'])
    cv['fcap'] = - cv['fp1'] * cv['fp2'] * 1./cv['fz'] / cv['Acb']
    
    cv['fmin'] = min(cv['fp1'], cv['fp2'], cv['fp3'], cv['fz']) * 10**-2
    cv['fmax'] = max(cv['fp1'], cv['fp2'], cv['fp3'], cv['fz']) * 10**2
    cv['tfnum']= [-1./(4 * np.pi**2 * cv['fcap'] * cv['fz']), 
                  -1./(2 * np.pi * cv['fcap']), 0]
    cv['tfden']=[b1* a2, a2 + a1*b1, a1 + b1, 1]
    cv['VuQ'] = cv['Vcc'] - cv['Rc']*cv['IcQ']


    def pf(i):
        """On purpose function. See ahead"""
        pd = {'R': r'$\Omega$', 'C': 'F', 'V': 'V', 'I': 'A'}
        c = pd[i[0]] if i[0] in pd.keys() else ''
        return c
    cl = []
    cl.append('Q: ' + cv['Q'] + '\n')
    for i in sorted(CVSTD.keys(), reverse=True):
        if i != 'Q':
            cl.append(i+ ' = ' + nf(cv[i]) + pf(i) + '\n')
    cv['par_txt'] = ''.join(cl)
    
    cv['freqs_txt'] = \
        r'$f_z\,=\,' + ('%.4g' % cv['fz']) + 'Hz$\n' + \
        r'$f_{p1}\,=\,' + ('%.4g' % cv['fp1']) + 'Hz$\n' + \
        r'$f_{p2}\,=\,' + ('%.4g' % cv['fp2']) + 'Hz$\n' + \
        r'$f_{p3}\,=\,' + ('%.4g' % cv['fp3']) + 'Hz$\n' + \
        r'$\hat{f}\,=\,' + ('%.4g' % cv['fcap']) + 'Hz$'