# Chapter 1: Introduction to Differential Amplifier and Op-amp¶

## example 1.1, Page No. 4¶

In :
# output voltage of differential amplifier

import math
#Variable declaration
v1 = 300*10**-6           # voltage at terminal 1
v2 = 240*10**-6           # voltage at terminal 2
Aid = 5000.0              # differential gain of amplifier
cmmr1 = 100               # CMMR for case 1
cmmr2 = 10**5             # CMMR for case 2

#Calculations
# case 1
Vid = v1-v2
Vcm = (v1+v2)/2
Acm = Aid/cmmr1
Vout = Aid*Vid+Acm*Vcm
Vout = Vout*1000           # mV

# case 2
Acm2 = Aid/cmmr2
Vout2 = Aid*Vid+Acm2*Vcm
Vout2 = Vout2*1000         # mV

Vout_ideal = Aid*Vid*1000  # mV
#Result
print("(i) CMMR = %d:\nVout = %.1f mV\n\n(ii) CMMR = %d:\nVout = %.4f mV\n\nIdeal Vout = %.0f mV"%(cmmr1,Vout,cmmr2,Vout2,Vout_ideal))

(i) CMMR = 100:
Vout = 313.5 mV

(ii) CMMR = 100000:
Vout = 300.0135 mV

Ideal Vout = 300 mV


## example 1.2, Page No.9¶

In :
# Operating point values

import math
#Variable declaration
Rc = 4.7*10**3              # collector resistor
Re = 3.3*10**3              # emitter resistor
Vcc = 12                    # + supply voltage
Vee = -12                   # - supply voltage
Vbe = 0.7                   # base-emitter junction voltage

#Calculations
Ie  = (Vcc-Vbe)/(2*Re)
Ic = Ie
Vce = Vcc+Vbe-(Ic*Rc)

#Result
print("Q point is (%.3f mA, %.3f V)"%(Ic*1000,Vce))

Q point is (1.712 mA, 4.653 V)


## example 1.3, Page No. 14¶

In :
# differential amplifier parameters(refer fig. 1.14)

import math
#Variable declaration
hie = 2.8*10**3                # input impedance
Rc = 4.7*10**3                 # collector resistance
Vcc = 15                       # supply voltage
hfe = 100                      # transistor current gain
Re = 6.8*10**3                 # emitter resistance
Vbe = 0.7                      # emitter-base junction voltage drop
Rin = 100                      # input resistance
v1 = 70*10**-3                 # input voltage 1
v2 = 40*10**-3                 # input voltage 2

# Calculations
# Operating point values
Ie = Ic = (Vcc-Vbe)/( (2*Re) + (Rin/hfe))
Vce = Vcc+Vbe-Ic*Rc
# Differential gain
Aid = (hfe*Rc)/(Rin+hie)
Aid = math.floor(Aid*1000)/1000
#Common mode gain
Acm = hfe*Rc/(2*Re*(1+hfe)+Rin+hie)
#CMMR
CMMR = 20*math.log10(Aid/Acm)
CMMR = math.floor(CMMR*1000)/1000
#output voltage
Vid = v1-v2
Vcm = (v1+v2)/2
Vout = Aid*Vid+Acm*Vcm

#Result
print("(i) Operating point values:\nIcq = %.3f mA\nVcq = %.3f V\n\n(ii) Differential gain:\nAid = %.3f"%(Ic*1000,Vce,Aid))
print("\n(iii) Common mode gain:\nAcm = %.4f"%(math.floor(Acm*10000)/10000))
print("\n(iv) CMMR:\nCMMR in dB  = %.3f dB\n\n(v) Output Voltage:\nVout = %.2f V"%(CMMR,Vout))

(i) Operating point values:
Icq = 1.051 mA
Vcq = 10.758 V

(ii) Differential gain:
Aid = 162.068

(iii) Common mode gain:
Acm = 0.3414

(iv) CMMR:
CMMR in dB  = 53.527 dB

