# Chapter 4: Basic Op Amp Circuits¶

## Example 4.1, Page 98¶

In [1]:
#Variable declaration
Rf=10.*10**3;     #/In Ohms
Ri=1*10**3;     #/In Ohms

#Calculations
Av=1+(Rf/Ri);

#Result
print "Gain of Circuit is %.f"%Av

Gain of Circuit is 11


## Example 4.2, Page 98¶

In [2]:
#Variable declaration
Av1=26.;#in dB
Av=20.;
#Zi=47*10**3  #in ohms
Ri=1.0*10**3;     #/In Ohms

#Calculations&Results
#we know Av=1+(Rf/Ri)
Rf=Ri*(Av-1);
print "Value of Rf(ohm) when Ri is 1k =%.2f"%Rf
Ri=2*10**3;     #/In Ohms
Rf=Ri*(Av-1);
print "Value of Rf(ohm) when Ri is 1k=%.2f"%Rf
Ri=5*10**2;     #/In Ohms
Rf=Ri*(Av-1);
print "Value of Rf(ohm) when Ri is 1k =%.2f"%Rf

Value of Rf(ohm) when Ri is 1k =19000.00
Value of Rf(ohm) when Ri is 1k=38000.00
Value of Rf(ohm) when Ri is 1k =9500.00


## Example 4.3, Page 99¶

In [3]:
#Variable declaration
Av=1;
#Av=1+(Rf/Ri)
#Rf/Ri=Av-1=0

#Calculations&Results
print "Rf/Ri=0 ";
print "Rf is replaced by short circuiting wire and Ri can have any theoretical value"
print "When Ri is infinite it can be deleted from circuit";

Rf/Ri=0
Rf is replaced by short circuiting wire and Ri can have any theoretical value
When Ri is infinite it can be deleted from circuit


## Example 4.4, Page 100¶

In [4]:
import math

#Variable declaration
Rf=14.*10**3;#in ohm
Ri=2.*10**3;#in ohm

#Calculations&Results
Av1=1+(Rf/Ri);
print "Av1 is %.f"%Av1
Av3=20*math.log10(Av1);
print "Av1 in dB is %f"%Av3

Rf=18.*10**3;#in ohm
Ri=2*10**3;#in ohm
Av2=1+(Rf/Ri);
print "Av2 is %.f"%Av2
Av4=20*math.log10(Av2);
print "Av2 dB is %.f"%Av4
Avt=Av3+Av4;
print "Total Gain dB Av1+Av2 is %f"%Avt
vin=-30;#in dB
vout=Avt+vin;
print "Vout in dB %f"%vout

Av1 is 8
Av1 in dB is 18.061800
Av2 is 10
Av2 dB is 20
Total Gain dB Av1+Av2 is 38.061800
Vout in dB 8.061800


## Example 4.5, Page 102¶

In [5]:
#Variable declaration
Ri=5*10**3;# in ohm
Rf=20.*10**3;# in ohm
vin=100*10**-3;#In volt

#Calculations
Av=-(Rf/Ri);
vout=vin*Av;

#Result
print "Vout is %f volts"%vout;
print "(i.e. negative sign means inverted)";

Vout is -0.400000 volts
(i.e. negative sign means inverted)


## Example 4.6, Page 103¶

In [6]:
#Variable declaration
Ri=15.*10**3;
zin=Ri;
Av=-10;#inverting amplifier gain

#Calculations
#Av=-(Rf/Ri)
Rf=Ri*-Av;

#Result
print "Value for Rf = %.f ohms"%Rf;

Value for Rf = 150000 ohms


## Example 4.7, Page 103¶

In [8]:
import math

#Variable declaration
#capacitors are used to remove higher frequencies
Rf=200.*10**3;#In Ohm
Ri=15*10**3; #In Ohm

#Calculations&Results
Av=-(Rf/Ri);
Av1=20*math.log10(-Av);
print "Maximum gain is %.2f"%Av
print "Maximum gain in dB is %.1f"%Av1
Av2=0;# divider action makes Ri infinite
print "Minimum gain in dB is %.f"%Av2;

Maximum gain is -13.33
Maximum gain in dB is 22.5
Minimum gain in dB is 0


## Example 4.8, Page 105¶

In [9]:
#Variable declaration
Iin=50*10**-6;       #In Ampere
Vout=4.;     #In Volt

#Calculations
Rf=Vout/Iin;

#Result
print "Transresistance of Circuit is %.f ohms"%Rf

Transresistance of Circuit is 80000 ohms


## Example 4.9, Page 107¶

In [15]:
#Variable declaration
Ri=20*10**3;     #In Ohm
Vin=0.4;        #In Volt
Rl=1*103;#In ohm

#Calculations&Results
gm=1./Ri;        #unit-micro*Siemens
#maximum current is 20microAmp in Op Amp
print "V max = %.f V"%Vout;  #incorrect answer in textbook

