#Express the gain in decibel
#given
#Powere gain of 1000
import math
Pg1=1000.;
Pgd1=10.*math.log10(Pg1);
print '%s %.f %s' %("Power gain (in dB)=",Pgd1,"dB\n");
#Voltage gain of 1000
Vg1=1000.;
Vgd1=20.*math.log10(Vg1);
print '%s %.f %s' %("Voltage gain (in dB)=",Vgd1,"dB\n");
#Powere gain of 1/100
Pg2=1./100.;
Pgd2=10.*math.log10(Pg2);
print '%s %.f %s' %("Power gain (in dB)=",Pgd2,"dB\n");
#Voltage gain of 1/100
Vg2=1./100.;
Vgd2=20.*math.log10(Vg2);
print '%s %.f %s' %("Voltage gain (in dB)=",Vgd2,"dB\n");
#Determine power and voltage gain
#given
#For Gain = 10 dB
G=10.;#dB
Pg1=10.**(G/10.); #taking antilog
Vg1=10.**(G/20.); #taking antilog
print '%s %.f %s' %("For Gain",G,"dB\n")
print '%s %.f %s' %("Power gain ratio =",Pg1,"\n");
print '%s %.2f %s' %("Voltage gain ratio =",Vg1,"\n");
#For Gain 3 dB
G=3.;#dB
Pg2=10.**(G/10.); #taking antilog
Vg2=10.**(G/20.); #taking antilog
print '%s %.f %s' %("For Gain",G,"dB\n")
print '%s %.2f %s' %("Power gain ratio =",Pg2,"\n");
print '%s %.3f %s' %("Voltage gain ratio =",Vg2,"\n");
#Calculate the overall voltage gain
#given
import math
A1=80.
A2=50.
A3=30.
Ad=20.*math.log10(A1)+20.*math.log10(A2)+20.*math.log10(A3);
#Alternatively
A=A1*A2*A3;
Ad=20.*math.log10(A);
print '%s %.2f %s' %("The Voltage gain is =",Ad,"dB");
#Calculate quiescent output voltage and small signal voltage gain
#given
#At input Voltage =3V
Vi1=3.##V #input voltage
Vbe=0.7##V
B=250.#
Vcc=10.##V #Supply
Re1=1.*10.**3.##ohm
Rc1=3.*10.**3.##ohm
Re2=2.*10.**3.##ohm
Rc2=4.*10.**3.##ohm
Vb1=Vi1# #Voltage at the base of transistor T1
Ve1=Vb1-Vbe# #Voltage at the emitter of transistor T1
Ie1=Ve1/Re1#
Ic1=Ie1#
Vc1=Vcc-Ic1*Rc1#
Vb2=Vc1#
Ve2=Vb2-Vbe#
Ie2=Ve2/Re2#
Ic2=Ie2#
Vo1=Vcc-Ic2*Rc2#
print '%s %.1f %s' %("The quiescent output voltage(At input Voltage = 3V) is =",Vo1,"V\n")#
#At input Voltage =3.2 V
Vi2=3.2##V #input voltage
Vb1=Vi2# #Voltage at the base of transistor T1
Ve1=Vb1-Vbe# #Voltage at the emitter of transistor T1
Ie1=Ve1/Re1#
Ic1=Ie1#
Vc1=Vcc-Ic1*Rc1#
Vb2=Vc1#
Ve2=Vb2-Vbe#
Ie2=Ve2/Re2#
Ic2=Ie2#
Vo2=Vcc-Ic2*Rc2#
print '%s %.1f %s' %("The quiescent output voltage (At input Voltage =3.2 V) is =",Vo2,"V\n")#
#Small Signal input and output voltage
vi=Vi2-Vi1#
vo=Vo2-Vo1#
Av=vo/vi#
print '%s %.f' %("The small signal voltage gain is =",Av)
#Calculate the maximum voltage gain and bandwidth of multistage amplifier
#FUNCTIONS
#given
def prll(r1,r2):
z=r1*r2/(r1+r2)#
return z
import math
rin=10.*10.**6.;#ohm #input resistance of JFET
Rd=10.*10.**3.;#ohm
Rs=500.;#ohm
Rg=470.*10.**3.;#ohm
Rl=470.*10.**3.;#ohm
Cc=0.01*10.**-6.;#Farad
Csh=100.*10.**-12.;#Farad
Cs=50.*10.**-6.;#Farad
rd=100.*10.**3.;#ohm
gm=2.*10.**-3.;#S
Rac2=prll(Rd,Rl);
Rac1=prll(Rd,Rg);
Req=prll(rd,prll(Rd,Rl));
Am=math.ceil(gm*Req);
Am2=Am*Am; #Voltage gain of two stage amplifier
print '%s %.f %s' %("Voltage gain of two stage amplifier=",Am2,"\n");
R_=prll(rd,Rd)+prll(Rg,rin);
f1=1./(2.*math.pi*Cc*R_); #lower cutoff frequency
f1_=f1/(math.sqrt(math.sqrt(2.)-1.));
f2=1./(2.*math.pi*Csh*Req); #upper cutoff frequency
f2_=f2*(math.sqrt(math.sqrt(2.)-1.));
BW=f2_-f1_;
print '%s %.f %s' %("Bandwidth=",BW/1000.,"kHz\n");
#There is a slight error in f1 due to use of R'(here R_)=479 kohm and in f2 due to approaximation of Req there is a slight variation
#Calculate the midband voltage gain and bandwidth of cascade amplifier
#given
import math
Am=8.##midband voltage gain of individual MOSFET
BW=500.*10.**3.#Hz
f2=BW#
n=4.#
A2m=Am**n#
f2_=f2*(math.sqrt((2.**(1./n))-1.))#
print '%s %.f %s' %("Midband voltage gain =",A2m,"\n")#
print '%s %.1f %s' %("Overall Bandwidth =",f2_/1000,"kHz")#
#Calculate the input and output impedance and voltage gain
#FUNCTIONS
def prll(r1,r2):
z=r1*r2/(r1+r2)#
return z
import math
hie=1.1*10.**3.;#ohm=rin
hfe=120.;#=B
#the values of Rac2, Zi, Zo are as per diagram
Rac2=prll(3.3*10**3,2.2*10**3);
Rac1=prll(6.8*10**3,prll(56*10**3,prll(5.6*10**3,1.1*10**3)));
Zi=prll(5.6*10**3,prll(56*10**3,1.1*10**3));
Zo=prll(3.3*10**3,2.2*10**3);
print '%s %.3f %s %s %.2f %s' %("Input Resistance =",Zi/1000,"kohm\n","\nOutput Resistance =",Zo/1000,"kohm");
Am2=-hfe*Rac2/(hie);
Am1=-hfe*Rac1/(hie);
Am=Am1*Am2;
Am=20.*math.log10(Am);
print '%s %.2f %s' %("\nThe Overall Voltage gain is",Am,"dB");