# Chapter 7 - Feedback Amplifiers and Sinusoidal Oscillators¶

## Example 7_1 Page No. 204¶

In :
from math import log10
from __future__ import division
A=60000
print "A= %0.2f"%(A) #Amplifier gain
Af=10000
print "Af= %0.2f"%(Af) #Feedback gain
N_dB=20*log10(Af/A)
print "N_dB=20*log10(Af/A)= %0.2f"%(N_dB),"dB" #Negative feedback gain
B=(1/(Af))-(1/A)# formulae using (Af=A/(1+A*B))
print "B=(1/(Af))-(1/A)= %0.2e"%(B) #Feedback factor

A= 60000.00
Af= 10000.00
N_dB=20*log10(Af/A)= -15.56 dB
B=(1/(Af))-(1/A)= 8.33e-05


## Example 7_2 Page No. 205¶

In :
from __future__ import division
A=10000
print "A= %0.2f"%(A) #Amplifier gain
B=0.01
print "B= %0.2f"%(B) #Feedback factor
Af=(A/(1+A*B))
print "Af= (A/(1+A*B))=%0.2f"%(Af) #Feedback gain
A1=100000
print "A1= %0.2f"%(A1) #New amplifier gain value
Af1=(A1/(1+A1*B))
print "Af1= (A1/(1+A1*B))=%0.2f"%(Af1) #New feedback gain

A= 10000.00
B= 0.01
Af= (A/(1+A*B))=99.01
A1= 100000.00
Af1= (A1/(1+A1*B))=99.90


## Example 7_3 Page No. 208¶

In :
from __future__ import division
Vo=(50)
print "Vo= %0.2f"%(Vo)," volts" # output voltage
Vi=(0.5)
print "Vi= %0.2f"%(Vi)," volts" # input voltage
print "part(i)"
A=Vo/Vi
print "A= Vo/Vi=%0.2f"%(A) #Amplifier gain
HD=10
print "Harmonic_distortion=%0.2f"%(HD),"%"# Percentage second harmonic distortion
D=(10*Vo)/100
print "D= (10*Vo)/100 = %0.2f"%(D)," volts" # Second Harmonic distortion
Df=(1*Vo)/100
print "Df= (1*Vo)/100 = %0.2f"%(Df)," volts" # Harmonic distortion with Feedback
B=(D/(Df*A))-(1/A) #Using formulae Df=(D/(1+A*B))
print "B=(D/(Df*A))-(1/A) = %0.2f"%(B) #Feedback factor
print "part(ii)"
Af=(A/(1+A*B))
print "Af= (A/(1+A*B)) = %0.2f"%(Af) #Feedback gain
print "part(iii)"
Vif=Vo/Af
print "Vif= Vo/Af = %0.2f"%(Vif)," volts" # New input voltage required

Vo= 50.00  volts
Vi= 0.50  volts
part(i)
A= Vo/Vi=100.00
Harmonic_distortion=10.00 %
D= (10*Vo)/100 = 5.00  volts
Df= (1*Vo)/100 = 0.50  volts
B=(D/(Df*A))-(1/A) = 0.09
part(ii)
Af= (A/(1+A*B)) = 10.00
part(iii)
Vif= Vo/Af = 5.00  volts


## Example 7_4 Page No. 210¶

In :
from __future__ import division
GBW=10**(6)
print "GBW= %0.2f"%(GBW)," Hz"# Gain-Bandwidth product
AMf=100
print "AMf=%0.2f"%(AMf) # Midband gain with feedback
fHF=GBW/AMf
print "fHF=GBW/AMf= %0.2f"%(fHF)," Hz"#Signal bandwidth
f_10percent=(10*fHF)/100
print "f_10per cent=(10*fHF)/100= %0.2f"%(f_10percent)," Hz"#Frequency below which AMf will not deviate by more than 10 percent

GBW= 1000000.00  Hz
AMf=100.00
fHF=GBW/AMf= 10000.00  Hz
f_10per cent=(10*fHF)/100= 1000.00  Hz


## Example 7_5 Page No. 212¶

In :
from __future__ import division
AM=50000
print "AM=%0.2f"%(AM) # Midband gain
fH=20*10**(3)
print "fH= %0.2f"%(fH)," Hz"# Upper cut-off frequency
fL=30
print "fL= %0.2f"%(fL)," Hz"# Lower cut-off frequency
B=5*10**(-5)
print "B= %0.2e"%(B) #Feedback factor
AMf=AM/(1+B*AM)
print "AMf=AM/(1+B*AM)=%0.2f"%(AMf) # Midband gain with feedback
fHf=fH*(1+B*AM)
print "fHf=fH*(1+B*AM)= %0.2f"%(fHf)," Hz"#Upper cut-off frequency with feedback
fLf=fL/(1+B*AM)
print "fLf=fL/(1+B*AM)= %0.2f"%(fLf)," Hz"#Lower cut-off frequency with feedback
#NOTE: calculated value of AMf is AMf=14285.714  and fLF=8.5714286 but in book given as AMf=14286  and fLF=8.58 Hz

