from __future__ import division
# Determine the collector current Ic1 and collector-emitter voltage Vce1 for the difference amplifier circuit
V1 = 0 # # volt
V2 = -5 # #volt
Vcm = 5 # #volt
Vcc = 10# #volt
Vee = -10 # #volt
Ie = 1 # #mA
Rc = 10 # #kilo ohm
# Transistor parameters
# base current are negligible
Vbe = 0.7 # # volt
# The collector current of difference amplifier is
Ic1 = Ie/2 #
print 'The collector current of difference amplifier Ic1 = Ic2 = %0.2f'%Ic1,' mA '
# The collector voltages of transistors Q1 and Q2 are expressed as
Vc1 = Vcc-Ic1*Rc #
print 'The collector voltages of transistors Q1 and Q2 are Vc1 = Vc2 = %0.2f'%Vc1,' volt '
# We know common mode voltage (Vcm) , from this the emitter voltage can be identified as follows
# For the common mode voltage Vcm = 0 V , the emitter voltage is Ve = -0.7 V
# For the common mode voltage Vcm = 5 V , the emitter voltage is Ve = 4.3 V
# For the common mode voltage Vcm = -5 V , the emitter voltage is Ve = -5.7 V
# For the different emitter voltages the collector-emitter voltage can be calculated as
Ve = -0.7 # # volt
Vce1 = Vc1-Ve#
print 'For Ve = -0.7 Volt the collector - emitter voltage Vce1 = %0.2f'%Vce1,' Volt'
Ve = 4.3 # # volt
Vce1 = Vc1-Ve#
print 'For Ve = 4.3 Volt the collector - emitter voltage Vce1 = %0.2f'%Vce1,' Volt'
Ve = -5.7 # # volt
Vce1 = Vc1-Ve#
print 'For Ve = -5.7 Volt the collector - emitter voltage Vce1 = %0.2f'%Vce1,' Volt'
# To determine the difference-mode and common-mode gain of the difference amplifier
Vcc = 10 # # volt
Vee = -10 # #volt
Iq = 0.8 # #mA
Ie = 0.8 # #mA
Rc = 12 # #kilo-Ohm
Vt = 0.026 # # volt
# Transistor parameter
beta = 100 #
Rs = 0 # #Ohm
Ro = 25 # #kilo-Ohm
# The differential mode gain Ad
gm = (Ie/ 2*Vt) #
# Ad = (gm*r*Rc/r+Rc) # # where r is r-pi
# For Rb=0 , the differential mode gain is
Ad = (Ie/(2*Vt))*Rc#
#But
print ' The differential mode gain Ad = %0.1f'%Ad
#The common mode gain Acm
# Acm = - (gm*Rc/1+2*gm*Re+2*Re/r)
Acm =-(Ad/(1+(((1+beta)*Ie*Ro)/(beta*Vt))))
print ' The common mode gain Acm = %0.3f'%Acm
# To find the output of a difference amplifier when only common mode signal is applied
# V1 = V2 = Vcm = 200*sin(wt) # # micro volt (uV)
Acm = -0.237 #
# When the common mode input signal is applied to the difference amplifier , the difference mode gain is zero
Vcm = 200 #
Vo = Acm*Vcm #
print 'The output of a difference amplifier is Vo = %0.2f'%Vo,'sinwt uV ' # multiply by sinwt because it is in Vcm
from math import log10
#Determine the common mode rejection ratio(CMRR) of the difference amplifier
Vcc = 10 # # volt
Vee = -10 # #volt
Iq = 0.8 # #mA
Ie = 0.8 # #mA
Rc = 12 # #kilo-Ohm
Vt = 0.026 # # volt
# Transistor parameter
beta = 100 #
Rs = 0 # #Ohm
Ro = 25 # #kilo-Ohm
# The differential mode gain Ad
gm = (Ie/ 2*Vt) #
# Ad = (gm*r*Rc/r+Rc) # # where r is r-pi
# For Rb=0 , the differential mode gain is
Ad = (Ie/(2*Vt))*Rc#
#But
print 'The differential mode gain Ad = %0.1f'%Ad
#The common mode gain Acm
# Acm = - (gm*Rc/1+2*gm*Re+2*Re/r)
Acm =-(Ad/(1+(((1+beta)*Ie*Ro)/(beta*Vt))))
print 'The common mode gain Acm = %0.3f'%Acm
# The CMRR of difference amplifier is given as
Ad = Ad/2 #
CMRR = abs(Ad/Acm)
print 'The CMRR of difference amplifier is = %0.f'%CMRR
# In decibel it can be expressed as
CMRRdb = 20*log10(CMRR)
print 'In decibel CMRR is = %0.2f'%CMRRdb
# To determine emitter resistance of the difference amplifier
Vcc = 10 # # volt
Vee = -10 # #volt
Iq = 0.8 # #mA
Ie = 0.8 # #mA
CMRRdb = 90 # #dB
Vt = 0.026 #
# Transistor parameter
beta = 100 #
# CMRR = abs(Ad/Acm)
# the CMRR of the difference amplifier is defined as
#CMRR = ((1/2)*(1+((1+beta)*Ie*Re)/beta*Vt))
# CMRRdb = 20*log10(CMRR)
CMRR = 10**(CMRRdb/20)
print ' The CMRR of difference amplifier is = %0.2e'%CMRR
# The resistance RE is calculated as
RE = (((2*CMRR)-1)/((1+beta)*Ie))*(beta*Vt)/1e3
print ' The value of resistance RE is = %0.2f'%RE,' Mohm '
from __future__ import division
# determine the differential mode gain when load resistance RL = 100 k ohm
RL = 100*10**3 # # k ohm # load resistance
IE = 0.20*10**-3 # # mA # biasing current
VA = 100 # # V # early voltage
VT = 0.026 # # threshold volt
# the differential gain of differential amplifier with an active load circuit
#Ad = Vo/Vd = gm(ro2 || ro4 || RL )
ro2 = (2*VA)/IE#
ro4 = ro2 #
gm = IE/(2*VT) #
Ad = gm/((1/ro2)+(1/ro4)+(1/RL))
print ' The differential mode gain Ad is = %0.f'%Ad