#Example 5.1
#The 741C is connected as a noniverting amplifier.What maximum gain can be used
#that will still keep the amplifier's response flat to 10kHz.
%matplotlib inline
from scipy import pi
import numpy as np
from matplotlib.pyplot import ylabel, xlabel, title, plot, show, clf, subplot, semilogx, savefig
import matplotlib.pyplot as plt
#Variable declaration
f=np.arange(0,1000000) #frequency range
s=2.0j*pi*f
A=200000 #Gain of opamp at 0 Hz
f0=5 #first break frequency in Hz
p=2.0*pi*f0
#Calculation
tf=A*p/(s+p) #open loop gain
#Magnitude plot
clf() #clear the figure
subplot(211)
title('tf=p/(s+p)')
semilogx(f,20*log10(abs(tf)))
ylabel('Mag. Ratio (dB)')
#Phase plot
subplot(212)
semilogx(f,arctan2(imag(tf),real(tf))*180.0/pi)
plt.ylabel('Phase (deg.)')
plt.xlabel('Freq (Hz)')
plt.show()
savefig('fig1.png') #savefig('fig1.eps')
Amax=40 #from the graph
#Result
print "Maximum gain is",Amax,"dB"
#Example 5.2
#Using the frequency response and phase response curves obtained in figure 5-5
#Obtain the equation for the MC1556 opamp. Also determine the approximate values
#of the break frequencies.
from __future__ import division #to perform decimal division
import math
#Variable declaration
phase=-157.5 #Phase shift at about 3 MHz
f=3*10**6
fo1=6 #first break frequency,from the graph
A=140000 #Gain of the opamp at 0Hz
#calculation
k=-math.atan(f/fo1)*180/math.pi-phase
fo2=f/math.tan(k*math.pi/180) #second break frequency
#result
print "Gain equation is Aol(f)=A((1+(f/fo1)*j)*(1+(f/fo2)*j)"
print "A,the gain of the opamp at 0 Hz is",A
print "First break frequency fo1 is",fo1,"Hz"
print "Second break frequency fo2 is",round(fo2/10**6,2),"MHz"
#Example 5.3
#Determine the stability of the voltage follower shown in figure 3-7.
#Assume that the opamp is a 741 IC
%matplotlib inline
from scipy import pi
import numpy as np
from matplotlib.pyplot import ylabel, xlabel, title, plot, show, clf, subplot, semilogx, savefig
import matplotlib.pyplot as plt
#Variable declaration
f=arange(10,1000000)
s=2.0j*pi*f
A=200000
f0=5
p=2.0*pi*f0
B=1 #For voltage follower B=1
#Calculation
tf=A*p*B/(s+p) #open loop gain
#Magnitude plot
clf() #clear the figure
subplot(211)
title('tf=p/(s+p)')
semilogx(f,20*log10(abs(tf)))
ylabel('Mag. Ratio (dB)')
#Phase plot
subplot(212)
semilogx(f,arctan2(imag(tf),real(tf))*180.0/pi)
ylabel('Phase (deg.)')
xlabel('Freq (Hz)')
show()
savefig('fig1.png') #savefig('fig1.eps')
#Result
print "From the plot it is seen that phase angle is -90 degree"
print "when the magnitude is o dB.Since the phase angle reaches >-180"
print "when the magnitude is 0dB, voltage follower is stable at 0dB"