(v) Output Voltage:
Vout = 4.88 V


## example 1.4, Page No. 16¶

In :
# operating point , voltage gain and input/output impedance(refer fig 1.15)

import math
#Variable declaration
Rc = 3.3*10**3              # collector resistor
Rin = 150                   # inputr resistance
Re = 8.2*10**3              # emitter resistor
Vcc = 12                    # supply voltage
beta = 100                  # beta value
Vbe = 0.7                   # emitter-base junction voltage drop

#Calculations
# opearating point
Ie = Ic = (Vcc-Vbe)/( (2*Re) + (Rin/beta))
Ie = Ic = math.floor(Ic*10**6)/10**6
Vce = Vcc+Vbe-Ic*Rc
# Voltage gain
re = (26*10**-3)/Ie
Aid = Rc/re
# input and output impedance
Ri = 2*re*beta
Ro = Rc

#Result
print("(i) Operating point values:\nIcq = %.3f mA\nVcq = %.4f V\n\n(ii) Voltage gain:\nAid = %.2f"%(Ic*1000,Vce,Aid))
print("\n(iii)input and output impedances:\nRi = %.3f k-ohm\nRo = %.1f k-ohm"%(Ri/1000,Ro/1000))

(i) Operating point values:
Icq = 0.688 mA
Vcq = 10.4296 V

(ii) Voltage gain:
Aid = 87.32

(iii)input and output impedances:
Ri = 7.558 k-ohm
Ro = 3.3 k-ohm


## example 1.5, Page No. 19¶

In :
# constant current in the circuit(refer fig 1.19(a)

import math
#Variable declaration
Vee = 20.0                     # supply voltage
R1 = 4.7*10**3                 # resistor R1
R2 = 4.7*10**3                 # resistor R2
R3 = 2.2*10**3                 # resistor R3
Vbe = 0.7                      # emitter-base junction voltage drop

#Calcualtions
Vb = (-Vee*R1)/(R1+R2)
Ve = Vb - Vbe
Ie = (Ve-(-Vee))/(R3)
I = Ie = math.floor(Ie*10**5)/10**5

#Result
print("I = %.2f mA"%(I*1000))

I = 4.22 mA


## example 1.6, Page No.23¶

In :
# Widlar current source(refer fig. 1.24)

import math
#Variable declaration
Ic2 = 20*10**-6             # required collector current of 2nd Trasistor
Vbe = 0.7                   # emitter-base junction voltage drop
Vcc = 30                    # supply voltage
R = 33.3*10**3              # Resistor R
Vt = 26*10**-3              # thermal voltage

#Calculations
Ic1 = (Vcc-Vbe)/R
Re = Vt*math.log(Ic1/Ic2)/Ic2

#Result
print("Re = %.2f k-ohm"%(Re/1000))

Re = 4.92 k-ohm


## example 1.7, Page No. 24¶

In :
# Widlar current source: value of Ic2

import math
# Variable declaration
Iref = 1*10**-3             # reference current
Re = 5*10**3                # emitter resistor
Vt = 26*10**-3              # thermal voltage

# Calculations
Ic2_1 = 12*10**-6             # assumed value 1
lhs1 = (Vt*math.log(Iref/Ic2_1))-(Ic2_1*Re)
Ic2_2 = 22*10**-6             # assumed value 2
lhs2 = (Vt*math.log(Iref/Ic2_2))-(Ic2_2*Re)
lhs2 = math.ceil(lhs2*10**5)/10**5
Ic2_3 = 20*10**-6             # assumed value 3
lhs3 = (Vt*math.log(Iref/Ic2_3))-(Ic2_3*Re)

#Result
print("for Ic2 = %.0f micro-A, L.H.S = %.5f"%(Ic2_1*10**6,lhs1))
print("for Ic2 = %.0f micro-A, L.H.S = %.5f"%(Ic2_2*10**6,lhs2))
print("\nhence actual value is less than but closer to %.0f micro-A"%(Ic2_2*10**6))
print("\nfor Ic2 = %f micro-A, L.H.S = %.4f"%(Ic2_3*10**6,lhs3))
print("LHS is almost zero, so the value of Ic2 = %.0f micro-A"%(Ic2_3*10**6))

