%matplotlib inline
# result
print "theoretical example"
# variable declaration
I_E=2.0*10**-3; #emittor current
#calculation
r_e=25.0*10**-3/I_E; #ac emitter resistance
#result
print "ac emitter resistance = %.2f ohms" %r_e
# variable declaration
I_E=3.8*10**-3; #emittor current
B_ac=160.0; #AC value
R1=22*10**3; #resistance in ohm
R2=6.8*10**3; #resistance in ohm
R_s=300.0; #resistance in ohm
V_s=10.0*10**-3; #voltage in volt
r_e=25.0*10**-3/I_E;
#calculation
R_in_base=B_ac*r_e; #base resistance
R_in_tot=(R1*R2*R_in_base)/(R_in_base*R1+R_in_base*R2+R1*R2);
V_b=(R_in_tot/(R_in_tot+R_s))*V_s; #base voltage
#result
print "voltage at the base of the transistor = %.3f volts" %V_b
import math
# variable declaration
R_E=560.0; #resistance in ohm
f=2*10**3; #minimum value of frequency in hertz
X_C=R_E/10.0; #minimum value of capacitive reactance
#calculation
C2=1.0/(2.0*math.pi*X_C*f); #capacitor
#result
print "value of bypass capacitor = %.7f farads" %C2
import math
# variable declaration
r_e=6.58; #from ex6.3
R_C=1.0*10**3; #collector resistance
R_E=560; #emittor resistance
#calculation
A_v=R_C/(R_E+r_e); #gain without bypass capacitor
A_v1=R_C/r_e; #gain with bypass capacitor
print "gain without bypass capacitor = %.2f" %A_v
print "gain in the presence of bypass capacitor = %.2f" %A_v1
# variable declaration
R_C=10.0**3; #resistance in ohm
R_L=5.0*10**3; #inductor resistance
r_e=6.58; #r_e value
#calculation
R_c=(R_C*R_L)/(R_C+R_L); #collector resistor
A_v=R_c/r_e; #gain with load
#result
print "ac collector resistor = %.2f ohms" %R_c
print "gain with load = %.2f" %A_v
# variable declaration
R_C=3.3*10**3; #resistance in ohm
R_E1=330.0; #emitter resistance
#calculation
A_v=R_C/R_E1; #voltage gain
#result
print "approximate voltage gain as R_E2 is bypassed by C2 = %.2f" %A_v
import math
B_DC=150.0;
B_ac=175.0;
V_CC=10.0;
V_s=10.0*10**-3;
R_s=600.0;
R1=47.0*10**3;
R2=10.0*10**3;
R_E1=470.0;
R_E2=470.0;
R_C=4.7*10**3;
R_L=47.00*10**3;
R_IN_base=B_DC*(R_E1+R_E2);
#since R_IN_base is ten times more than R2,it can be neglected in DC voltage calculation
V_B=(R2/(R2+R1))*V_CC;
V_E=V_B-0.7;
I_E=V_E/(R_E1+R_E2);
I_C=I_E;
V_C=V_CC-I_C*R_C;
print('dc collector voltage = %.3f volts'%V_C)
r_e=25.0*10**-3/I_E;
#base resistance
R_in_base=B_ac*(r_e+R_E1);
#total input resistance
R_in_tot=(R1*R2*R_in_base)/(R1*R2+R_in_base*R1+R_in_base*R2);
attenuation=R_in_tot/(R_s+R_in_tot);
#ac collector resistance
R_c=R_C*R_L/(R_C+R_L);
#voltage gain from base to collector
A_v=R_c/R_E1;
#overall voltage gain A_V
A_V=A_v*attenuation;
#rms voltage at collector V_c
V_c=A_V*V_s;
V_out_p=math.sqrt(2)*V_c;
print('V_out peak = %d mV'%(V_out_p*1000))
################Waveform plotting##############################
import pylab
import numpy
t = arange(0.0, 4.0, 0.0005)
subplot(121)
plot(t, V_C+V_c*sin(2*pi*t))
ylim( (4.63,4.82) )
title('Collector Voltage')
subplot(122)
plot(t, -V_s*sin(2*pi*t))
plot(t, V_out_p*sin(2*pi*t))
ylim( (-0.15,0.15) )
title('Source and output AC voltage')
# variable declaration
R_E=10.0**3; #emitter resistance
R_L=10.0**3; #resistance in ohm
R1=18.0*10**3; #R1 in ohm
R2=18.0*10**3; #R2 in ohm
B_ac=175.0; #AC value
V_CC=10.0; #voltage in volt
V_BE=0.7; #base-emitter voltage
V_in=1.0; #input voltage in volt
#calculation
R_e=(R_E*R_L)/(R_E+R_L); #ac emitter resistance R_e
R_in_base=B_ac*R_e; #resistance from base R_in_base
#total input resiatance R_in_tot
R_in_tot=(R1*R2*R_in_base)/(R1*R2+R1*R_in_base+R2*R_in_base);
print "total input resistance = %.2f ohms" %R_in_tot
V_E=((R2/(R1+R2))*V_CC)-V_BE; #emitter voltage
I_E=V_E/R_E; #emitter current
r_e=25.0*10**-3/I_E; #emitter resistance
A_v=R_e/(r_e+R_e);
print "voltage gain = %.2f" %A_v
#ac emitter current I_e
#V_e=A_v*V_b=1V
V_e=1.0; #V_evoltage
I_e=V_e/R_e; #emitter current
I_in=V_in/R_in_tot; #input current in ampere
A_i=I_e/I_in; #current gain
print "current gain = %.2f" %A_i
A_p=A_i; #power gain
#since R_L=R_E, one half of the total power is disspated to R_L
A_p_load=A_p/2.0; #power load
print "power gain delivered to load = %.2f" %A_p_load
# variable declaration
V_CC=12.0; #source voltage in volt
V_BE=0.7; #base-emitter volatge
R_C=1.0*10**3; #resistance in ohm
r_e_ce=5.0; #for common emitter amplifier
R1=10.0*10**3; #resistance in ohm
R2=22.0*10**3; #resistance in ohm
R_E=22.0; #emitter resistance in ohm
R_L=8.0; #load resistance in ohm
B_DC=100.0; #dc value
B_ac=100.0; #ac value
#calculation
pt=R2+B_DC**2*R_E #temp variable
V_B=((R2*B_DC**2*R_E/(pt))/(R1+(R2*B_DC**2*R_E/(pt))))*V_CC;
V_E=V_B-2.0*V_BE; #emitter voltage
I_E=V_E/R_E; #emitter current
r_e=25.0*10**-3/I_E; #for darlington emitter-follower
P_R_E=I_E**2*R_E; #power dissipated by R_E
P_Q2=(V_CC-V_E)*I_E #power dissipated by transistor Q2
R_e=R_E*R_L/(R_E+R_L); #ac emitter resi. of darlington emitter follower
#total input resistance of darlington
kt=R_e+r_e #temp varaible
R_in_tot=R1*R2*B_ac**2*(kt)/(R1*R2+R1*B_ac**2*(kt)+R2*B_ac**2*(kt));
R_c=R_C*R_in_tot/(R_C+R_in_tot); #effective ac resistance
A_v_CE=R_c/r_e_ce; #voltage gain of common emitter
A_v_EF=R_e/(r_e+R_e); #voltage gain of common emitter amplifier
A_v=A_v_CE*A_v_EF; #overall voltage gain
#result
print "voltage gain of common emitter amplifier= %.2f" %A_v_CE
print "voltage gain of common emitter amplifier= %.2f" %A_v_EF
print "overall voltage gain = %.2f" %A_v
# variable declaration
B_DC=250.0; #dc value
R_C=2.2*10**3; #resistance in ohm
R_E=1.0*10**3; #emitter resistance
R_L=10.0*10**3;#load resistance
R1=56.0*10**3; #resistance in ohm
R2=12.0*10**3; #resistance in ohm
V_BE=0.7; #base-emitter voltage in volt
V_CC=10.0; #source voltage in volt
#calculation
#since B_DC*R_E>>R2
V_B=(R2/(R1+R2))*V_CC;
V_E=V_B-V_BE; #emiiter voltage
I_E=V_E/R_E; #emitter current
r_e=25.0*10**-3/I_E; #r_e value
R_in=r_e; #input resistance
R_c=R_C*R_L/(R_C+R_L); #ac collector resistance
A_v=R_c/r_e; #current gain
#current gain is almost 1
#power gain is approximately equal to voltage gain
A_p=A_v; #power gain
A_i=1; #current gain
#result
print "input resistance = %.2f ohms" %R_in
print "voltage gain = %.2f" %A_v
print "current gain = %.2f" %A_i
print "power gain = %.2f" %A_p
import math
# variable declaration
A_v1=10.0;
A_v2=15.0;
A_v3=20.0;
#calcultion
A_v=A_v1*A_v2*A_v3; #overall voltage gain
A_v1_dB=20.0*math.log10(A_v1); #gain in decibel
A_v2_dB=20.0*math.log10(A_v2); #gain in decibel
A_v3_dB=20.0*math.log10(A_v3); #gain in decibel
A_v_dB=A_v1_dB+A_v2_dB+A_v3_dB; #total gain in decibel
#result
print "overall voltage gain = %.1f" %A_v
print "Av1 = %.1f dB" %A_v1_dB
print "Av2 = %.1f dB" %A_v2_dB
print "Av3 = %.1f dB" %A_v3_dB
print "total voltage gain =%.1f dB" %A_v_dB