Load current is 20 uA
V max = 402 V


## Example 4.10, Page 107¶

In [16]:
#Variable declaration
Vin=10;     #In Volt

#Calculations
Ri=1./gm;

#Result
print "Value of Ri = %f ohms"%Ri

Value of Ri = -0.001667 ohms


## Example 4.11, Page 110¶

In [17]:
#Variable declaration
Iin=5*10**-6;        #In Ampere
Ri=33*10**3;     #In Ohm
Rf=1*10**3;          #In Ohm

#Calculations&Results
Ai=1+(Ri/Rf);           #for inverting current amplifier
Iout=Ai*Iin;
print "I out = %f A"%Iout
print "Vmax is %f V"%Vmax
print "(No problem)"

I out = 0.000170 A
Vmax is 1.865000 V
(No problem)


## Example 4.12, Page 111¶

In [18]:
#Variable declaration
Ai=50.;
Rl=200*10**3;          #In Ohm
#Ai=1+(Ri/Rf)
Rf=1.*10**3;          #In Ohm(Assumption)

#Calculations&Results
Ri=Rf*(Ai-1);
print "Ri for Rf 1000ohm = %.f ohms"%Ri
Rf=2*10**3;          #In Ohm(Assumption)
Ri=Rf*(Ai-1);
print "Ri for Rf 2000ohm = %.f ohms"%Ri
Rf=0.5*10**3;          #In Ohm(Assumption)
Ri=Rf*(Ai-1);
print "Ri for Rf 500ohm = %.f ohms"%Ri
Imax=13.5/Rl;
print "Resulting current = %f A"%Imax;
print "Maximum allowable input current = %f A"%(Imax/50);

Ri for Rf 1000ohm = 49000 ohms
Ri for Rf 2000ohm = 98000 ohms
Ri for Rf 500ohm = 24500 ohms
Resulting current = 0.000068 A
Maximum allowable input current = 0.000001 A


## Example 4.13, Page 113¶

In [19]:
#Variable declaration
#Noninverting Amplifier
Rf=10.*10**3;          #In Ohm(Assumption)
#Channel 1
Ri1=4*10**3;          #In Ohm(Assumption)
Vi1=1.;      #In Volt

#Calculations&Results
Av1=-Rf/Ri1;
Vo1=Av1*Vi1;
print "Vout1 = %.1f V"%Vo1;
#Channel 2
Ri2=2*10**3;          #In Ohm(Assumption)
Vi2=-2;      #In Volt
Av2=-Rf/Ri2;
Vo2=Av2*Vi2;
print "Vout2 = %.f V"%Vo2
#Channel 3
Ri3=1*10**3;          #In Ohm(Assumption)
Vi3=0.5;      #In Volt
Av3=-Rf/Ri3;
Vo3=Av3*Vi3;
print "Vout1 = %.f V"%Vo3
print "Total output via summation is %.1f V"%(Vo1+Vo2+Vo3)

Vout1 = -2.5 V
Vout2 = 10 V
Vout1 = -5 V
Total output via summation is 2.5 V


## Example 4.14, Page 116¶

In [1]:
import math
import numpy
import sympy
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

#Variable declaration
#Noninverting Amplifier
V1=1;       #In Volt
V2=-0.2;        #In Volt
#to draw graph of V3
t=numpy.linspace(0,0.5)

#Calculations
#from sympy import Symbol
#t = Symbol('t')
V3=2*numpy.sin(100*t);      #In Volt
R1=20*10**3;    #In ohm
R2=20*10**3;    #In ohm
R3=20*10**3;    #In ohm
Rf=20*10**3;    #In ohm
Ri=5*10**3;    #In ohm
#Vout=(1+(Rf/Ri))*(V1+V2+V3)/3;
Vout=(1+(Rf/Ri))*(V1+V2)/3;     #for DC componet in Vin
Voutac=(1+(Rf/Ri))*(V3)/3;      #for ac componet in Vin

#Results
print "Output Voltage is 3.33 V peak sine wave riding on 1.33 V DC";
plt.plot(Voutac+Vout);
plt.title("Output")
plt.xlabel("t")
plt.ylabel("V")
plt.show()

Output Voltage is 3.33 V peak sine wave riding on 1.33 V DC


## Example 4.15, Page 118¶

In [28]:
import math

#Variable declaration
Ri=10.*10**3;     #In ohm
Av=26;      #In dB

#Calculations
Av1=10*math.log10(Av);
Rf1=Av1*Ri;
#Rf1=20*Ri1;
#Ri1+20*Ri1=Ri;
#Ri1=Ri-Rf1;
Ri1=Ri/21;
Rf1=20*Ri1*10**-3;

#Result
print "Rf1 is %.2f ohm"%Rf1

Rf1 is 9.52 ohm