import math
##Example 6.1
Vtn=1.;
##let x= u_n*Cox*1/2
x=20.*10**-3;
##let y=W/L
y=40.;
I_D=1.;
Kn=x*y;
print"%s %.2f %s"%('\nconduction parameter= ',Kn,' mA/V^2\n')
g_m=2.*math.sqrt(Kn*I_D);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
import math
##Example 6.2
Vgsq=2.12;
Vdd=5.;
Rd=2.5;
Vtn=1.;
Kn=0.8;
##let lambda=y
y=0.02;##V^-1
Idq=Kn*(Vgsq-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',Idq,'mA\n')
Vdsq=Vdd-Idq*Rd;
print"%s %.2f %s"%('\ndrain to source voltage= ',Vdsq,' V\n')
Vgs=1.82;
Vgs-Vtn
##since Vdsq>Vgs-Vtn transistor is biased in saturation
g_m=2.*Kn*(Vgsq-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
ro=(y*Idq)**-1;
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Av=-g_m*ro*Rd/(ro+Rd);
print"%s %.2f %s"%('\nsmall signal voltage gain= ',Av,'\n')
import math
##Example 6.3
Vdd=10.;
R1=70.9;##(Kohm)
R2=29.1;##(Kohm)
Rd=5.;##(Kohm)
Vtn=1.5;
Kn=0.5;##(mA/V^2)
##lambda=y
y=0.01;##V^-1
Rsi=4.;##(Kohm)
Vgsq=Vdd*R2/(R1+R2);
print"%s %.2f %s"%('\ngate to source voltage= ',Vgsq,' V\n')
Idq=Kn*(Vgsq-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',Idq,' mA\n')
Vdsq=Vdd-Idq*Rd;
print"%s %.2f %s"%('\ndrain to source voltage= ',Vdsq,' V\n')
g_m=2*Kn*(Vgsq-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
ro=(y*Idq)**-1;
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Ri=R1*R2/(R1+R2);
print"%s %.2f %s"%('\namplifier input resistance= ',Ri,' Kohm\n')
Av=-g_m*(ro*Rd/(ro+Rd))*Ri/(Ri+Rsi);
print"%s %.2f %s"%('\nsmall signal voltage gain=\n',Av,'')
print"%s %.2f %s"%('\namplifier input resistance= ',Ri,' Kohm\n')
Ro=Rd*ro/(Rd+ro);
print"%s %.2f %s"%('\namplifier output resistance= ',Ro,' Kohm\n')
import math
##Example 6.4
Vtn=1.;
Kn=1.;##(mA/V^2)
##lambda=y
y=0.015;##V^-1
Ri=100.;##(Kohm)
Idq=2.;##(mA)
Idt=4.;##(mA)
##Idt=4=Kn*(Vgst-Vtn)^2
Vgst=math.sqrt(Idt/Kn)+Vtn;
print"%s %.2f %s"%('\nVgst= ',Vgst,' V\n')
Vdst=Vgst-Vtn;
print"%s %.2f %s"%('\nVdst= ',Vdst,' V\n')
Vdd=12.;
Vdsq=7.;
Rd=(Vdd-Vdsq)/Idq;
print"%s %.2f %s"%('\nRd = ',Rd,'KOhm\n')
Vgsq=math.sqrt(Idq/Kn)+Vtn;
print"%s %.2f %s"%('\nVgsq= ',Vgsq,' V\n')
R1=Ri*Vdd/Vgsq;
print"%s %.2f %s"%('\nR1= ',R1,' Kohm\n')
R2=Ri*R1/(R1-Ri);
print"%s %.2f %s"%('\nR2= ',R2,' Kohm\n')
g_m=2*Kn*(Vgsq-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
ro=(y*Idq)**-1;
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Av=-g_m*(ro*Rd/(ro+Rd));
print"%s %.2f %s"%('\nsmall signal voltage gain= ',Av,'\n')
import math
##Example 6.6
Vtn=0.8;
Kn=1.;##(mA/V^2)
Idq=0.5;
Vdd=5.;
Rd=7.;##(Kohm)
Vgsq=math.sqrt(Idq/Kn)+Vtn;
print"%s %.2f %s"%('\nVgsq= ',Vgsq,' V\n')
Vs=-Vgsq
Vdsq=Vdd-Idq*Rd-Vs;
print"%s %.2f %s"%('\nVdsq=',Vdsq,' V\n')
g_m=2.*Kn*(Vgsq-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
Av=-g_m*Rd;
print"%s %.2f %s"%('\nsmall signal voltage gain=\n',Av,'')
import math
##Example 6.7
Vdd=12.;
R1=162.;
R2=463.;
Rs=0.75;
Kn=4.;
Vtn=1.5;
##lambda=y
y=0.01;
Rsi=4.;
Idq=7.97;
Vgsq=2.91;
g_m=2.*Kn*(Vgsq-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',g_m,' mA/V\n')
ro=(y*Idq)**-1.;
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Ri=R1*R2/(R1+R2);
print"%s %.2f %s"%('\namplifier input resistance= ',Ri,' Kohm\n')
x=Rs*ro/(Rs+ro);
Av=g_m*x*(Ri/(Ri+Rsi))/(1.+g_m*x);
print"%s %.2f %s"%('\nsmall signal voltage gain=\n',Av,'')
import math
##Example 6.9
Rs=750.;##Ohm
ro=12500.;
g_m=11.3*10**-3;
x=1./g_m;
y=x*Rs/(x+Rs);
Ro=y*ro/(y+ro);
print"%s %.2f %s"%('\noutput resistance= ',Ro,' ohm\n')
import math
##Example 6.11
Vtnd=1.;
Vtnl=1.;
Kn=30.;
##let W/L=x
xl=1.;
Vdd=5.;
Av=10.;
##Av=sqrt(xd/xl)
xd=(Av)**2*xl;
print"%s %.2f %s"%('\nwidth to length ratio of driver transistor=\n',xd,'')
Knd=xd*Kn*0.001/2.;
Knl=xl*Kn*0.001/2.;
print"%s %.2f %s"%('\nconduction parameter Knd= ',Knd,' mA/V^2\n')
print"%s %.2f %s"%('\nconduction parameter Knl= ',Knl,' mA/V^2\n')
##Vgsd-Vtnd=(Vdd-Vtnl)-sqrt(Knd/Knl)*(Vgsd-Vtnd)
y=math.sqrt(Knd/Knl);
Vgsd=(y+5.)/(1.+y);
print"%s %.2f %s"%('\nVgsd= ',Vgsd,' V\n')
Vdsd=Vgsd-1.;
print"%s %.2f %s"%('\nVdsd= ',Vdsd,' V\n')
import math
##Example 6.12
Vtnd=0.8;
Vtnl=-1.5;
Knd=1.;
Knl=0.2;
##lambda=y
yd=0.01;
yl=0.01;
Idq=0.2;
gmd=2.*math.sqrt(Knd*Idq);
print"%s %.2f %s"%('\ntransconductance of the driver= ',gmd,' mA/V\n')
roD=1./(yd*Idq);
print"%s %.2f %s"%('\noutput resistances= ',roD,' Kohm\n')
Av=-gmd*roD/2.;
print"%s %.2f %s"%('\nsmall signal voltage gain= \n',Av,'')
import math
##Example 6.13
Vtn=0.8;
Vtp=-0.8;
Kn=80.*10**-3;
Kp=40.*10**-3;
##x=W/L
xn=15.;
xp=10.;
##lambda=y
yn=0.01;
yp=0.01;
Ibias=0.2;
gm=2.*math.sqrt(Kn*xn*Ibias/2.);
print"%s %.2f %s"%('\ntransconductance of the NMOS driver= ',gm,' mA/V^2\n')
ron=1./(yn*Ibias);
print"%s %.2f %s"%('\noutput resistances= ',ron,' Kohm\n')
Av=-gm*ron/2.;
print"%s %.2f %s"%('\nsmall signal voltage gain= \n',Av,'')
import math
##Example 6.14
Kn1=500.*10**-3;
Kn2=200.*10**-3;
Vtn1=1.2;
Vtn2=Vtn1;
Idq1=0.2;
Idq2=0.5;
Vdsq1=6.;
Vdsq2=6.;
Ri=100.;
Rsi=4.;
Rs2=(10.-Vdsq2)/Idq2;
print"%s %.2f %s"%('\nRs2= ',Rs2,' KOhm\n')
Vgs2=math.sqrt(Idq2/Kn2)+Vtn2;
print"%s %.2f %s"%('\ngate to source voltage for M2= ',Vgs2,' V\n')
Vs2=-1.;
Vg2=Vs2+Vgs2;
print"%s %.2f %s"%('\ngate voltage of M2= ',Vg2,' V\n')
Vg1=Vg2;
Rd1=(5.-Vg1)/Idq1;
print"%s %.2f %s"%('\nresistor Rd1= ',Rd1,' KOhm\n')
Vs1=Vg1-Vdsq1;
print"%s %.2f %s"%('\nsource voltage of M1= ',Vs1,' KOhm\n')
Rs1=(Vs1+5.)/Idq1;
print"%s %.2f %s"%('\nresistor Rs1= ',Rs1,' KOhm\n')
Vgs1=math.sqrt(Idq1/Kn1)+Vtn1;
print"%s %.2f %s"%('\ngate to source voltage for M1',Vgs1,' V\n')
R1=Ri*10./(Vgs1+Idq1*Rs1);
print"%s %.2f %s"%('\nR1= ',R1,' KOhm\n')
##Ri=R1*R2/(R1+R2)
R2=Ri*R1/(R1-Ri);
print"%s %.2f %s"%('\nR2= ',R2,' KOhm\n')
import math
##Example 6.15
Vtn1=1.2;
Vtn2=1.2;
Kn1=0.8;
Kn2=0.8;
##x=R1+R2+R3=300
x=300.;
Rs=10.;
Idq=0.4;
Vdsq1=2.5;
Vdsq2=2.5;
Vs1=Idq*Rs-5.;
print"%s %.2f %s"%('\ndc voltage at source of M1= ',Vs1,' V\n')
Vgs=math.sqrt(Idq/Kn1)+Vtn1;
print"%s %.2f %s"%('\ngate to source voltage= ',Vgs,' V\n')
R3=(Vgs+Vs1)*x/5.;
print"%s %.2f %s"%('\nR3= ',R3,' KOhm\n')
Vs2=Vdsq2+Vs1;
print"%s %.2f %s"%('\nvoltage at source of M2= ',Vs2,' V\n')
##y=R2+R3
y=(Vgs+Vs2)*x/5.;
print"%s %.2f %s"%('\nR2+R3= ',y,' KOhm\n')
R2=150.;
R1=x-y;
print"%s %.2f %s"%('\nR1=',R1,' KOhm\n')
R3=y-R2;
print"%s %.2f %s"%('\nR3= ',R3,' KOhm\n')
Vd2=Vdsq2+Vs2;
print"%s %.2f %s"%('\nvoltage at drain of M2 = ',Vd2,'V\n')
Rd=(5.-Vd2)/Idq;
print"%s %.2f %s"%('\ndrain resistance= ',Rd,' KOhm\n')
import math
##Example 6.17
Kn=0.8;
Vtn=1.2;
Vgs=1.91;
Rd=2.5;
gm=2.*Kn*(Vgs-Vtn);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
Av=-gm*Rd;
print"%s %.2f %s"%('\nsmall signal voltage gain= ',Av,' \n')
import math
##Example 6.18
##Determine the small signal voltage gain of a circuit in fig.6.55
Idss=12.;
Vp=-4.;
##lambda=y
y=0.008;
import numpy
from numpy.polynomial import Polynomial as P
p = P([26.4, 17.2, 2.025])
p.roots()
print('',p.roots(),' V\n')
Vgsq=-2.01
Idq=Idss*(1.-Vgsq/Vp)**2;
print"%s %.2f %s"%('\nquiescent drain current= ',Idq,' mA\n')
gm=(-2*Idss/Vp)*(1.-Vgsq/Vp);
print"%s %.2f %s"%('\ntransconductance= ',gm,' mA/V\n')
ro=(1/(y*Idq));
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
Rd=2.7;
Rl=4.;
x=Rd*Rl/(Rd+Rl);
Av=-gm*ro*x/(ro+x);
print"%s %.2f %s"%('\nsmall signal voltage gain= ',Av,' \n')
import math
##Example 6.19
Idss=12.;
Vp=-4.;
Rl=10.;
##lambda=y
y=0.01;
Av=0.9;
##gm=(-2*Idss/Vp)*(1-Vgs/Vp)
gm=2.;
Vgs=(1.+gm*Vp/(2.*Idss))*Vp;
print"%s %.2f %s"%('\ngate to source voltage= ',Vgs,' V\n')
Idq=Idss*(1.-Vgs/Vp)**2;
print"%s %.2f %s"%('\nquiescent drain current= ',Idq,' mA\n')
Rs=(-Vgs+10.)/Idq;
print"%s %.2f %s"%('\nRs= ',Rs,' KOhm\n')
ro=(1./(y*Idq));
print"%s %.2f %s"%('\noutput resistance= ',ro,' KOhm\n')
x=Rl*ro/(Rl+ro);
t=x*Rs/(x+Rs);
Av=gm*t/(1.+gm*t);
print"%s %.2f %s"%('\nsmall signal voltage gain= ',Av,' \n')