{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ch-7: Field Effect Transistor "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 180 Example 7.1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VGS = 12 V, IG = 10**-9 A\n",
      "Therefore,  gate-to-source resistance  = VGS / IG =12000.00 Mohm\n"
     ]
    }
   ],
   "source": [
    "VGS=12.\n",
    "IG=10**-9\n",
    "GSR=VGS/IG\n",
    "GSR1=GSR*10**-6\n",
    "print \"VGS = 12 V, IG = 10**-9 A\"\n",
    "print \"Therefore,  gate-to-source resistance  = VGS / IG =%0.2f Mohm\"%GSR1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 181 Example 7.2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "delta_VGS = 4 - 3.9 = 0.1 V\n",
      "delta_ID = 1.6 - 1.3 = 0.3 mA\n",
      "Therefore,  transconductance, gm = delta_ID / delta_VGS =3.00 m-mho\n"
     ]
    }
   ],
   "source": [
    "delta_VGS=0.1\n",
    "delta_ID=0.3*10**-3\n",
    "print \"delta_VGS = 4 - 3.9 = 0.1 V\"\n",
    "print \"delta_ID = 1.6 - 1.3 = 0.3 mA\"\n",
    "gm=delta_ID/delta_VGS\n",
    "gm1=gm*10**3\n",
    "print \"Therefore,  transconductance, gm = delta_ID / delta_VGS =%0.2f m-mho\"%gm1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 184 Example 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ID = IDSS*[1 - (VGS/VGS_off)]**2\n",
      "Therefore,    VGS =-6.00 V\n",
      "VP = |VGS_off| = 6.00 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "VGSoff=-6\n",
    "IDSS=8\n",
    "ID=4\n",
    "print \"ID = IDSS*[1 - (VGS/VGS_off)]**2\"\n",
    "VGS=(1-sqrt(ID/IDSS))*VGSoff\n",
    "print \"Therefore,    VGS =%0.2f V\"%VGS\n",
    "VP=abs(VGSoff)\n",
    "print \"VP = |VGS_off| = %0.2f V\"%VP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 184 Example 7.4."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The minimum value of VDS for pinch-off to occur for VGS = -2 V is\n",
      "VDSmin = VGS - VP =3.00 V\n",
      "IDS = IDSS * [1-(VGS/VP)]**2 =8.00 mA\n"
     ]
    }
   ],
   "source": [
    "VGS=-2\n",
    "VP=-5\n",
    "IDSS=8*10**-3\n",
    "print \"The minimum value of VDS for pinch-off to occur for VGS = -2 V is\"\n",
    "VDSmin=VGS-VP\n",
    "print \"VDSmin = VGS - VP =%0.2f V\"%VDSmin\n",
    "IDS=IDSS*(1-(VGS/VP))**2\n",
    "IDS1=IDS*10**3\n",
    "print \"IDS = IDSS * [1-(VGS/VP)]**2 =%0.2f mA\"%IDS1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 186 Example 7.5."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of drain current at Q-point,\n",
      "IDQ = IDSS / 2 =5.00 mA\n",
      "and the value of drain-to-source at Q-point,\n",
      "VDSQ = VDD / 2 = 10.00 V\n",
      "Therefore, the operating point is at:\n",
      "VDS =10.00 V\n",
      "ID(mA) =5.00 mA\n",
      "Therefore,  RD = 2.50 kohm\n",
      "The source voltage or voltage across the source resistor RS is\n",
      "     VS = -VGS = -3 V\n",
      "Also,VS = ID*RS \n",
      "Therefore, RS = 750.00 ohm\n"
     ]
    }
   ],
   "source": [
    "IDSS=10*10**-3\n",
    "VGS=-3\n",
    "ID=4*10**-3\n",
    "VDD=20.\n",
    "print \"The value of drain current at Q-point,\"\n",
    "IDQ=IDSS/2\n",
    "IDQ1=IDQ*10**3\n",
    "print \"IDQ = IDSS / 2 =%0.2f mA\"%IDQ1\n",
    "print \"and the value of drain-to-source at Q-point,\"\n",
    "VDSQ=VDD/2.\n",
    "print \"VDSQ = VDD / 2 = %0.2f V\"%VDSQ\n",
    "print \"Therefore, the operating point is at:\"\n",
    "print \"VDS =%0.2f V\"%VDSQ\n",
    "print \"ID(mA) =%0.2f mA\"%IDQ1\n",
    "RD=(VDD-VDSQ)/ID\n",
    "RD1=RD*10**-3\n",
    "print \"Therefore,  RD = %0.2f kohm\"%RD1\n",
    "print \"The source voltage or voltage across the source resistor RS is\"\n",
    "VS=-VGS\n",
    "print \"     VS = -VGS = -3 V\"\n",
    "print \"Also,VS = ID*RS \"\n",
    "RS=VS/ID\n",
    "print \"Therefore, RS = %0.2f ohm\"%RS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 186 Example 7.6."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We know that,  ID = IDSS * [1 - (VGS/VP)]**2\n",
      "Substituting the given values, we get\n",
      "  ID =40.00 mA\n",
      "Therefore,  RS = |VGSQ / ID| =125.00 ohm\n"
     ]
    }
   ],
   "source": [
    "IDSS=40*10**-3\n",
    "VP=-10\n",
    "VGSQ=-5\n",
    "print \"We know that,  ID = IDSS * [1 - (VGS/VP)]**2\"\n",
    "print \"Substituting the given values, we get\"\n",
    "ID = IDSS*(1-(VGSQ/VP))**2\n",
    "ID1=ID*10**3\n",
    "print \"  ID =%0.2f mA\"%ID1\n",
    "RS=abs(VGSQ/ID)\n",
    "print \"Therefore,  RS = |VGSQ / ID| =%0.2f ohm\"%RS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 187 Example 7.7. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "From fig.7.13.,\n",
      "    VGG = VDD*(R2 / (R1+R2)) = 10.00 V\n",
      "Therefore,  ID=3.39 or 4.72 mA\n",
      "As ID = 4.72mA > 4mA = IDSS, this value is inappropriate. So, IDQ=3.39 mA is selected.\n",
      "Therefore,\n",
      "       VGSQ = VGG - (IDQ*RS) =-0.17 V\n",
      "and VDSQ = VDD - (IDQ*(RD+RS)) =10.75 V\n",
      "Then,  VDGQ = VDSQ - VGSQ = 10.92 V\n",
      "which is grater than |VP| = 2 V. Hence, the FET is in the pinch-off region.\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols,solve\n",
    "VDD=24.\n",
    "R2=8.57*10**6\n",
    "R1=12*10**6\n",
    "VP=-2\n",
    "IDSS=4*10**-3\n",
    "RD=910.\n",
    "RS=3*10**3\n",
    "print \"From fig.7.13.,\"\n",
    "VGG=round(VDD*(R2/(R1+R2)))\n",
    "print \"    VGG = VDD*(R2 / (R1+R2)) = %0.2f V\"%VGG\n",
    "x=symbols('x')\n",
    "p1=solve(9*x**2-73*x+144,x)\n",
    "ans1=p1[0]\n",
    "ans2=p1[1]\n",
    "print \"Therefore,  ID=%0.2f or %0.2f mA\"%(ans1,ans2)\n",
    "print \"As ID = 4.72mA > 4mA = IDSS, this value is inappropriate. So, IDQ=3.39 mA is selected.\"\n",
    "print \"Therefore,\"\n",
    "IDQ=3.39*10**-3\n",
    "VGSQ=VGG-(IDQ*RS)\n",
    "print \"       VGSQ = VGG - (IDQ*RS) =%0.2f V\"%VGSQ\n",
    "VDSQ=VDD-(IDQ*(RD+RS))\n",
    "print \"and VDSQ = VDD - (IDQ*(RD+RS)) =%0.2f V\"%VDSQ\n",
    "VDGQ = VDSQ - VGSQ\n",
    "print \"Then,  VDGQ = VDSQ - VGSQ = %0.2f V\"%VDGQ\n",
    "print \"which is grater than |VP| = 2 V. Hence, the FET is in the pinch-off region.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 190 Example 7.8."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Assume that the JFET is biased in the saturation region. Then the dc drain current is given by\n",
      "            ID = IDSS*(1-(VGS/VP))**2\n",
      "Therefore,  VGS = -1.03 V\n",
      "The voltage at the source terminal is\n",
      "            VS = (ID*RS) - 5 = -2.50 V\n",
      "The gate voltage is\n",
      "            VG = VGS + VS = -3.53 V\n",
      "The gate voltage is\n",
      "               VG = ((R2 / (R1 + R2))*10) - 5\n",
      "Therefore,         R2 = 17.70 kohm\n",
      "and            R1(k-ohm) = 102.30 kohm\n",
      "The drain-to-source voltage is\n",
      "VDS = 5 - ID*RD - ID*RS - (-5)\n",
      "     RD = 0.50 kohm\n",
      "VGS - VP = 2.47 \n",
      "Here, since VDS > (VGS-VP), the JFET is biased in the saturation region, which satisfies the initial assumption\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "IDSS=10*10**-3\n",
    "VP=-3.5\n",
    "Rth=120*10**3 #R1+R2=120 k-ohm\n",
    "ID=5*10**-3\n",
    "VDS=5\n",
    "RS=0.5*10**3\n",
    "print \"Assume that the JFET is biased in the saturation region. Then the dc drain current is given by\"\n",
    "print \"            ID = IDSS*(1-(VGS/VP))**2\"\n",
    "VGS=VP*(1-(sqrt(ID/IDSS)))\n",
    "print \"Therefore,  VGS = %0.2f V\"%VGS\n",
    "# textbook answer is wrong\n",
    "print \"The voltage at the source terminal is\"\n",
    "VS=(ID*RS)-5\n",
    "print \"            VS = (ID*RS) - 5 = %0.2f V\"%VS\n",
    "print \"The gate voltage is\"\n",
    "VG=VGS+VS\n",
    "print \"            VG = VGS + VS = %0.2f V\"%VG\n",
    "print \"The gate voltage is\"\n",
    "print \"               VG = ((R2 / (R1 + R2))*10) - 5\"\n",
    "R2=(Rth*(VG+5))/10\n",
    "R2_1=R2*10**-3\n",
    "print \"Therefore,         R2 = %0.2f kohm\"%R2_1\n",
    "# textbook answer is wrong\n",
    "R1=Rth-R2\n",
    "R1_1=R1*10**-3\n",
    "print \"and            R1(k-ohm) = %0.2f kohm\"%R1_1\n",
    "# textbook answer is wrong\n",
    "print \"The drain-to-source voltage is\"\n",
    "print \"VDS = 5 - ID*RD - ID*RS - (-5)\"\n",
    "RD=(10-VDS-(ID*RS))/ID\n",
    "RD1=RD*10**-3\n",
    "print \"     RD = %0.2f kohm\"%RD1\n",
    "x=VGS-VP\n",
    "print \"VGS - VP = %0.2f \"%x  # textbook has taken a different value hence the wrong answer in textbook\n",
    "print \"Here, since VDS > (VGS-VP), the JFET is biased in the saturation region, which satisfies the initial assumption\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 191 Example 7.9."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VGSt = 3.50 V\n",
      "Therefore,\n",
      "      VDSt = VGSt - VTN = 2.00 V\n",
      "Therefore,  RD(k-ohm) = (VDD - VDSQ) / IDQ = 3.33 kohm\n",
      "Then,     IDQ = KN*(VGSQ-VTN)**2\n",
      "Therefore,  VGSQ = 2.72 V\n",
      "    R1 = 439.56 kohm\n",
      "    R2 = 129.45 kohm\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "KN=1*10**-3\n",
    "lamda=0.01\n",
    "Ri=100*10**3\n",
    "IDt=4*10**-3\n",
    "IDQ=1.5*10**-3\n",
    "VTN=1.5\n",
    "VDD=12.\n",
    "VDSQ=7.\n",
    "VGSt=sqrt(IDt/KN)+VTN\n",
    "print \"VGSt = %0.2f V\"%VGSt\n",
    "print \"Therefore,\"\n",
    "VDSt=VGSt-VTN\n",
    "print \"      VDSt = VGSt - VTN = %0.2f V\"%VDSt\n",
    "RD=(VDD-VDSQ)/IDQ\n",
    "RD1=RD*10**-3\n",
    "print \"Therefore,  RD(k-ohm) = (VDD - VDSQ) / IDQ = %0.2f kohm\"%RD1\n",
    "print \"Then,     IDQ = KN*(VGSQ-VTN)**2\"\n",
    "VGSQ=(sqrt(IDQ/KN))+VTN\n",
    "print \"Therefore,  VGSQ = %0.2f V\"%VGSQ\n",
    "R1=1200/2.73\n",
    "print \"    R1 = %0.2f kohm\"%R1\n",
    "R2=R1/((12/2.73)-1)\n",
    "print \"    R2 = %0.2f kohm\"%R2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Page No. 192 Example 7.10."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ID = 0.40 mA\n",
      "The d.c. drain-to-source voltage is\n",
      "     VDS = VDD - ID*RS = 3.00 V\n",
      "Then,  VDSsat = VGS - VTN = 2.00 V\n",
      "Since VDS > VDSsat, the MOSFET is biased in the saturation region\n"
     ]
    }
   ],
   "source": [
    "\n",
    "VTN=-2\n",
    "KN=0.1*10**-3\n",
    "VDD=5\n",
    "RS=5*10**3\n",
    "VGS=0\n",
    "ID=KN*(-VTN)**2\n",
    "ID1=ID*10**3\n",
    "print \"ID = %0.2f mA\"%ID1\n",
    "print \"The d.c. drain-to-source voltage is\"\n",
    "VDS=VDD-(ID*RS)\n",
    "print \"     VDS = VDD - ID*RS = %0.2f V\"%VDS\n",
    "VDSsat=VGS-VTN\n",
    "print \"Then,  VDSsat = VGS - VTN = %0.2f V\"%VDSsat\n",
    "print \"Since VDS > VDSsat, the MOSFET is biased in the saturation region\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
