# parameters of practical invertig amplifier
import math
#VAriable declaration
R1 = 470 # Resistor R1
Rf = 4.7*10**3 # feedback resistor
A = 2*10**5 # Open loop gain
Rin= 2*10**6 # input resistance
Ro = 75 # output resistance
f = 5 # single break frequency
V = 15 # dual supply voltage
#Calculations
K = Rf/(R1+Rf)
B = R1/(R1+Rf)
B = math.floor(B*10000)/10000
Af = (-A*Rf)/(R1+Rf+R1*A)
Rinf = R1+(Rf*Rin/(Rf+Rin+A*Rin))
Rof = Ro/(1+A*B)
ff = f*(1+A*B)
#Result
print("Closed loop voltage gain with feedback = %.0f\nInput resistane with feedback = %.4f ohm"%(math.floor(Af),Rinf))
print("Output resistance with feedback = %.2f m-ohm\nBandwidth with feedback = %.3f KHz"%(Rof*1000,ff/1000))
# inverting Op-amp design
import math
#Variable declaration
Af = -30.0 # voltage gain
Rf = 1*10**6 # feedback resistance
#Calcaculation
R1 = -Rf/Af
#Result
print("R1 = %.2f k-ohm\nlet us choose, R1 = 30 k-ohm + 3.3 k-ohm......standard values(refer fig. 3.7)"%(R1/1000))
print("Theoretical example")
# Value of feedback resistance
import math
#Variable declaration
Af = 61 # gain with feedback
R1 = 1000 # resistor R1
#Calculations
Rf = (Af-1)*R1
#Result
print("Rf = %d k-ohm"%(Rf/1000))
# parameters of non-invertig amplifier
import math
#VAriable declaration
R1 = 1000.0 # Resistor R1
Rf = 10*10**3 # feedback resistor
A = 2*10**5 # Open loop gain
Rin= 2*10**6 # input resistance
Ro = 75 # output resistance
f = 5 # single break frequency
V = 12 # dual supply voltage
#Calculations
B = R1/(R1+Rf)
#B = math.floor(B*10000)/10000
Af = A/(1+A*B)
Rinf = Rin*(1+A*B)
Rof = Ro/(1+A*B)
ff = f*(1+A*B)
#Result
print("Closed loop voltage gain with feedback = %.3f\nInput resistane with feedback = %.2f G-ohm"%(Af,math.floor((Rinf/10**9)*100)/100))
print("Output resistance with feedback = %.2f m-ohm\nBandwidth with feedback = %.2f KHz"%(Rof*1000,ff/1000))
# inverter parameters
import math
#Variable declaration
A = 2*10**5 # Open loop gain
Rin= 2*10**6 # input resistance
Ro = 75 # output resistance
f = 5 # single break frequency
#Calculations
Af = -1 # inverter gain
Rf = 330.0 # Rf = R1, Value assumed
R1 = Rf
B = R1/(R1+Rf)
Rof = Ro/(A*B)
BW = f*(A*B)
#Result
print("Af = %.0f\nRif = %.0f ohm\nRof = %.5f ohm\nfF = %.1f MHz"%(Af,Rf,Rof,BW/10**6))
# parameters of invertig and non-inverting amplifier
import math
#VAriable declaration
R1_n = 1000.0 # Resistor R1 in case of non-inverting ampliflier
Rf_n = 10*10**3 # feedback resistor in case of non-inverting ampliflier
R1_i = 470.0 # Resistor R1 in case of inverting ampliflier
Rf_i = 4.7*10**3 # feedback resistor in case of inverting ampliflier
A = 2*10**5 # Open loop gain
Ri = 2*10**6 # input resistance
Ro = 75 # output resistance
f = 5 # single break frequency
V = 15 # dual supply voltage
Vos = 13 # output voltage swing
#Calculations
#(i) Non-inverting amplifier
B = R1_n/(R1_n+Rf)
Af = 1+(Rf_n/R1_n)
Rinf = Ri*(1+A*B)
Rof = Ro/(1+A*B)
ff = f*(1+A*B)
ff =ff/1000 # KHz
VooT = Vos/(1+A*B)
#(ii) Inverting amplifier
B_i = R1_i/(R1_i+Rf)
Af_i = -(Rf_i/R1_i)
Rinf_i = R1_i
Rof_i = Ro/(1+A*B_i)
ff_i = f*(1+A*B_i)
ff_i =ff_i/1000 # KHz
VooT_i = Vos/(1+A*B_i)
#Result
print("(i) Non-inverting amplifier:")
print(" Closed loop voltage gain with feedback = %.0f\n Input resistane with feedback = %.4f ohm"%(math.floor(Af),Rinf/10**9))
print(" Output resistance with feedback = %.5f ohm\n Bandwidth with feedback = %.2f KHz"%(Rof,math.ceil(ff*100)/100))
print(" Total output offset voltage with feedback = +/- %.3f mV"%(VooT*1000))
print("\n(ii) Inverting amplifier:")
print(" Closed loop voltage gain with feedback = %.0f\n Input resistane with feedback = %.0f ohm"%(math.floor(Af_i),Rinf_i))
print(" Output resistance with feedback = %.5f ohm\n Bandwidth with feedback = %.2f KHz"%(Rof,math.ceil(ff*100)/100))
print(" Total output offset voltage with feedback = +/- %.3f mV"%(VooT*1000))
# inverting amplifier parameters
import math
#variable declaration
Rf = 500*10**3 # feedback resistance
R1 = 5*10**3 # R1 resistance
Vi = 0.1 # input voltage
#Calculation
Af = -Rf/R1
Ri = R1
Ro = 0
Vout = Af*Vi
Iin = Vi/R1
#Result
print("Af = %d\nRi = %d k-ohm\nRo = %d ohm\nVout = %d V\nIin = %.2f mA"%(Af,Ri/1000,Ro,Vout,Iin*1000))
# input ippedance, Voltage gain and power gain(refer fig. 3.15)
import math
#Variable declaration
Rf = 1*10**6 # feedback resistance
Rin = 1*10**6 # input resistance
#Calculations
Av = -Rf/Rin
Ai = 1 #unity gain inverter
Ap = abs(Av*Ai)
#Result
print("(i) Given amplifier is an inverting amplifier,therefore, Av = %.0f"%Av)
print("(ii) Because it is a unity gain inverter, so Ai = %.0f"%Ai)
print("(iii) Power gain of op-amp circuit, Ap = %.0f"%Ap)
# inverting op-amp circuit design
import math
# Variable declaartion
Av = -8 # voltage gain
Vin = -1 # input voltage
I1 = 15*10**-6 # maximum current through R1 and Rf
#Calculations
R1 = abs(Vin)/I1
R1std = 68*10**3 # standard value
Rf = -Av*R1
#Result
print("R1 = %.2f K-ohm\t\t(we use %.0f K-ohm as standard value)"%(R1/1000,R1std/1000))
print("Rf = %f K-ohm"%(Rf/1000))
#Answer for Rf is wrong in the book
print("Theoretical example")