#Example 6.1
#In the circuit of figure 6-3(a) Rin=50 Ohm,Ci=0.1 uF,R1=100 Ohm, Rf=1 KOhm
#Rl=10 kOhm and supply voltages +15, -15 V.
#Determine the bandwidth of the amplifier.
from __future__ import division #to perform decimal division
import math
#Variable declaration
R1=100
Rf=1*10**3
Rin=50
Rl=10*10**3
Ci=0.1*10**-6 #Capacitance b/w 2 stages being coupled
RiF=R1 #ac input resistance of the second stage
Ro=Rin #ac output resistance of the 1st stage
UGB=10**6 #Unity gain bandwidth
#calculation
fl=1/(2*math.pi*Ci*(RiF+Ro)) #Low-freq cutoff
K=Rf/(R1+Rf)
Af=-Rf/R1 #closed loop voltage gain
fh=UGB*K/abs(Af) #High-freq cutoff
BW=fh-fl #Bandwidth
#result
print "\n Low-freq cutoff is",round(fl/10**3,2),"kHz"
print "\n High-freq cutoff is",round(fh/10**3,2),"kHz"
print"\n Bandwidth is",round(BW/10**3,2),"kHz"
#Example 6.2
#For the noninverting amplifier of figure 6-4(c), Rin=50 Ohm,Ci=C1=0.1 uF
#R1=R2=R3=100 kOhm,Rf=1 MOhm,Vcc=15 V.Determine
#a)the bandwidth of the amplifier
#b)the maximum output voltage swing
from __future__ import division #to perform decimal division
import math
#Variable declaration
R1=100*10**3
R2=100*10**3
R3=100*10**3
Rf=1*10**6
Rin=50
Ci=0.1*10**-6 #Capacitance b/w 2 stages being coupled
Ro=Rin #ac output resistance of the 1st stage
Vcc=15
UGB=10**6 #Unity gain bandwidth
Rif=R2*R3/(R2+R3) #since Ri*(1+A*B)>>R2 or R3
#calculation
fl=1/(2*math.pi*Ci*(Rif+Ro)) #Low-freq cutoff
K=Rf/(R1+Rf)
Af=-Rf/R1 #closed loop voltage gain
fh=UGB*K/abs(Af) #High-freq cutoff
BW=fh-fl #Bandwidth
#result
print "Low-freq cutoff is",round(fl,2),"kHz"
print "High-freq cutoff is",round(fh/10**3,2),"kHz"
print"Bandwidth is",round(BW/10**3,2),"kHz"
print "The ideal maximum output voltage swing is",Vcc,"Volts"
#Example 6.3
#The circuit of figure 6-5(a) is to provide a gain of 10 at a peak frequency of
#16 kHz. Determine the value of all its components.
from __future__ import division #to perform decimal division
import math
#Variable declaration
fp=16*10**3 #Peak frequency
Af=10 #Gain at peak frequency
C=0.01*10**-6 #Assume
R=30 #Assume the value of internal resistance of the inductor
R1=100 #Assume the value of internal resisrance of the coil
#calculation
L=1/(((2*math.pi*fp)**2)*10**-8) #Simplifying fp=1/(2*pi*sqrt(L*C))
Xl=2*math.pi*fp*L #Inductive reactance
Qcoil=Xl/R #Figure of merit of the coil
Rp=((Qcoil)**2)*R #Parallel resistance of the tank circuit
Rf=-Rp/(1-(Rp/(Af*R1))) #Simplifying Af=(Rf||Rp)/R1
#result
print "Inductance is",round(L*10**3,1),"mH"
print "Figure of merit of the coil is",round(Qcoil,1)
print "Parallel resistance of the tank circuit is",round(Rp/10**3,2),"kHz"
print "Feedback resistance is",round(Rf/10**3,2),"kHz"
#Example 6.4
#In the circuit of figure 6-6 Va=1V, Vb=2V, Vc=3V, Ra=Rb=Rc=3 kOhm,Rf=1 kOhm
#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,
#determine the output voltage Vo
from __future__ import division #to perform decimal division
import math
#Variable declaration
Va=1 #Input voltage in Volts
Vb=2 #Input voltage in Volts
Vc=3 #Input voltage in Volts
Ra=3*10**3 #Resistance in ohms
Rb=3*10**3 #Resistance in ohms
Rc=3*10**3 #Resistance in ohms
Rf=1*10**3 #Resistance in ohms
#calculation
Vo=-((Rf/Ra)*Va+(Rf/Rb)*Vb+(Rf/Rc)*Vc) #Output voltage
#result
print "Output voltage is",Vo,"Volts"
#Example 6.5
#In the circuit of figure 6-7 Va=2V, Vb=-3V, Vc=4V, R=R1=1 kOhm,Rf=2 kOhm
#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,
#determine the output voltage Vo and voltage V1 at the noninverting terminal.
from __future__ import division #to perform decimal division
import math
#Variable declaration
Va=2 #Input voltage in volts
Vb=-3 #Input voltage in volts
Vc=4 #Input voltage in volts
R1=1*10**3 #Resistance in ohms
Rf=2*10**3 #Resistance in ohms
#calculation
V1=(Va+Vb+Vc)/3 #Voltage at non-inverting terminal
Vo=(1+Rf/R1)*V1 #Output voltage
#result
print "Voltage at non-inverting terminal is",V1,"Volts"
print "Output voltage is",Vo,"Volts"
#Example 6.6
#In the circuit of figure 6-9 Va=2V, Vb=3V,Vc=4V,Vc=4V,Vd=5V,R=1 kOhm
#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,
#Determine the output voltage Vo
from __future__ import division #to perform decimal division
import math
#Variable declaration
Va=2 #Input voltage in volts
Vb=3 #Input voltage in volts
Vc=4 #Input voltage in volts
Vd=5 #Input voltage in volts
R=1*10**3 #Resistance in ohms
#calculation
Vo=-Va-Vb+Vc+Vd #Output voltage
#result
print "Output voltage is",Vo,"Volts"
#Example 6.7
#In the circuit of figure 6-12 R1=1 kOhm, Rf=4.7 kOhm, Ra=Rb=Rc=100 kOhm.
#Vdc=5V and Supply voltages are 15V and -15V.
#The transducer is a thermistor with the following specifications.
#Rt=100 kOhm at a reference temperature of 25 degree celcius, temperature
#coefficient of resistance =-1 kOhm/ degree celcius or 1%/degree celcius.
#Determine the output voltage Vo at o degree C and 100 degree C.
from __future__ import division #to perform decimal division
import math
#Variable declaration
R1=1*10**3 #Resistance in ohms
Rf=4.7*10**3 #Resistance in ohms
Ra=100*10**3 #Resistance in ohms
Rb=100*10**3 #Resistance in ohms
Rc=100*10**3 #Resistance in ohms
Vdc=5 #dc voltage in Volts
Rt=100*10**3 #Resistance of a thermistor
temp_coeff=1*10**3
R=Ra #Ra=Rb=Rc=R
#calculation
delta_R=-temp_coeff*(0-25) #Change in resistance
Vo1=((Rf*delta_R)/(R1*4*R))*Vdc #Output voltage at degrees
delta_R=-temp_coeff*(100-25) #Change in resistance
Vo2=((Rf*delta_R)/(R1*4*R))*Vdc #Output voltage at 100 degrees
#result
print "Output voltage at 0 degree is",round(Vo1,2),"Volts"
print "Output voltage at 100 degree is",round(Vo2,2),"Volts"
#Example 6.8
#The circuit of Figure 6-12 is used as an analog weight scale with the following
#specifications. The gain of the differential instrumentation amplifier = -100.
#Assume that Vdc= +10 V and the opamp supply voltages = +/- 10 V. The unstrained
#resistance of each of the four elements of the strain gage is 100 ohm Vo= 1 V.
#When a certain weight is placed on the scale platform,the output voltage Vo=1 V.
#Assuming that the output is initially 0,determine the change in the resistance
#of each strain-gage element.
from __future__ import division #to perform decimal division
import math
#Variable declaration
A=-100 #Gain of the differential instrumentation amplifier
Ra=100
Rb=100
Rc=100
Vdc=10
Vo=1
R=Ra #Ra=Rb=Rc=R
#calculation
delta_R=(Vo*R)/(Vdc*abs(A)) #Change in resistance
#result
print "Change in resistance is",delta_R,"ohm"
#Example 6.9
#The differential input and output amplifier of figure 6-14(a) is used as a
#pre-amplifier and requires a differential output of atleast 3.7 V. Determine
#the gain of the circuit if the differential input Vin=100 mV.
from __future__ import division #to perform decimal division
import math
#Variable declaration
Vo=3.7 #differential output voltage in Volts
Vin=100*10**-3 #differential input voltage in Volts
R1=100 #Assume
Rf=0.5*((Vo*R1)/Vin-1) #Feedback resisrance
#calculation
A=(1+2*Rf/R1) #Gain of the differential amplifier
#result
print "Feedback resisrance is",round(Rf/10**3,1),"kOhm"
print "Gain of the differential amplifier is",round(A,0)
#Example 6.10
#In the figure 6-17, for the indicated values of resistors, determine the full
#scale range for the input voltage.
from __future__ import division #to perform decimal division
import math
#Variable declaration
R1min=1*10**3
R1max=6.8*10**3
io=1*10**-3 #Meter current for full-wave rectification
#calculation
vin_min=1.1*R1min*io #Minimum input voltage
vin_max=1.1*R1max*io #Maximum input voltage
#result
print "Minimum input voltage is",vin_min,"Volts"
print "Maximum input voltage is",vin_max,"Volts"
#Example 6.11
#The circuit of figure 6-18,when the switch is in position 1, Vin=0.5 V and
#Vo=1.2 V. Determine the current through the diode and the voltage drop across
#it.Assume that the opamp is initially nulled.
from __future__ import division #to perform decimal division
import math
#Variable declaration
Vin=0.5 #Input voltage
Vo=1.2 #Output voltage
R1=100
#calculation
Io=Vin/R1 #Current through diode
Vd=Vo-Vin #Voltage drop across diode
#result
print "Current through diode is",Io*10**3,"mA"
print "Voltage drop across diode is",Vd,"Volts"
#Example 6.12
#The circuit of figure 6-19,Vin=5 V, R=1 Kilo Ohm and V1=1 V. Find
#a) the load current.
#b) the output voltage Vo.
#Assume that the op-amp is initially nulled.
from __future__ import division #to perform decimal division
import math
#Variable declaration
Vin=5 #Input voltage in Volts
V1=1 #Voltage in Volts
R1=10*10**3 #Resistance in ohms
#calculation
I1=Vin/R1 #Load current
Vo=2*V1 #Output voltage
#result
print "Load Current is",I1*10**3,"mA"
print "Output voltage is",Vo,"Volts"
#Example 6.13
#The circuit of figure 6-20, Vref=2V, R1=1 kilo Ohm. Rf=2.7 kilo Ohm. Assuming
#that the opamp is initially nulled, determine the range for the output voltage
#Vo.
from __future__ import division #to perform decimal division
import math
#Variable declaration
R1=1*10**3 #Resistance in ohms
Rf=2.7*10**3 #Resistance in ohms
Vref=2 #Voltage in Volts
Io=0 #Since all the binary inputs D0 to D7 are logic zero
#calculation
Vo_min=Io*Rf #Minimum output voltage
Io=(Vref/R1)*(1/2+1/4+1/8+1/16+1/32+1/64+1/128+1/256)
Vo_max=Io*Rf #Maximum output voltage
#result
print "Minimum output voltage is",Vo_min,"Volts"
print "Maximum output voltage is",round(Vo_max,2),"Volts"
#Example 6.14
#The circuit of figure 6-21, Vdc=5 V and Rf=3 kilo Ohm. Determine the change in
#the output voltage if the photocell is exposed to light of 0.61 lux from a dark
#condition.Assume that the opamp is initially nulled.
from __future__ import division #to perform decimal division
import math
#Variable declaration
Rf=3*10**3
Vdc=5
Rt1=100*10**3 #Resistance at darkness in ohms
Rt2=1.5*10**3 #Resistance at Illumination in ohms
#calculation
Vomin=-(Vdc/Rt1)*Rf #Min output voltage at darkness
Vomax=-(Vdc/Rt2)*Rf #Max output voltage at Illumination
#result
print "Minimum output voltage at darkness is",Vomin,"Volts"
print "Maximum output voltage at illumination is",round(Vomax,2),"Volts"
#Example 6.15
#In the figure 6-23, R1Cf=1 second, and the input is a step(dc) voltage, as
#shown in figure 6-26(a). Determine the output voltage and sketch it.
#Assume that the opamp is initially nulled.
%matplotlib inline
import math
import scipy
from matplotlib.pyplot import ylabel, xlabel, title, plot, show
import scipy.integrate
#Variable declaration
Vin=2 #Input voltage in Volts
VoO=0 #Output offset voltage
#calculation
def integrnd(x) :
return 2
val1, err = scipy.integrate.quad(integrnd, 0, 1)
val2, err = scipy.integrate.quad(integrnd, 1, 2)
val3, err = scipy.integrate.quad(integrnd, 2, 3)
val4, err = scipy.integrate.quad(integrnd, 3, 4)
a=-val1
b=a+-val2
c=b+-val3
d=c+-val4
import matplotlib.pyplot as plt
x=[0,1,2,3,4]
y=[VoO,a,b,c,d]
plt.plot(x,y)
title('Output voltage')
xlabel('time')
ylabel('Voutput')
plt.show()