import math
##Example 11.1
V1=10.;
V2=-10.;
Iq=1.;
Rc=10.;
Vbe=0.7;
iC1=Iq/2.;
iC2=iC1;
print"%s %.2f %s"%('\ncollector currents = ',iC1,'mA\n')
Vc1=V1-iC1*Rc;
Vc2=Vc1;
print"%s %.2f %s"%('\ncollector voltages = ',Vc1,'V\n')
Vcm=0.;
Ve=Vcm-Vbe;
Vce1=Vc1-Ve;
print"%s %.2f %s"%('\ncollector emitter voltage= ',Vce1,' V\n')
Vcm=-5.;
Ve=Vcm-Vbe;
Vce1=Vc1-Ve;
print"%s %.2f %s"%('\ncollector emitter voltage = ',Vce1,'V\n')
Vcm=5.;
Ve=Vcm-Vbe;
Vce1=Vc1-Ve;
print"%s %.2f %s"%('\ncollector emitter voltage= ',Vce1,' V\n')
import math
##Example 11.3
V1=10.;
V2=-10.;
Iq=0.8*10**-3;
Rc=12000.;
Ro=25000.;
b=100.;
Vt=0.026;
Ad=Iq*Rc/(4.*Vt);
print"%s %.2f %s"%('\ndifferential gain=\n',Ad,'')
Acm=-(Iq*Rc/(2.*Vt))/(1.+(1.+b)*Iq*Ro/(Vt*b));
print"%s %.2f %s"%('\ncommon mode gain=\n',Acm,'')
import math
##Example 11.7
Ad=92.3;
Acm=0.237;##mod of Acm
CMRR=Ad/Acm;
print"%s %.2f %s"%('\ncommon mode rejection ratio=\n',CMRR,'')
CMRRdB=20.*math.log10(CMRR);
print"%s %.2f %s"%('\nCMRR in decibels= ',CMRRdB,' dB\n')
import math
##Example 11.8
CMRRdB=90.;##dB
CMRR=3.16*10**4;
b=100.;
Vt=0.026;
Iq=0.8;
Ro=(2.*CMRR-1.)*Vt*b/((1.+b)*Iq);
Ro=Ro*10**-3;##Mohm
print round(Ro,2)
import math
##Example 11.9
b=100.;
Vbe=0.7;
Va=100.;
Vt=0.026;
Iref=0.5;
Iq=Iref;
I1=Iq/2.
Icq=I1;
r=b*Vt/Icq;
print"%s %.2f %s"%('\nsmall signal parameter= ',r,' KOhm\n')
ro=Va/Icq;
print"%s %.2f %s"%('\nro= ',ro,' KOhm\n')
Ro=Va/Iq;
print"%s %.2f %s"%('\noutput resistance of Q4= ',Ro,' KOhm\n')
Rid=2.*r;
print"%s %.2f %s"%('\ndifferential mode input resistance = ',Rid,'KOhm\n')
Ricm=(1.+b)*(Ro*ro/2.)/(Ro+ro/2.);
Ricm=Ricm*0.001;##Mohm
print"%s %.2f %s"%('\ncommon mode input resistance= ',Ricm,' MOhm\n')
import math
import numpy
from numpy import poly
##Example 11.10
Kn1=0.1;
Kn2=Kn1;
Kn3=0.1;
Kn4=Kn3;
R1=30.;
Vtn=1.;
Rd=16.;
Vgs4=2.40;
I1=(20.-Vgs4)/R1;
print"%s %.2f %s"%('\nI1= ',I1,' mA\n')
Iq=I1;
Id1=Iq/2.;
print"%s %.2f %s"%('\nId1 and Id2 = ',Id1, 'mA\n')
Vgs1=math.sqrt(Id1/Kn1)+Vtn;
print"%s %.2f %s"%('\nVgs1 and Vgs2 = ',Vgs1,'V\n')
vo1=10.-Id1*Rd;
print"%s %.2f %s"%('\nvo1 and vo2= ',vo1,' V\n')
Vds1=Vgs1-Vtn;
print"%s %.2f %s"%('\nVds1=Vds2=Vds1(sat)= ',Vds1,' V\n')
Vcm=vo1-Vds1+Vgs1;
print"%s %.2f %s"%('\nVcm max= ',Vcm,' V\n')
Vds4=Vgs4-Vtn;
print"%s %.2f %s"%('\nVds4= ',Vds4,' V\n')
Vcm2=Vgs1+Vds4-10.;
print"%s %.2f %s"%('\nVcm min= ',Vcm2,'V\n')
import math
##Example 11.11
Kn=0.5;
Iq=1.;
Vt=0.026;
##transconductance of the MOSFET
gm=2.*math.sqrt(Kn*Iq/2);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
##transconductance of the bipolar transistor
gm=Iq/(2.*Vt);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
import math
##Example 11.12
Iq=0.587;
Kn=1.;
Rd=16.;
##lambda=y
y=0.01;
Ro=1./(y*Iq);
print"%s %.2f %s"%('\noutput resistance = ',Ro,'KOhm\n')
Ad=math.sqrt(Kn*Iq/2.)*Rd;
print"%s %.2f %s"%('\ndifferential mode voltage gain= \n',Ad,'')
Acm=-math.sqrt(2.*Kn*Iq)*Rd/(1.+2.*math.sqrt(2.*Kn*Iq)*Ro);
print"%s %.2f %s"%('\ncommon mode voltage gain=\n',Acm,'')
CMRR=20.*math.log10(-Ad/Acm);
print"%s %.2f %s"%('\ncommon mode rejection ratio= ',CMRR,' dB\n')
import math
##Example 11.13
Iq=0.2;
Va=100.;
Va2=Va;
Va4=Va;
Rl=100.;
Vt=0.026;
Ad=(1./Vt)/(1./Va2+1./Va4);
print"%s %.2f %s"%('\nopen circuit voltage gain=\n',Ad,'')
Ad=(Iq/(2.*Vt))/(Iq/(2.*Va2)+Iq/(2.*Va4)+1./Rl);
print"%s %.2f %s"%('\nvoltage gain=\n',Ad,'')
import math
##Example 11.15
Kn=0.2;
Idq=0.1;
ro4=1000.;##Kohm
ro6=1000.;##KOhm
ro2=ro4;
##lambda=y
y=0.01;
gm=2.*math.sqrt(Kn*Idq);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
ro=1./(y*Idq);
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Ro=ro4+ro6*(1.+gm*ro);
Ro=Ro*0.001;##Mohm
print"%s %.2f %s"%('\noutput resistance of the cascode active load= ',Ro,'Mohm\n')
Ro=Ro*1000.;##KOhm
Ad=gm*ro2*Ro/(ro4+Ro);
print"%s %.2f %s"%('\ndifferential mode voltage gain=\n',Ad,'')
import math
##Example 11.16
Iq=0.2;
Ic1=Iq;
Icb=1.;
R4=10.;
R3=0.2;
b=100.;
Va=100.;
Vt=0.026;
Ri=2.*(1.+b)*b*Vt/Iq;
Ri=Ri*0.001;##MOhm
print"%s %.2f %s"%('\ninput resistance= ',Ri,' MOhm\n')
R11=b*Vt/Iq;
print"%s %.2f %s"%('\nresistance R11= ',R11,' KOhm\n')
Re=R11*R3/(R11+R3);
print"%s %.2f %s"%('\nRe= ',Re,' KOhm\n')
gm11=Iq/Vt;
print"%s %.2f %s"%('\ngm11= ',gm11,' mA/V\n')
ro11=Va/Iq;
print"%s %.2f %s"%('\nro11 = ',ro11,'KOhm\n')
Rc11=ro11*(1+gm11*Re);
Rc11=Rc11*0.001;##MOhm
print"%s %.2f %s"%('\nRc11= ',Rc11,' MOhm\n')
r8=b*Vt/Icb;
print"%s %.2f %s"%('\nresistance= ',r8,'KOhm\n')
##answer of following given in the book is wrong
Rb8=r8+(1.+b)*R4;
Rb8=Rb8*0.001;##MOhm
print"%s %.2f %s"%('\nRb8 = ',Rb8,'MOhm\n')
Rl7=Rc11*Rb8/(Rc11+Rb8);
print"%s %.2f %s"%('\nRl7= ',Rl7,' MOhm\n')
Av=Iq*Rl7/(2.*Vt);
print"%s %.2f %s"%('\nsmall signal voltage gain=\n',Av,'')
import math
##Example 11.17
Va=100.;
R4=10.;
b=100.;
Rc11=1.26*10**3;
r8=2.6;
Iq=0.2;
Rc7=Va/Iq;
print"%s %.2f %s"%('\nRc7= ',Rc7,' KOhm\n')
Z=Rc11*Rc7/(Rc11+Rc7);
print"%s %.2f %s"%('\nZ= ',Z,' KOhm\n')
x=(r8+Z)/(1.+b);
Ro=R4*x/(R4+x);
print"%s %.2f %s"%('\noutput resistance= ',Ro,' KOhm\n')
import math
##Example 11.19
b=100.;
Vt=0.026;
Rc=20.;
Ir4=0.4;
Iq=Ir4;
Ir6=Ir4;
r4=b*Vt/Ir4;
print"%s %.2f %s"%('\nr4= ',r4,' KOhm\n')
r3=b**2*Vt/Ir4;
print"%s %.2f %s"%('\nr3= ',r3,' KOhm\n')
Ri2=r3+(1.+b)*r4;
print"%s %.2f %s"%('\ninput resistance= ',Ri2,' KOhm\n')
gm=Iq/(2.*Vt);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
Ad1=gm*Rc*Ri2/(2.*(Rc+Ri2));
print"%s %.2f %s"%('\ngain of differential amplifier stage=\n',Ad1,'')
r5=b*Vt/Ir6;
print"%s %.2f %s"%('\nr5 = ',r5,'KOhm\n')
Ir7=2.;
r6=b*Vt/Ir7;
print"%s %.2f %s"%('\nr6= ',r6,' KOhm\n')
R6=16.5;
R7=5.;
Ri3=r5+(1.+b)*(R6+r6+(1.+b)*R7);
Ri3=Ri3*0.001;##MOhm
print"%s %.2f %s"%('\nRi3= ',Ri3,' MOhm\n')
Rs=5.;
A2=Ir4*Rs/(2.*Vt);
print"%s %.2f %s"%('\nvoltage gain A2=\n',A2,'')
A3=1.;##vo/vo3
Ad=Ad1*A2*A3;
print"%s %.2f %s"%('\nsmall signal voltage gain=\n',Ad,'')
import math
##Example 11.20
Ro=10000000.;
Co=1.*10**-12;
Rb=500.;
r=10000.;
b=100.;
f=1./(2.*math.pi*Ro*Co);
f=f*0.001;##KHz
print"%s %.2f %s"%('\nfrequency of the zero= ',f,' KHz\n')
Req=Ro*(1.+Rb/r)/(1.+Rb/r+2.*(1.+b)*Ro/r);
print"%s %.2f %s"%('\nReq= ',Req,' Ohm\n')
f=1/(2.*math.pi*Req*Co);
f=f*10**-9;##GHz
print"%s %.2f %s"%('\nfrequency of the pole= ',f,' GHz\n')