import math
#Variable declaration
R0 = 1.0 #ohm
Ri = 100.0 #kilo ohm
Aoc = 100.0 #volts per volts
Rs=0.0 #kilo ohm
Rl=0.0 #ohm
gain=0.0
input_load=0.0
output_load=0.0
#Calculation
def calculate(): #returns gain
global input_load, output_load
input_load = (Ri/(Rs+Ri))
output_load = (Rl/(R0+Rl))
ans=input_load*Aoc*output_load # in V/V
return ans
#answer part (a)
Rs=25.0
Rl=3.0
gain=calculate()
print "a)"
print "The overall gain is ",round(gain,1),"V/V"
print "The input load is ",input_load*100,"% of it's unloaded value"
print "The output load is ",output_load*100,"% of it's unloaded value"
#answer part (b)
Rs=50.0
Rl=4.0
gain=calculate()
print "b)"
print "The overall gain is ",round(gain,1),"V/V"
print "The input load is ",round(input_load*100,1),"% of it's unloaded value"
print "The output load is ",round(output_load*100,1),"% of it's unloaded value"
import math
#Variable declaration
vt = 1.0 # in volt
R1 = 2.0 # in kilo ohm
R2 = 18.0 #in kilo ohm
#Calculation
def calculate(a): #returns Vo
global vt,R1,R2
ans=vt*(1+(R2/R1))/(1+((R2/R1)/a)) #equation 1.11
return ans
#answer
print "a)Vo = ",round(calculate(10**2),5),"V"
print "b)Vo = ",round(calculate(10**4),5),"V"
print "c)Vo = ",round(calculate(10**6),5),"V"
#textbook contains precision error
import math
#Variable Declaration
R1=10*10**3 #ohm
R2=100*10**3 #ohm
#Calculation
Ri=R1 # Input Resistance
Ro=0 #Output Resistance
A=-(R2/R1) #Ideal Overall Gain
#answer
print "Ri =",round(Ri/1000,2),"kilo ohm"
print "Ro =",round(Ro),"ohm"
print "A =",round(A,2),"V/V"
#Variable declaration
rf1 = 3 # coefficient of V1
rf2 = 4 # coefficient of V2
rf3 = 2 # coefficient of V3
#Calculations
rf1*=2 # Common factor 2
rf2*=2 # Common factor 2
rf3*=2 # Common factor 2
r1=20 # assumption
rf=r1*rf1
r2=rf/rf2
r3=rf/rf3
#answer
print "R1 = ",r1,"kilo ohm"
print "R2 = ",r2,"kilo ohm"
print "R3 = ",r3,"kilo ohm"
print "Rf = ",rf,"kilo ohm"
#Variable declaration
r1,r2,rf #vo=10*v1+5=-(rf/r1*v1)-rf/r2*(-15)
#Calculation
r1=10
rf=10*r1; #-rf/r1*v1=10*v1
r2=rf*15/5 #-rf/r2*(-15)=5
#answer
print "R1 = ",r1,"kilo ohm"
print "R2 = ",r2,"kilo ohm"
print "Rf = ",rf,"kilo ohm"
#Variable declaration
ri1=100 # in kilo ohm
ri2=100 # in kilo ohm
#Calculation
r1=ri1;
r2=3*r1; #r2/r1=3
# r3 + r4 = ri2 and (1+r1/r2)/(1+r3/r4)=1
#Solving the above two
r3=ri2/4;
r4=ri2-r3
#answer
print "R1 = ",r1,"kilo ohm"
print "R2 = ",r2,"kilo ohm"
print "R3 = ",r3,"kilo ohm"
print "R4 = ",r4,"kilo ohm"
#in textbook r3 and r4 values are reversed which doesn't satisfy the equations
#Variable Declaration
A=100
accuracy=0.1
#Calcualtion
T=100/accuracy
beta=1.0/100.0 # A_ideal=i/beta=100
a=(10**3)/beta
beta=(a/100-1)/a # A=a/(1+(a*beta))
#answer
print "a)T >= ",int(T)
print "b)a >= ",int(a)
print "a)Beta = ",beta
import math
#Variable Declaration
a = 10**5
beta
T
#Calculation
def calculate():
global a,beta,T
T=a*beta
ans=10.0/(1+T) # for a +- 10% change in a
return ans
#answer
beta=10**(-3) #given
desensitivity_factor=calculate(); # stores the answer
print "a) A changes by (+-)",round(desensitivity_factor,6),"%" #part a
beta=1 #given
desensitivity_factor=calculate();
print "b) A changes by (+-)",round(desensitivity_factor,6),"%" #part b
import math
#Variable Declaration
rd = 2.0 # Mega ohm
ro = 75.0 # ohm
a = 200000.0 # V/V
#Calculation
def calculate(R1,R2):
global a,ro,rd
beta=R1/(R1+R2)
if(R1==float("inf")): # for infinty
beta=1
T=a*beta
A=(1+(R2/R1))/(1+(1/T)) # equation 1.55
if(R1==float("inf")): # for infinity
A=1/(1+(1/T))
Ro=ro/(1+T) # equation 1.61
Ri=rd*(1+T) # equation 1.59
print " A = ",round(A,6),"V/V"
print " Ro = ",round(Ro*(10**3),3),"mili ohm"
print " Ri = ", round(Ri,3),"Mega ohm"
#answer
print "a)"
calculate(1.0,999)
print "b)"
calculate(float("inf"),1)
import math
#Variable Declaration
a = 200000.0 # V/V
ro = 75 # ohm
#Calculating function
def calculate(R1,R2):
global a,ro
T=a*(R1/(R1+R2))
A=(-1)*(R2/R1)/(1+(1/T)) # equation 1.63
Rn=R2/(1+a) # equation 1.67b
Ri=R1 # equation 1.68
Ro=ro/(1+T)
print " A = ",round(A,5),"V/V"
print " Rn = ",round(Rn,5),"ohm"
print " Ri = ",round(Ri,5),"ohm"
print " Ro = ",round(Ro,5),"ohm"
#answer
print "a)"
calculate(100000.0,100000.0)
print "b)"
calculate(1000.0,1000000.0)
import math
#Variable Declaration
R1 = 1000000.0 # ohm
R2 = 1000000.0 # ohm
R3 = 100000.0 # ohm
R4 = 1000.0 # ohm
RL = 2000.0 # ohm
rd = 1000000.0 #ohm
a = 10**5 # V/V
ro = 100.0 # ohm
#Calculation
A_ideal = (-1)*(R2/R1)*(1+(R3/R2)+(R3/R4)) # ideal op-amp and summing currents at node v1
T = a/(1+(R2/R1)+(R2/rd))/(1+(ro/(R2+(R1*rd/(R1+rd))))+(ro/RL))/100 #equation 1.73
A = A_ideal/(1+(1/T))
dev=(A_ideal-A)/A_ideal*100
#answer
print "a) A_ideal =",A_ideal,"V/V"
print "b) A =",round(A,2),"V/V"
print "Deviation from ideal =",round(dev,2),"%"
#book example has precision error so answer is 0.32%
import math
#Variable Declaration
rd = 1000.0 # kilo ohm
a = 10**4 # V/V
ro = 100.0 #ohm
R1 = 10.0 # kilo ohm
R2 = 20.0 # kilo ohm
R3 = 30.0 # kilo ohm
R4 = 300.0 # kilo ohm
RL = 2.0 # kilo ohm
#Calculation
def parallel(a,b):
ans=a*b/(a+b)
return ans
Ra = parallel(R1,parallel(R2,parallel(R3,rd)))
Rb=Ra+R4
Rc=parallel(Rb,RL) #After suppressing all input sources
Rd=Rc+ro/1000 #replacing the op-amp with it's terminal resistances
Vn=Rb/Ra #and applying a test voltage and analysing the circuit
Vt=Rd/Rc
beta=1/Vn/Vt
T=a*beta
v1=R4/R1
v2=R4/R2
v3=R4/R3
A=1/(1+1/T)
#answer
print "a)"
print " Beta =",round(beta,6),"V/V"
print " T =",round(T,1)
print "b)"
print " Vo= -(",round(A*v1,2),"V1 +",round(A*v2,2),"V2 +",round(A*v3,2),"V3 )"
import math
#Variable Declaration
rd = 100.0 # kilo ohm
ro = 100.0 # ohm
R1 = 30.0 # kilo ohm
R2 = 20.0 # kilo ohm
R3 = 10.0 # kilo ohm
#Calculation
def parallel(a,b):
ans=a*b/(a+b)
return ans
beta_n = (parallel(R1,rd)+R1)/((ro/1000)+R2+parallel(R1,rd)+R3) # from circuit 1.35 after appyling
beta_p = R3/((ro/1000)+R2+parallel(R1,rd)+R3) # voltage divide formula twice
beta=beta_n-beta_p #equation 1.76
#answer
print "Beta =",round(beta,4),"V/V"
# beta_n calculation in book is wrong
import math
#Variable Declaration
R1 = 10 #kilo ohm
R2 = 20 #kilo ohm
V1 = 3 # V
Iq = 0.5 # mA
RL = 2 #kilo ohm
#Calculation
V0 = (-1)*R2/R1*V1
It = abs(V0)/RL # Currents through R1,R2,Rt are i1,i2,It respectively
i1 = It/R1
i2 = i1 # applying voltage divider rule
i0 = i2+It
icc = Iq
iee = icc+ i0
Poa = 30*Iq+((V0+15)*i0) #Whenever current passes through voltage drop, power = vi
#answer
print "a)"
print " Icc =",icc,"mA"
print " Iee =",iee,"mA"
print " I0 =",i0,"mA"
print "b)"
print " Power Poa =",Poa,"mW"
#Variable Declaration
ro = 75.0 #kilo ohm
T = 200000.0
Vs = 10.0 # V
Rl = 1.0 #kilo ohm
#Calculation
iL = Vs/Rl
Ro = ro/(1+T)
del_v = Ro*10*(10**(-3))
#answer
print "b)"
print " Change in v =",round(del_v*(10**6),2),"micro Volt -> quite a small change"
%matplotlib inline
import matplotlib.pyplot as plt
import scipy as np
import math
#Variable Declaration
A = -2 #V/V
peak = 10 # V
#Calculation
output = np.absolute(A) * peak
#answer
print "The op-amp saturates at Vo=+-13 V"
print "With Vn= 20/3-13/3 =",round((20.0/3)-(13.0/3),4),"V"
#Graphs
t1 = np.arange(0,1,.0005) # Triangular waveform
t2 = np.arange(1,3,.0005)
t3 = np.arange(3,5,.0005)
m1 = np.arange(0,0.65,.0005)
m2 = np.arange(.65,1.35,.0005)
m3 = np.arange(1.35,2.65,.0005) # Output Vo wave
m4 = np.arange(2.65,3.35,.0005)
m5 = np.arange(3.35,4.65,.0005)
m6 = np.arange(4.65,5,.0005) # Output Vn wave
m7 = np.arange(0.65,1,.0005)
m8 = np.arange(1,1.35,.0005)
m9 = np.arange(2.65,3,.0005)
m10 = np.arange(3, 3.35, .0005)
plt.subplot(2,1,1)
plt.suptitle("Vt (Blue), Vo (Red) and Vn (Green) Graphs")
plt.xlim(0,4.5)
plt.xlabel("time->")
plt.ylabel("V->")
plt.plot(t1,peak*t1,"b",)
plt.plot(t2,(-1)*peak*t2+2*(peak),"b",)
plt.plot(t3,peak*t3-4*(peak),"b",)
plt.grid(True)
plt.subplot(2,1,2)
plt.xlim(0,4.5)
plt.xlabel("time->")
plt.ylabel("V->")
plt.plot(m1,-20*m1,"r")
plt.plot(m2,np.full(len(m2),-13),"r")
plt.plot(m3,20*m3-40,"r")
plt.plot(m4,np.full(len(m4),13),"r")
plt.plot(m5,-20*m5+80,"r")
plt.plot(m6,np.full(len(m6),-13),"r")
plt.plot(m1,np.full(len(m1),0),"g",)
plt.plot(m7,6.665*m7-4.4,"g")
plt.plot(m8,-6.665*m8+8.8,"g")
plt.plot(m3,np.full(len(m3),0),"g")
plt.plot(m9,6.665*m9-17.6,"g")
plt.plot(m10,-6.665*m10+22.4,"g")
plt.plot(m5,np.full(len(m5),0),"g")
plt.plot(m6,np.full(len(m6),0),"g")
plt.grid(True)