#Example 3.1
#Compute the following parameters of voltage-series feedback amplifier
#Af,Ri,Ro,fF,VooT
from __future__ import division #to perform decimal division
#Variable declaration
R1=1000 #Resistance in ohms
Rf=10000 #Feedback Resistance in Ohms
A=200000 #Open-loop voltage gain
Ri=2*10**6 #Input resistance without feedback
Ro=75 #Output resistance without feedback
fo=5 #Break frequency of an Op-amp
Vsat=13 #Saturation voltage
#calculation
B=R1/(R1+Rf) #Gain of the feedback circuit
Af=A/(1+A*B) #Closed-loop voltage gain
RiF=Ri*(1+A*B) #Input resistance with feedback
RoF=Ro/(1+A*B) #Output resistance with feedback
fF=fo*(1+A*B) #Bandwidth with feedback
VooT=Vsat/(1+A*B) #Total output offset voltage with feedback
#Result
print "Closed-loop voltage gain is",round(Af,2)
print "Input resistance with feedback is",round(RiF/10**9,2),"Giga Ohm"
print "Output resistance with feedback is",round(RoF*10**3,2),"mOhm"
print "Bandwidth with feedback is",round(fF/10**3,2),"KHz"
print "Total output offset voltage with feedback is ",round(VooT*10**3,3),"mV"
#Example 3.2
#Compute the following parameters of voltage follower circuit of figure 3-7
#Af,Ri,Ro,fF,VooT
from __future__ import division #to perform decimal division
#Variable declaration
R1=1000 #Resistance in ohms
Rf=10000 #Feedback Resistance in Ohms
A=200000 #Open-loop voltage gain
Ri=2*10**6 #Input resistance without feedback
Ro=75 #Output resistance without feedback
fo=5 #Break frequency of an Op-amp
Vsat=13 #Saturation voltage
B=1 #Gain of the feedback circuit of voltage follower
#calculation
Af=A/(1+A*B) #Closed-loop voltage gain
RiF=Ri*(1+A*B) #Input resistance with feedback
RoF=Ro/(1+A*B) #Output resistance with feedback
fF=fo*(1+A*B) #Bandwidth with feedback
VooT=Vsat/(1+A*B) #Total output offset voltage with feedback
#Result
print "Closed-loop voltage gain is",round(Af)
print "Input resistance with feedback is",round(RiF/10**9),"Giga Ohm"
print "Output resistance with feedback is",round(RoF*10**3,3),"mOhm"
print "Bandwidth with feedback is",round(fF/10**6,2),"MHz"
print "Total output offset voltage with feedback is ",round(VooT*10**6,3),"uV"
#Example 3.3
#Compute the following parameters of inverting amplifierof figure 3-8
#Af,Ri,Ro,fF,VooT
from __future__ import division #to perform decimal division
#Variable declaration
R1=470 #Resistance in ohms
Rf=4.7*10**3 #Feedback Resistance in Ohms
A=200000 #Open-loop voltage gain
Ri=2*10**6 #Input resistance without feedback
Ro=75 #Output resistance without feedback
fo=5 #Break frequency of an Op-amp
Vsat=13 #Saturation voltage
#calculation
K=Rf/(R1+Rf) #Voltage attenuation factor
B=R1/(R1+Rf) #Gain of the feedback circuit
Af=-A*K/(1+A*B) #Closed-loop voltage gain
X=Rf/(1+A)
RiF=R1+(X*Ri)/(X+Ri) #Input resistance with feedback
RoF=Ro/(1+A*B) #Output resistance with feedback
fF=fo*(1+A*B)/K #Bandwidth with feedback
VooT=Vsat/(1+A*B) #Total output offset voltage with feedback
#Result
print "Closed-loop voltage gain is",round(Af)
print "Input resistance with feedback is",round(RiF),"Ohm"
print "Output resistance with feedback is",round(RoF*10**3,2),"mOhm"
print "Bandwidth with feedback is",round(fF/10**3),"kHz"
print "Total output offset voltage with feedback is ",round(VooT*10**3,3),"mV"
%matplotlib inline
from __future__ import division #to perform decimal division
from matplotlib.pyplot import ylabel, xlabel, title, plot, show
import matplotlib.pyplot as plt
import math
import numpy as np
#Variable declaration
R1=470 #Resistance in ohms
Rf=4.7*10**3 #Feedback Resistance in Ohms
A=200000 #Open-loop voltage gain
vin=1 #input voltage in Volts
#calculation
K=Rf/(R1+Rf) #Voltage attenuation factor
B=R1/(R1+Rf) #Gain of the feedback circuit
Af=-A*K/(1+A*B) #Closed-loop voltage gain
vo=Af*vin #output voltage
x=np.arange(0,4*math.pi,0.1)
y=-5*np.sin(x)
plt.plot(x,y)
plt.ylabel('vo')
plt.xlabel('t')
plt.title(r'$output voltage$')
plt.show()
#Result
print "Output voltage is",round(vo),"V peak to peak"
#Example 3.5_a & 3.5_b
#For the circuit of figure 3_14,R1=R2=1 kilo ohm and the opamp is 741 IC.
#a) What are the gain and input resistance of the amplifier?
#b) Calculate output voltage vo if vx=2.7 V pp and vy=3 V pp sine waves at 100 Hz
from __future__ import division #to perform decimal division
#Variable declaration
R1=1000 #Resistance in ohms
R2=1000 #Resistance in ohms
Rf=10*10**3 #Feedback Resistance in Ohms
R3=10*10**3
vx=2.7 #input voltage in Volts
vy=3 #input voltage in Volts
#calculation
#part a
AD=-Rf/R1 #voltage gain
RiFx=R1 #Input resistance of inverting amplifier
RiFy=R2+R3 #Input resistance of noninverting amplifier
#part b
vxy=vx-vy
vo=AD*vxy #output volatage
#Result
print "Voltage gain is",AD
print "Input resistance of inverting amplifier is",RiFx/10**3,"kilo ohms"
print "Input resistance of noninverting amplifier is",round(RiFy/10**3),"kilo ohms"
print "Output voktage is",vo,"V peak to peak at 100 Hz"
#Example 3.6_a & 3.6_b
#For the differential amplifier of figure 3_16, R1=R3=680 ohm, Rf=R2=6.8 Kilo ohm
#vx=-1.5 V pp, vy=-2 V pp sine waves at 1 KHz and the opamp is 741 IC.
#a) What are the gain and input resistance of the amplifier?
#b) Calculate output voltage of the amplifier.(Assume vooT=0V)
from __future__ import division #to perform decimal division
#Variable declaration
R1=680 #Resistance in ohms
R2=6800 #Resistance in ohms
Rf=6800 #Feedback Resistance in Ohms
R3=680
Ri=2*10**6 #Open loop input resistance of the opamp
vx=-1.5 #input voltage in Volts
vy=-2 #input voltage in Volts
A=200000 #openloop gain
#calculation
#part a
AD=1+Rf/R1 #voltage gain
B=R2/(R2+R3)
RiFy=Ri*(1+A*B) #Input resistance of first stage amplifier
B=R1/(R1+Rf)
RiFx=Ri*(1+A*B) #Input resistance of second stage amplifier
#part b
vxy=vx-vy
vo=AD*vxy #output volatage
#Result
print "Voltage gain is",AD
print "Input resistance of first stage amplifier is",round(RiFy/10**9),"Giga ohms"
print "Input resistance of second stage amplifier is",round(RiFx/10**9,1),"Giga ohms"
print "Output voLtage is",vo,"V peak to peak at 1 KHz"