AM=50000.00
fH= 20000.00  Hz
fL= 30.00  Hz
B= 5.00e-05
AMf=AM/(1+B*AM)=14285.71
fHf=fH*(1+B*AM)= 70000.00  Hz
fLf=fL/(1+B*AM)= 8.57  Hz


## Example 7_6 Page No. 214¶

In :
from math import atan,pi
from __future__ import division
AM=100
print "AM=%0.2f"%(AM),"dB" # Midband gain
fc1=1*10**(4)
print "fc1= %0.2f"%(fc1)," Hz"# First Critical frequency
fc2=10**5
print "fc2= %0.2f"%(fc2)," Hz"# Second Critical frequency
fc3=10**6
print "fc3= %0.2f"%(fc3)," Hz"# Third Critical frequency
print "part(i)"
Af1=85
print "Af1=%0.2f"%(Af1),"dB" #  gain at 50 kHz and -20dB/decade roll-off
f=50*10**(3)
print "f= %0.2f"%(f)," Hz"# operating frequency
theta_A=- atan(f/fc1)*180/pi-  atan(f/fc2)*180/pi-  atan(f/fc3)*180/pi#phase shift in radians
print "theta_A=%0.2f"%(theta_A)," degree"# Phase shift for feedback gain Af1
theta_pm=180-abs(theta_A)# formulae phase margin
print "theta_pm=180-abs(theta_A)=%0.2f"%(theta_pm)," degree"# Phase Margin for feedback gain Af1
print "Amplifier stable"# Since phase margin is (+)ive
print "part(ii)"
Af2=50
print "Af2=%0.2f"%(Af2)," dB" #  gain at 500 kHz and -40dB/decade roll-off
f=500*10**(3)
print "f= %0.2f"%(f)," Hz"#  frequency
theta_A=- atan(f/fc1)-  atan(f/fc2)-  atan(f/fc3)#phase shift in radians
theta_A=theta_A*180/pi # degree
print "theta_A= %0.2f"%(theta_A)," degree"#  Phase shift for feedback gain Af2
theta_pm=180-abs(theta_A)# formulae phase margin
print "theta_pm=180-abs(theta_A)=%0.2f"%(theta_pm)," degree"# Phase Margin for feedback gain Af1
print "Amplifier  unstable"# Since phase margin is (-)ive
print "part(iii)"
Af3=20
print "Af3=%0.2f"%(Af3),"dB" #  gain at 1100 kHz and -60dB/decade roll-off
f=1100*10**(3)
print "f= %0.2f"%(f)," Hz"#  frequency
theta_A=- atan(f/fc1)-  atan(f/fc2)-  atan(f/fc3)#phase shift in radians
theta_A=theta_A*180/pi # degree
print "theta_A=%0.2f"%(theta_A)," degree"# Phase shift for feedback gain Af3
theta_pm=180-abs(theta_A)# formulae phase margin
print "theta_pm=180-abs(theta_A)=%0.2f"%(theta_pm)," degree"# Phase Margin for feedback gain Af1
print "Amplifier unstable"# Since phase margin is (-)ive
#NOTE:Correct ans for part(i) phase margin ,theta_pm=71.882476 degree but in book given as 71.86 degree
# correct ans for part(iii) phase shift, theta_A=-222.01103 degree but in book given as -220.02 degree

AM=100.00 dB
fc1= 10000.00  Hz
fc2= 100000.00  Hz
fc3= 1000000.00  Hz
part(i)
Af1=85.00 dB
f= 50000.00  Hz
theta_A=-108.12  degree
theta_pm=180-abs(theta_A)=71.88  degree
Amplifier stable
part(ii)
Af2=50.00  dB
f= 500000.00  Hz
theta_A= -194.11  degree
theta_pm=180-abs(theta_A)=-14.11  degree
Amplifier  unstable
part(iii)
Af3=20.00 dB
f= 1100000.00  Hz
theta_A=-222.01  degree
theta_pm=180-abs(theta_A)=-42.01  degree
Amplifier unstable


## Example 7_7 Page No. 216¶

