{
 "metadata": {
  "name": "",
  "signature": "sha256:7b8ef11e11019a3b1cc284475151e0d8bb5d6632f9c468e0f90289ce47134c38"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "                                   Chapter 2: TRANSISTORS AND OTHER DEVICES"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1,Page number 89"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Rb=200                  #base resistance(ohm)\n",
      "Vbe=0.7                 #base emitter voltage drop(V) in active region          \n",
      "Vbb=5                   #base voltage of bipolar transistor(V) \n",
      "beeta=100               #current gain\n",
      "Rc=3                    #collector resistance(k ohms)\n",
      "Vcc=10                  #voltage given to the collector(V)\n",
      "\n",
      "#Calculations\n",
      "Ib=(Vbb-Vbe)/Rb           #base current(mA)  \n",
      "Ic=beeta*Ib               #collector current(mA) \n",
      "Vcb=-Vbe-(Rc*Ic)+Vcc      #collector base voltage drop(V)\n",
      "\n",
      "#Results\n",
      "print\"base current\",Ib,\"mA\" \n",
      "print\"collector current\",Ic,\"mA\"\n",
      "print\"reverse bias collector junction is\",Vcb,\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "base current 0.0215 mA\n",
        "collector current 2.15 mA\n",
        "reverse bias collector junction is 2.85 V\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.2,Page number 90"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vbb=5               #base voltage of bipolar transistor(V)\n",
      "Vbe=0.7             #base emitter voltage drop(V) in active region  \n",
      "Rb=150              #base resistance(ohm)\n",
      "beeta=125           #curret gain     \n",
      "Rc=3                #collector resistance(k ohms)  \n",
      "Vcc=10              #supply voltage(V)\n",
      "Vce=0.2             #collector to emitter voltage(V)\n",
      "\n",
      "#Calculations\n",
      "#Part a\n",
      "Ib=(Vbb-Vbe)/Rb       #base current(mA)\n",
      "Ic=beeta*Ib           #collector current(mA)\n",
      "Vcb=-Vbe-(Rc*Ic)+Vcc  #collector base voltage drop(V)\n",
      "\n",
      "#Part b -for npn transistor\n",
      "Vbe=0.8             #base emitter voltage drop(V) in saturation\n",
      "Ic=(Vcc-Vce)/Rc     #collector current(mA)\n",
      "Ib=(Vbb-Vbe)/Rb     #base current(mA)\n",
      "Ibmin=Ic/beeta      #minimum base current(mA) to go into saturation(mA)\n",
      "\n",
      "#Results\n",
      "print\"In active region, base current is\",round(Ib/1E-3),\"*10**-3 mA and collector current is\",round(Ic,2),\"mA\" \n",
      "print\"base current and collector current in npn are\",round((Ib/1E-3),2),\"*10**-3 mA\",\"and\",round(Ic,2),\"mA resp.\"\n",
      "print\"base current minimum is\",round(Ibmin,3),\"mA\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In active region, base current is 28.0 *10**-3 mA and collector current is 3.27 mA\n",
        "base current and collector current in npn are 28.0 *10**-3 mA and 3.27 mA resp.\n",
        "base current minimum is 0.026 mA\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.3,Page number 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vbb=5                 #base voltage of bipolar transistor(V)\n",
      "Vbe=0.7               #base emitter voltage drop(V) in active region  \n",
      "Rb=50                 #base resistance(ohm)\n",
      "beeta=50              #current gain\n",
      "Re=1.8                #emitter resistance(k ohms)    \n",
      "Vcc=10                #supply voltage(V)\n",
      "Vce=0.2               #collector to emitter voltage(V)\n",
      "\n",
      "#Calculations\n",
      "Ib=(Vbb-Vbe)/(Rb+Re*(beeta+1))      #base current(mA)\n",
      "Ic=beeta*Ib                         #collector current(mA)\n",
      "Ie=Ib+Ic                            #emitter current(mA)\n",
      "\n",
      "#Results\n",
      "print\"values are Ib:\",round(Ib,2),\"mA,Ic:\",round(Ic,2),\"mA and Ie:\",round(Ie,2),\"mA\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "values are Ib: 0.03 mA,Ic: 1.52 mA and Ie: 1.55 mA\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4,Page number 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vbe=0.7                      #base to emitter voltage(V)\n",
      "Rb=250                       #base resistance(k ohms)\n",
      "Vcc=10                       #supply voltage(V)\n",
      "Rl=0.5                       #load resistance(k ohms)\n",
      "\n",
      "#Calculations\n",
      "Ic=Vcc/Rl                    #collector current(mA)\n",
      "IbQ=(Vcc-Vbe)/Rb             #Ib at operating point(uA)\n",
      "IcQ=8                        #Ic at operating point(mA)\n",
      "VceQ=6                       #Vce at operating point(V)\n",
      "\n",
      "#Results\n",
      "print\"values are IbQ:\",IbQ,\"uA,IcQ:\",IcQ,\"mA and Vcc:\",Vcc,\"V\"\n",
      "print\"collector current Ic is\",Ic,\"mA and output voltage,vL=6-2 sinwt V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "values are IbQ: 0.0372 uA,IcQ: 8 mA and Vcc: 10 V\n",
        "collector current Ic is 20.0 mA and output voltage,vL=6-2 sinwt V\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.5,Page number 104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vgs=12                   #gate to source voltage(V)\n",
      "Vt=4                     #threshold voltage(V)\n",
      "Id=12.8                  #drain current(mA)\n",
      "K=0.0002                 #device parameter \n",
      "Vdd=24                   #drain voltage(V)\n",
      "Vds=Vgs=8                #drain to source voltage(V)      \n",
      "\n",
      "#Calculations\n",
      "Id=K*((Vds-Vt)**2)       #drain current at Vds=8V\n",
      "Rd=(Vdd-Vds)/Id          #drain resistance(k ohms)\n",
      "\n",
      "#Result\n",
      "print\"diode resistance is\",Rd,\"ohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "diode resistance is 5000.0 ohms\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7,Page number 106"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vds=7.5                #drain to source voltage(V)\n",
      "Id=5                   #drain current(mA)      \n",
      "\n",
      "#Calculations\n",
      "Vgs=-1.5               #gate to source voltage(V)\n",
      "Vgg=-Vgs               #gate voltage=gate to source voltage(V) \n",
      "\n",
      "#Result\n",
      "print\"gate voltage is\",Vgg,\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "gate voltage is 1.5 V\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8,Page number 107"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vds=7.5                  #drain to source voltage(V)\n",
      "Idss=8.                  #drain current for Vgs(V)\n",
      "Vgs=2.                   #gate to source voltage(V)\n",
      "Vp=4.                    #peak voltage(V)\n",
      "\n",
      "#Calculations\n",
      "Id=Idss*((Vp-Vgs)/Vp)**2  #drain current(mA)\n",
      "\n",
      "#Result\n",
      "print\"diode current is\",Id,\"mA\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "diode current is 2.0 mA\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.10,Page number 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "beeta=160               #current gain\n",
      "Vee=10                  #emitter voltage(V)\n",
      "Rb=400                  #base resistance(k ohms)\n",
      "Veb=0.8                 #emitter to base voltage(V)\n",
      "Re=2.5                  #emitter resistance(k ohms)\n",
      "Rc=1.5                  #collector resistance(k ohms)   \n",
      "\n",
      "#Calculations\n",
      "#Part a \n",
      "Ib=(Vee-Veb)/((Re*(1+beeta))+Rb)    #base current(uA)\n",
      "Ic=beeta*Ib                         #collector current(mA)\n",
      "Ie=(beeta+1)*Ib                     #emitter current(mA) \n",
      "Vce=Vee-(Re*Ie)-(Rc*Ic)             #emitter to collector voltage(V)   \n",
      "Vce=-Vce                            #collector to emitter voltage(V)\n",
      "\n",
      "#Part b\n",
      "beeta=80                            #current gain \n",
      "Ib1=(Vee-Veb)/((Re*(1+beeta))+Rb)   #base current(uA)\n",
      "Ic1=beeta*Ib1                       #collector current(mA)\n",
      "Ie1=(beeta+1)*Ib1                   #emitter current(mA)   \n",
      "Vce1=-(Vee-(Ie1*Re)-(Rc*Ic1))       #collector to emitter voltage(V)   \n",
      "                      \n",
      "#Result\n",
      "print\"collector current and Vce for beeta=160 are\",round(Ic,2),\"mA\",\"and\",round(Vce,2),\"V\" \n",
      "print\"Ic and Vce for beeta=80 are\",round(Ic,2),\"mA\",\"and\",round(Vce1,2),\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "collector current and Vce for beeta=160 are 1.83 mA and -2.63 V\n",
        "Ic and Vce for beeta=80 are 1.83 mA and -5.08 V\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.13,Page number 120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import*\n",
      "import math \n",
      "\n",
      "#Variable declaration\n",
      "K=2                      #device parameter\n",
      "Rd=Rs=2.5*10**3          #drain resistance(k ohms)\n",
      "R1=100*10**3             #resistance(ohms)\n",
      "R2=200*10**3             #resistance(ohms)\n",
      "Vdd=12                   #drain voltage(V)\n",
      "Vt=4                     #threshold voltage(V)\n",
      "\n",
      "#Calculations\n",
      "Vgg=(R2*Vdd)/(R1+R2)\n",
      "Id=symbols('Id')                         #gate voltage(V)\n",
      "expr=solve(Id**2-3.28*Id+2.56,Id)\n",
      "print expr\n",
      "Id=1.28\n",
      "Vds=Vdd-5*Id\n",
      "\n",
      "#Result\n",
      "print\"Id is\",Id,\"mA and Vds is\",Vds,\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[1.28000000000000, 2.00000000000000]\n",
        "Id is 1.28 mA and Vds is 5.6 V\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.14,Page number 121"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "k=2.                       #device parameter\n",
      "Vt=-1.                     #threshold voltage(V)\n",
      "Vdd=-12.                   #drain voltage(V)\n",
      "R1=300.                    #resistance(kohms)\n",
      "R2=100.                    #resistance(kohms)\n",
      "\n",
      "#Calculations\n",
      "#Part a\n",
      "Vgs=-2                  #gate to source voltage(V)\n",
      "Vgg=(R2*Vdd)/(R1+R2)    #gate voltage(V)\n",
      "Id=k*((Vgs-Vt)**2)      #drain current(mA)\n",
      "Rs=(Vgs-Vgg)/Id         #source resistance(k ohms) as Id=Is,Kvl in GS loop\n",
      "Is=Id\n",
      "\n",
      "#Part b\n",
      "Vds=-4                    #drain to source voltage(V)\n",
      "Rd=(-Vdd+Vds-(Is*Rs))/Id  #applying kvl in DS loop\n",
      "\n",
      "#Part c \n",
      "Vt=-1.5                      #threshold voltage(V)             \n",
      "Vgg=-1.5                     #gate voltage using Id formula    \n",
      "R2new=(Vgg*R1)/(Vdd-Vgg)     #new resistance(k ohms)\n",
      "\n",
      "#Results\n",
      "print\"a)source resistance is\",Rs,\"kohm\" \n",
      "print\"b)drain resistance is\",Rd,\"kohm\"\n",
      "print\"c)R2new is\",round(R2new,2),\"kohm\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a)source resistance is 0.5 kohm\n",
        "b)drain resistance is 3.5 kohm\n",
        "c)R2new is 42.86 kohm\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.15,Page number 122"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Vp=-4                    #peak voltage(V)\n",
      "Idss=10                  #drain current for Vgs(V)\n",
      "Vdd=18                   #drain voltage(V)   \n",
      "Rs=2               #source resistance(ohms) \n",
      "Rd=2               #drain resistance(ohms)\n",
      "R1=450*10**3             #resistance(ohms)\n",
      "R2=90*10**3              #resistance(ohms)\n",
      "\n",
      "#Calculations\n",
      "Vgg=(R2*Vdd)/(R1+R2)\n",
      "from sympy import*\n",
      "Id=symbols('Id')\n",
      "expr=solve(20*Id**2-148*Id+245,Id)\n",
      "print expr\n",
      "Id1=2.5\n",
      "Vds=Vdd-((Rs+Rd)*Id1)\n",
      "\n",
      "#Result\n",
      "print\"Id is\",Id1,\"mA and Vds is\",Vds,\"V\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[5/2, 49/10]\n",
        "Id is 2.5 mA and Vds is 8.0 V\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.16,Page number 123"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Vp=4                    #peak voltage(V)\n",
      "Idss=12.                #drain current for Vgs(V) \n",
      "Vdd=12                  #drain voltage(V)\n",
      "Id=4.                   #drain current(mA)\n",
      "Vds=6                   #drain to source voltage(V)\n",
      "\n",
      "#Calculations\n",
      "Rs=(Vp/4)*(1-(math.sqrt(Id/Idss)))      #by Id=Idss(1-(Vgs/Vp))^2 and putting Vgs=4Rs in it and solving\n",
      "Rd=((Vdd+Vds)/Id)-Rs                    #solving equation -Vdd-Vds+(Id*(Rd+Rs))=0      \n",
      "                                             \n",
      "#Result\n",
      "print\"source resistance is\",round(Rs,2),\"kohm\" \n",
      "print\"drain resistance\",round(Rd,2),\"kohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "source resistance is 0.42 kohm\n",
        "drain resistance 4.08 kohms\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}