for Ic2 = 12 micro-A, L.H.S = 0.05499
for Ic2 = 22 micro-A, L.H.S = -0.01076

hence actual value is less than but closer to 22 micro-A

for Ic2 = 20.000000 micro-A, L.H.S = 0.0017
LHS is almost zero, so the value of Ic2 = 20 micro-A


## example 1.8, Page No.34¶

In :
# level shifting network (refer fig. 1.42)

import math
#Variable declaration
Vi = 6.84               # input dc level
R2 =  270               # resistor R2
Vbe = 0.7               # emitter-base junction voltage drop

# Calculations
R1 = ((Vi-Vbe)*R2)-R2
R1 = R1/1000
#Result
print("Required value of R to get 0V output level is %.3f k-ohm"%(math.floor(R1*10**3)/1000))

Required value of R to get 0V output level is 1.387 k-ohm


## example 1.9, Page No. 36¶

In :
# differential and common mode output

import math
#Variable declaration
Aid = 80.0                   # differential gain
CMMR = 95.0                  # common mode rejection ratio
V1 = 2*10**-6                # input voltage 1
V2 = 1.6*10**-6              # input voltage 2

#Calculations
Aid = 10**(Aid/20)
CMMR = 10.0**(CMMR/20)
Vid = Aid*(V1-V2)
Acm = Aid/CMMR
Vcm = Acm*(V1+V2)/2

#Result
print("Vid = %.0f mV\nVcm = %.2f micro-V"%(Vid*10**3,Vcm*10**6))

Vid = 4 mV
Vcm = 0.32 micro-V


## example 1.10, Page No. 37¶

In :
# Common mode output

import math
#Variable declaration
Aid = 125.0                # differential gain
CMMR = 60.0                # common mode rejection ratio
Vp = 4.0                   # peak voltage
#Calculations
x = 10**(CMMR/20)          # Aid/Acm
Acm = Aid/x

#Result
print("Commode mode output is given by Acm*Vcm = %.1f*sin(200*pi*t)"%(Vp*Acm))

Commode mode output is given by Acm*Vcm = 0.5*sin(200*pi*t)


## example 1.11, Page No.37¶

In :
# Collector voltage and and differential voltage gain(refer fig 1.48)

import math
#Variable declaration
Vbe = 0.7                 # emitter-base junction voltage drop
hfe = 100.0               # current gain
hie = 3.9*10**3           # inpput impedance
Rin = 1*10**3             # Source resistance
Re = 27*10**3             # Emitter resistance
Rc = 6.8*10**3            # collector resistance
Vcc = 15                  # supply voltage

#Calculations
Ie = Ic = (Vcc-Vbe)/((Rin/hfe)+2*Re)
Vout1 = Vout2 = Vcc-Ic*Rc
Aid = abs(hfe*Rc/(Rin+hie))

#Result
print("Vc1 = Vc2 = %.2f V\nAid = %f "%(Vout1,Aid))
#Answer for Aid is wrong in the book

Vc1 = Vc2 = 13.20 V
Aid = 138.775510


## example 1.12, Page No. 38¶

In :
# Value of Resistance Re

import math
#Variable declaration
Vcc = 10.0                # Supply voltage
Vbe = 0.7                 # emitter-base junction voltage drop
Rc = 47*10**3             # Collector resistance
hfe = 100.0               # current gain
Vceq = 8.6                # quiescent collector emitter voltage

#Calculations
Ic = (Vcc+Vbe-Vceq)/Rc
Re =(Vcc-Vbe)/(2*((1+hfe)/hfe))
Re = math.floor(Re*10000)/10000
Re = Re/(Ic*1000)         # k-ohm

#Result
print("Re = %.2f k-ohm"%(math.floor(Re*100)/100))

