import math
A_ol=100000.0; #open loop voltage gain
A_cm=0.2; #common mode gain
CMRR=A_ol/A_cm;
CMRR_dB=20*math.log10(CMRR);
print('CMRR = %d'%CMRR)
print('CMRR in decibels = %f'%CMRR_dB)
del_t=1.0; # in microseconds
#lower limit is -9V and upper limit is 9V from the graph
del_V_out=9.0-(-9.0);
slew_rate=del_V_out/del_t;
print('slew rate =%d V/microseconds'%slew_rate)
R_f=100*10**3;
R_i=4.7*10**3;
A_cl_NI=1+(R_f/R_i);
print('closed loop voltage gain = %f'%A_cl_NI)
R_i=2.2*10**3;
A_cl=-100.0; #closed loop voltage gain
R_f=abs(A_cl)*R_i;
print('value of R_f = %d ohms'%R_f)
Z_in=2*10**6;
Z_out=75.0;
A_ol=200000.0;
R_f=220.0*10**3;
R_i=10.0*10**3;
B=R_i/(R_i+R_f); #B is attenuation
Z_in_NI=(1+A_ol*B)*Z_in;
Z_out_NI=Z_out/(1+A_ol*B);
A_cl_NI=1+(R_f/R_i);
Z_in_NI=Z_in_NI/10**10
print('input impedance = %f * 10^10 ohms'%Z_in_NI)
print('output impedance = %f ohms'%Z_out_NI)
print('closed loop voltage gain = %d'%A_cl_NI)
B=1.0; #voltage follower configuration
A_ol=200000.0;
Z_in=2*10**6;
Z_out=75.0;
Z_in_VF=(1+A_ol)*Z_in;
Z_out_VF=Z_out/(1+A_ol);
Z_in_VF=Z_in_VF*10**-11
print('input impedance = %d * 10^11 Ohms'%Z_in_VF)
print('output impedance = %f Ohms'%Z_out_VF)
R_i=1.0*10**3;
R_f=100.0*10**3;
Z_in=4.0*10**6;
Z_out=50.0;
A_ol=50000.0;
B=R_i/(R_i+R_f); #attenuation
Z_in_I=R_i; #almost equal to R_i
Z_out_I=Z_out/(1+(A_ol*B));
A_cl_I=-R_f/R_i;
print('input impedance = %d Ohms'%Z_in_I)
print('output impedance = %f Ohms'%Z_out_I)
print('closed loop voltage gain =%d'%A_cl_I)
import math
f_c_ol=100.0;
A_ol_mid=100000.0;
f=0.0;
A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))
print('open loop gain when f=0Hz is %f'%A_ol);
f=10.0;
A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))
print('open loop gain when f=10Hz is %f'%A_ol)
f=100.0;
A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))
print('open loop gain when f=100Hz is %f'%A_ol)
f=1000.0;
A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))
print('open loop gain when f=1000Hz is %f'%A_ol)
import math
f_c=100.0;
f=1.0;
theta_rad=-math.atan((f/f_c))
theta=theta_rad*180/math.pi;
print('phase lag when f=1Hz = %f degrees'%theta)
f=10.0;
theta_rad=-math.atan((f/f_c))
theta=theta_rad*180/math.pi;
print('phase lag when f=10Hz = %f degrees'%theta)
f=100.0;
theta_rad=-math.atan((f/f_c))
theta=theta_rad*180/math.pi;
print('phase lag when f=100Hz = %f degrees'%theta)
f=1000.0;
theta_rad=-math.atan((f/f_c))
theta=theta_rad*180/math.pi;
print('phase lag when f=1000Hz = %f degrees'%theta)
f=10000.0;
theta_rad=-math.atan((f/f_c))
theta=theta_rad*180/math.pi;
print('phase lag when f=10000Hz = %f degrees'%theta)
import math
A_v1=40.0; #all gains are in decibels
A_v2=32.0;
A_v3=20.0;
f_c1=2*10**3;
f_c2=40*10**3;
f_c3=150*10**3;
f=f_c1;
A_ol_mid=A_v1+A_v2+A_v3;
#theta 1
theta_rad1=-math.atan((f/f_c1))
theta1=theta_rad1*180/math.pi;
#theta 2
theta_rad2=-math.atan((f/f_c2))
theta2=theta_rad2*180/math.pi;
#theta 3
theta_rad3=-math.atan((f/f_c3))
theta3=theta_rad3*180/math.pi;
theta_tot=theta1+theta2+theta3;
print('open loop midrange gain in decibels is %d'%A_ol_mid)
print('total phase lag in degrees is %d'%theta_tot)
A_ol_mid=150000.0; #open loop midrange gain
B=0.002; #feedback attenuation
BW_ol=200; #open loop bandwidth
BW_cl=BW_ol*(1+B*A_ol_mid);
print('closed loop bandwidth = %d Hz'%BW_cl)
BW=3*10**6; #unity gain bandwidth
A_ol=100.0; #open loop gain
print("non-inverting amplifier")
R_f=220.0*10**3;
R_i=3.3*10**3;
A_cl=1+(R_f/R_i); #closed loop gain
BW_cl=BW/A_cl;
print('closed loop bandwidth = %f Hz'%BW_cl)
print("inverting amplifier")
R_f=47.0*10**3;
R_i=1.0*10**3;
A_cl=-R_f/R_i;
BW_cl=BW/(abs(A_cl));
print('closed loop bandwidth = %f Hz'%BW_cl)