In :
from __future__ import division
AV=50000
print "AV=%0.2f"%(AV) # Voltage gain
Ri=50*10**(6)
print "Ri= %0.2e"%(Ri)," ohm"  #Input resistance of OP-AMP
R0=1*10**(3)
print "R0= %0.2f"%(R0)," ohm"  #Output resistance
AVf=10
print "AVf=%0.2f"%(AVf) # Overall Voltage gain
RSf=50*10**(3)
print "RSf= %0.2f"%(RSf)," ohm"  #Source resistance
R1=RSf
RF=AVf*(R1)
print "RF=AVf*(R1)= %0.2e"%(RF)," ohm"  #Feedback resistance
VS=30
print "VS= %0.2f"%(VS)," volts" # Peak-peak output swing voltage
Vomax=0.5*(VS)
print "Vomax=0.5*(VS)= -%0.2f"%(Vomax),", +%0.2f"%(Vomax)," volts" # Maximum output voltage swing at negative and positive polarities respectively
Vsmax=Vomax/AVf
print "Vsmax=Vomax/AVf= -%0.2f"%(Vsmax),", +%0.2f"%(Vsmax)," volts" # Maximum output voltage without overload clipping at both polarities

#for overall voltage gain author has used two notations 'Avf' and 'Af' ... but I am working with 'Avf' only

AV=50000.00
Ri= 5.00e+07  ohm
R0= 1000.00  ohm
AVf=10.00
RSf= 50000.00  ohm
RF=AVf*(R1)= 5.00e+05  ohm
VS= 30.00  volts
Vomax=0.5*(VS)= -15.00 , +15.00  volts
Vsmax=Vomax/AVf= -1.50 , +1.50  volts


## Example 7_8 Page No. 218¶

In :
from __future__ import division
R1=50*10**(3)
print "R1= %0.2f"%(R1)," ohm"  # resistance at input terminal of OP-AMP
RF=500*10**(3)
print "RF= %0.2f"%(RF)," ohm"  #Feedback resistance
VS=1
print "VS= %0.2f"%(VS)," volts" # Peak-peak output swing voltage
print "part(i)"
print "A = infinite"# voltage gain
Vo1=-(RF/R1) #Output voltage when gain, A=infinite
print "Vo1=-(RF/R1)= %0.2f"%(Vo1)," volts"
print "part(ii)"
A=50000
print "A=%0.2f"%(A) #  gain of OP-AMP
B=R1/(R1+RF)
print "B=R1/(R1+RF)= %0.2f"%(B) #Feedback factor
Vo2=-((RF)*(B*A))/(R1*(1+A*B))
print "Vo2=-((RF)*(B*A))/(R1*(1+A*B))= %0.2f"%(Vo2)," volts"# output voltage for A=50000
e=-((Vo2-Vo1)*100)/Vo1
print "%%Error,e= ((Vo2-Vo1)*100)/Vo1=%0.2f"%(e),"% "#  calculation for percentage error in output voltage
print "part(iii)"
e=0.01
print "%%Error,e=%0.2f"%(e),"% "#Given percentage error in output voltage
Vo3=-(Vo1-(e*Vo1/100))
print "Vo3=Vo1-(e*Vo1/100)= %0.2f"%(Vo3)," volts"# output voltage for error 0.01%
x=Vo3*(R1/RF)
A=(x)/(B*(1-x)) #using formulae Vo=-(RF/R1)*((B*A)/1+A*B))
print "A=(Vo*R1)/(B*RF*(1-(Vo*RF/R1)))=%0.2e"%(A) # New Required gain for error less than 0.01%

# while solving the problem I have used 'e' for the error as no varriable is given for the same in textbook by author
# in textbook author has used 'Vo' for output voltage in all parts.. but to remove any ambiguity in the programe I have used 'Vo1' 'Vo2' 'Vo3' for part i, ii, iii, respectively

R1= 50000.00  ohm
RF= 500000.00  ohm
VS= 1.00  volts
part(i)
A = infinite
Vo1=-(RF/R1)= -10.00  volts
part(ii)
A=50000.00
B=R1/(R1+RF)= 0.09
Vo2=-((RF)*(B*A))/(R1*(1+A*B))= -10.00  volts
%Error,e= ((Vo2-Vo1)*100)/Vo1=0.02 %
part(iii)
%Error,e=0.01 %
Vo3=Vo1-(e*Vo1/100)= 10.00  volts
A=(Vo*R1)/(B*RF*(1-(Vo*RF/R1)))=1.10e+05


## Example 7_9 Page No. 218¶