Re = 103.03 k-ohm


## example 1.13, Page No. 38¶

In :
# Differential amplifier parameter

import math
#Variable declaration
Vbe = 0.712               # emitter-base junction voltage drop
hfe = 500.0               # current gain
hie = 18 *10**3           # inpput impedance
Rin = 50                  # Source resistance
Re = 6.8*10**3            # Emitter resistance
Rc = 4.7*10**3            # collector resistance
Vcc = 10                  # supply voltage

#Calcualtions
#(i)
Ie = (Vcc -Vbe)/(2*Re)
Ic = (hfe/(1+hfe))*Ie
Vce = Vcc+Vbe-Ic*Rc
Vce = math.floor(Vce*1000)/1000
Ic = math.floor(Ic*10**7)/10**7
Ic = Ic *1000              # mA
#(ii)
#(iii)
Ri = 2*(Rin+hie)
Ro = Rc

#Result
print("(i)\nIcq =%.4f mA\t\tVce = %.3f V\n\n(ii)\nAd = %.2f\n\n(iii)\nRi = %.1f k-ohm\t\tRo = %.1f k-ohm"%(Ic,Vce,Ad,Ri/1000.0,Ro/1000))
# answer for Ri is wrong in the book

(i)
Icq =0.6815 mA		Vce = 7.508 V

(ii)

(iii)
Ri = 36.1 k-ohm		Ro = 4.7 k-ohm


## example 1.14, Page No. 39¶

In :
# Current through the transistors(refer fig 1.50)

import math
#Variable declaration
Q2 = 0.5               # Area of Q2 /Area of Q1
Q3 = 0.25              # Area of Q3 /Area of Q1
Q4 = 0.125             # Area of Q4 /Area of Q1
Vcc = 15               # Supply voltage
Vbe = 0.7              # emitter-base junction voltage drop
R = 20*10**3           # Resistor R

#Calculations
I1 = (Vcc-Vbe)/R
I2 = I1*Q2
I3 = I1*Q3
I4 = I1*Q4

#Result
print("I2 = %.3f  mA\nI3 = %.4f mA\nI4 = %.3f  mA"%(math.floor(I2*10**6)/1000,math.floor(I3*10**7)/10000,I4*1000))

I2 = 0.357  mA
I3 = 0.1787 mA
I4 = 0.089  mA


## example 1.15, Page No. 39¶

In :
# Current calculation in the circuit

import math
#Variable declaration
Vz = 6.2                 # zener voltage
R1 = 4.7*10**3           # resistor R1
R3 = 2.2*10**3           # resistor R3
Vee = -20                # supply voltage
Vbe = 0.7              # emitter-base junction voltage drop

#Calcualtions
Vb = Vee + Vz
Ve = Vee+Vz-Vbe
I = Ie = (Ve-Vee)/R3

#Result
print("I = %.1f mA"%(I*1000))

I = 2.5 mA


## example 1.16, Page No.39¶

In :
# Differential amplifier

import math
#Variable declaration
Ie = 10**-3               # Emitter current
Vbe = 0.7                 # emitter-base junction voltage drop
Rc = 4.7*10**3            # colloector Resistance
Vcc = 12                  # Supply voltage

#Calculations
Re = (Vcc-Vbe)/(Ie)
Ic = Ic1 = Ic2 = Ie/2
Vout = Vcc-Ic*Rc

#Result
print("(i) Re = %.1f k-ohm\n\n(ii) Vout = %.2f V"%(Re/1000,Vout))

(i) Re = 11.3 k-ohm

(ii) Vout = 9.65 V


## example 1.17, Page No. 40¶

In :
# Ie3, Vce1 and differential mode gain(refer fig. 1.54)

import math
#Variable declaration
Vbe = 0.7                 # emitter-base junction voltage drop
hfe = 250.0               # current gain
hie = 560                 # inpput impedance for Q1 and Q2
Rin = 1.0*10**3           # Source resistance
Rb4 = 1.5*10**3           # Emitter resistance
Rc = 1.0*10**3            # collector resistance
Vcc = 12                  # supply voltage

# Calculations
I = (Vcc-Vbe)/Rb4
Ie3 = I
Ie1 = Ie2 = Ie3/2
Ic1 = Ie1
Vce1 = Vcc+Vbe-Ic1*Rc
Aid = hfe*Rc/(Rc+hie)

#Result
print("Ie3 = %.3f mA\nVce1 = %.3f V\nAid = %.2f"%(Ie3*10**3,Vce1,math.floor(Aid*100)/100))

Ie3 = 7.533 mA
Vce1 = 8.933 V
Aid = 160.25


## example 1.18, Page No. 41¶

In :
print("Theoretical example")

Theoretical example


## example 1.19, Page No. 41¶

In :
# DC shift and curretn in the circuit (refer fig. 1.55)

import math
#Variable declaration
Vcc = 15.0              # supply voltage
R1 = 10.0*10**3         # Resistor R1
R2 = 5.0*10**3          # Resistor R2
Vbe = 0.7               # emitter-base junction voltage drop

#Calculations
shift = (Vcc*R2/R1)+Vbe*(1-(R2/R1))
I = (Vcc-Vbe)/R1

#Result
print("(Vin-Vout) = %.2f V\n\t I = %.2f mA"%(shift, I*10**3))

(Vin-Vout) = 7.85 V
I = 1.43 mA


## example 1.20, Page No. 41¶

In :
# maximum possible closed loop gain

import math
#Variable declaration
sr = 3*10**6              # slew rate in V/sec
dV = 0.4                  # input voltage variation
dt = 12*10**-6            # time in which voltage varies

#Calculations
A = sr/(dV/dt)

#Result
print("Maximum closed loop gain = %.0f"%A)

Maximum closed loop gain = 90


## example 1.21, Page No. 42¶

In :
# input bias and input offset current

import math
#Variable Declaration
Vbe = 0.7                 # emitter-base junction voltage drop
beta1 = 100.0             # current gain for Q1
beta2 = 125.0             # current gain for Q1
Re = 39*10**3             # Emitter resistance
Rc = 4.7*10**3            # collector resistance
Vcc = 12                  # supply voltage

# Calculations
Ie = (Vcc-Vbe)/Re
Ie1 = Ie2 = Ie/2
Ib1 = Ie1/beta1
Ib2 = Ie2/beta2
Ib = (Ib1+Ib2)/2
Iios = abs(Ib1-Ib2)

#Result
print("Ib   = %.4f micro-A\nIios = %.5f micro-A"%(Ib*10**6,Iios*10**6))

Ib   = 1.3038 micro-A
Iios = 0.28974 micro-A


## example 1.22, Page No. 42¶

In :
# Maximum possible amplitude of output

import math
#Variable declaration
f = 7000.0                 # frequency of input sine wave
Icq = 8*10**-6             # collector current
Cc = 27*10**-12            # Capacitance

#Calculations
S = Icq/Cc
Vm = S/(2*math.pi*f)

#Result
print("Maximum amplitude of output = %.3f V"%(math.floor(Vm*1000)/1000))

Maximum amplitude of output = 6.736 V


## example 1.23, Page No. 42¶

In :
# Slew rate

import math
#Variable declaration
Vm = 3.8                   # output amplitude
tr = 4.5*10**-6            # required rise time
S_741 = 0.5*10**-6         # slew rate of IC741 op-amp

#Calculations
del_V = (0.9-0.1)*Vm
S = del_V/tr

#Result
print("Required slew rate = %.3f V/micro-s"%(math.floor(S/10**3)/1000))
print("Slew rate of IC 741 is 0.5V/usec which is too low as compared to the required value. Hence Ic 741 cannot be used.")

Required slew rate = 0.675 V/micro-s
Slew rate of IC 741 is 0.5V/usec which is too low as compared to the required value. Hence Ic 741 cannot be used.


## example 1.24, Page No.43¶