In :
from math import log10
from __future__ import division
AV=100000
print "AV=%0.2f"%(AV) # Voltage gain
Ri=10*10**(3)
print "Ri= %0.2f"%(Ri)," ohm"  #Input resistance of OP-AMP
Ro=10
print "Ro= %0.2f"%(Ro)," ohm"  #Output resistance
Rs=10*10**(6)
print "Rs= %0.2e"%(Rs)," ohm"  #Source resistance
RL=1*10**(3)
print "RL= %0.2f"%(RL)," ohm"  #Load resistance
B=(Rs-Ri)/(AV*Ri)
print "B=(Rs-Ri)/(AV*Ri)= %0.2f"%(B) #Feedback factor
AVf=AV/(1+B*AV)
print "AVf=AV/(1+B*AV)=%0.2f"%(AVf) # Overall Voltage gain with feedback
Rof=Ro/(1+B*AV)
print "Rof=Ro/(1+B*AV) =%0.2f"%(Rof)," ohm"  #output resistance with feedback
Rif=Ri*(1+B*AV)
print "Rif=Ri/(1+B*AV) =%0.2e"%(Rif)," ohm"  #Input resistance with feedback
Ap=(AVf**2)*(Rif/RL)
print "Ap=(AVf**2)*(Rif/RL)=%0.2e"%(Ap) # Overall Power gain
AP=10*log10(Ap)
print "AP=10*log10(Ap)=%0.2f"%(AP),"dB" # Overall Power gain in dB

AV=100000.00
Ri= 10000.00  ohm
Ro= 10.00  ohm
Rs= 1.00e+07  ohm
RL= 1000.00  ohm
B=(Rs-Ri)/(AV*Ri)= 0.01
AVf=AV/(1+B*AV)=100.00
Rof=Ro/(1+B*AV) =0.01  ohm
Rif=Ri/(1+B*AV) =1.00e+07  ohm
Ap=(AVf**2)*(Rif/RL)=1.00e+08
AP=10*log10(Ap)=80.00 dB


## Example 7_10 Page No. 220¶

In :
from math import sqrt,pi,log10
from __future__ import division
gm=10*10**(-3)
print "gm = %0.2f"%(gm)," A/V"#  transconductance
Cgs=5*10**(-12)
print "Cgs= %0.2e"%(Cgs)," farad"  # capacitance between gate-source
Cds=1*10**(-12)
print "Cds= %0.2e"%(Cds)," farad"  # capacitance between drain-source
rd=50*10**(3)
print "rd= %0.2f"%(rd)," ohm"  #Drain resistance
RG=10*10**(6)
print "RG= %0.2e"%(RG)," ohm"  #Gate resistance
Rse=1*10**(3)
print "Rse= %0.2e"%(Rse)," ohm"  #Gate resistance
L=0.5
print "L= %0.2f"%(L)," H"  #Inductance
C2=0.05*10**(-12)
print "C2= %0.2e"%(C2)," farad"  # Crystal parameter
C1=1*10**(-12)
print "C1= %0.2e"%(C1)," farad"  # Crystal parameter
print "part(i)"
x=C1+((Cds*Cgs)/(Cds+Cgs))
CT=1/((1/C2)+(1/x))
print "CT= %0.2f"%(CT)," farad"  # Equivalent series-resonating capacitance
print "part(ii)"
fo=sqrt(2)/(2*pi*sqrt(L*CT))
print "fo= sqrt(2)/(2*pi*sqrt(L*CT))=%0.2e"%(fo)," Hz"# frequency of oscillations
print "part(iii)"
z=sqrt((L*C1*C2)/(C1+C2))
fp=1/(2*pi*z)
print "fp= %0.2e"%(fp)," Hz"# parallel-resonant frequency
p=sqrt(L*C2)
fs=1/(2*pi*p)
print "fs= %0.2e"%(fs)," Hz"# series-resonant frequency
Q=(sqrt(L/C2))/(Rse)
print "Q=(sqrt(L/C2))/(Rse)= %0.2f"%(Q) #Quality factor
print "part(iv)"
AB=gm*rd*(Cds/Cgs)
print "AB=gm*rd*(Cds/Cgs)= %0.2f"%(AB) #Loop gain
T_bias=RG*(Cgs+Cds)
print "T_bias=RG*(Cgs+Cds)= %0.2e"%(T_bias),"s"#Bias Time-Constant
T_r = 1/(2*pi*fo)
print "T_r =1/(2*pi*fo)= %0.2e"%(T_r),"s"#resonant Time-Constant for 'fo'
print "for proper operation T_bias >> T_r"

# in part (ii)... value calculated for series resonant frequecy 'fo' is wrong in textbook.
# NOTE: in part(iii)... there is a misprint in the calculated value of Quality factor 'Q' in the textbook.
#I have used T_r instead of 1/wo (given in the book)

gm = 0.01  A/V
rd= 50000.00  ohm
RG= 1.00e+07  ohm
Rse= 1.00e+03  ohm
L= 0.50  H
part(i)