In :
# Maximum gain using op-amp

import math
#Variable declaration
S = 0.4*10**6              # op-amp slew rate in V/sec
Vm = 0.04                  # maximum input
w = 1.13*10**5             # freq in rad/sec

#Calculations
fm = w/(2*math.pi)
V = S/(2*math.pi*fm)
G = V/Vm

#Result
print("Gain = %.1f "%G)

Gain = 88.5


## example 1.25, Page No. 43¶

In :
# smallest and largest possible input bias current and input offset current

import math
#Variable declaration
Ie = 400*10**-6           # total emitter bias current
beta_min = 80             # minimum current gain
beta_max = 200            # maximum current gain

#Calculation
Ie1 = Ie2 = Ie/2
Ib1_1 = Ib2_1 = Ie1/(1+beta_min)     # for beta =80
Ib1_2 = Ib2_2 = Ie1/(1+beta_max)

Ib_max = (Ib1_1+Ib2_1)/2
Ib_min = (Ib1_2+Ib2_2)/2
Iios = Ib_max-Ib_min

#Result
print("Largest input bias current   = %.3f micro-A\nSmallest input bias current  = %.3f micro-A"%(Ib_max*10**6,Ib_min*10**6))
print("Largest input offset current = %.3f micro-A"%(Iios*10**6))

Largest input bias current   = 2.469 micro-A
Smallest input bias current  = 0.995 micro-A
Largest input offset current = 1.474 micro-A


## example 1.26, Page No.43¶

In :
# Collector current for each transistor(refer fig. 1.59)

import math
#Variable declaration
Vbe = 0.715                 # emitter-base junction voltage drop
beta = 100.0                # Current gain
Vcc = 10                    # input voltage
Rc1 = 5.6*10**3             # Collector resistance
Rc2 = 1.0*10**3             # Collector resistance

#Calculations
I = (Vcc-Vbe)/Rc1
Ic2 = (beta/(beta+4))*I

#Result
print("I   = %.3f mA\nIc2 = Ic3 = Ic4 = %.4f mA"%(I*1000,math.floor(Ic2*10**7)/10000))

I   = 1.658 mA
Ic2 = Ic3 = Ic4 = 1.5942 mA


## example 1.27, Page No. 44¶

In :
#Differential amplifier parameter

import math
#Variable declaration
beta = 100.0               # current gain
Vbe = 0.715                # emitter-base junction voltage drop
Vz = 6.2                   # Zener Voltage
Iz = 41*10**-3             # Zener Current
Rc = 4.7*10**3             # Collector Current
Rin = 500                  # input resistance
Rb = 68*10**3              # base voltage
Re = 2.7*10**3             # emitter resistance
Vcc = 10                   # Supply Voltage
hie = 1000.0               # input resistance

#Calculations
I = (Vcc-Vbe-Vz)/Rb
I = math.floor(I*10**8)/10**8
Ie3 = (Vcc-Vbe-Rb*I)/Re
Ie3 = math.ceil(Ie3*10**7)/10**7
Ic3 = (beta/(1+beta))*Ie3
Ic3 = math.floor(Ic3*10**7)/10**7
Ie = Ic3/2
Ie = math.floor(Ie*10**7)/10**7
Ic = beta*Ie/(1+beta)
Ic = math.ceil(Ic*10**7)/10**7
Vce = Vcc+Vbe-Ic*Rc
Vce = math.floor(Vce*10**4)/10**4
Aid = beta*Rc/(Rin+hie)
Ri = Rin+2*hie

#Result
print("(i) Aid = %.3f\n\n(ii) input Resistance = %.1f k-ohm\n\n(iii) Icq = %.4f mA\t\tVceq = %.4f V"%(Aid,Ri/1000,Ic*1000,Vce))
#Value for input resistance is wrong in the book

(i) Aid = 313.333

(ii) input Resistance = 2.5 k-ohm

(iii) Icq = 1.1256 mA		Vceq = 5.4246 V