{
 "metadata": {
  "name": "",
  "signature": "sha256:c173021e2b7fbdc477decea90b9573f8e45713d84c6fe5e0bdfc01c8abeb68c8"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "chapter07:Small Signal SIngle-Stage Amplifier"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E1 - Pg 229"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate max current and check will the capacitor act as short for given frequency\n",
      "#given\n",
      "import math\n",
      "C=100.*10.**-6.;#Farad\n",
      "Rs=1.*10.**3.;#ohm\n",
      "Rl=4.*10.**3.;#ohm\n",
      "Vs=1.;#V\n",
      "Imax=Vs/(Rs+Rl);\n",
      "fc=1./(2.*math.pi*(Rs+Rl)*C)     #critical frequency\n",
      "fh=10.*fc;                  #Border frequency\n",
      "print '%s %.f %s' %(\"Maximum current is =\",Imax*10**6,\"uA\\n\");\n",
      "print '%s %.2f %s' %(\"fh =\",fh,\"Hz\\n\");\n",
      "print '%s %.2f %s %s' %(\"As long as source frequency is greater than\",fh,\"Hz\",\"the coupling capacitor acts like an ac short for 20Hz to 20kHz\")\n",
      "\n",
      "#In book Imax is 200mA but there is misprinting of 'm' in mA it should be uA\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum current is = 200 uA\n",
        "\n",
        "fh = 3.18 Hz\n",
        "\n",
        "As long as source frequency is greater than 3.18 Hz the coupling capacitor acts like an ac short for 20Hz to 20kHz\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E2 - Pg 230"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Check whether the capacitor is an effective bypass for the signal currents of lowest frequency 20 Hz\n",
      "#given\n",
      "import math\n",
      "C=100.*10.**-6.;#Farad\n",
      "Rs=1.*10.**3.;#ohm\n",
      "Rl=4.*10.**3.;#ohm\n",
      "f=20.;#Hz          #lowest frequency\n",
      "Xc=1./(2.*math.pi*f*C)         #reactance of capacitor at 20Hz\n",
      "Rth=Rs*Rl/(Rs+Rl);      #Thevenins equivalent resistance\n",
      "print '%s %.1f %s %.f %s ' %(\"Xc < Rth/10 is satisfied\",Xc,\"ohm\",Rth/10,\"ohm\\n\");\n",
      "print '%s' %(\"The capacitor of 100uF will work as a good bypass for frequencies greater than 20 Hz \")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Xc < Rth/10 is satisfied 79.6 ohm 80 ohm\n",
        " \n",
        "The capacitor of 100uF will work as a good bypass for frequencies greater than 20 Hz \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E3 - Pg 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the value of capacitor required\n",
      "#given\n",
      "import math\n",
      "Rs1=20.*10.**3.;#ohm\n",
      "Rs2=30.*10.**3.;#ohm\n",
      "Rl1=40.*10.**3.;#ohm\n",
      "Rl2=80.*10.**3.;#ohm\n",
      "Rl3=80.*10.**3.;#ohm\n",
      "Rth=Rs1*Rs2/(Rs1+Rs2);          #Thevenins equivalent resistance\n",
      "Rl_=Rl2*Rl3/(Rl2+Rl3);\n",
      "Rl=Rl1*Rl_/(Rl1+Rl_);    #Equivalent load\n",
      "f=50.;#Hz          #lowest frequency\n",
      "R=Rth+Rl;\n",
      "C=10./(2.*math.pi*f*R)\n",
      "print '%s %.f %s' %(\"The required value of coupling capacitor is =\",C*10**6,\"uF\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The required value of coupling capacitor is = 1 uF\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E4 - Pg 247"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate voltage and current gain and input and output resistance\n",
      "def  prll(r1,r2):\n",
      "\tz=r1*r2/(r1+r2)#\n",
      "\treturn z\n",
      "#given\n",
      "\n",
      "#DC analysis\n",
      "Vcc=12.;#V\n",
      "Rb=200.*10.**3.;#ohm\n",
      "Rc=1.*10.**3.;#ohm\n",
      "B=100.;# beta\n",
      "Ib=Vcc/Rb;\n",
      "Ic=B*Ib;\n",
      "Icsat=Vcc/Rc;\n",
      "Vce=Vcc-Ic*Rc;\n",
      "print '%s %.2f %s %.2f %s' %(\"The Q point of DC analysis=\",Vce,\"V\",Ic*1000,\"mA\");\n",
      "\n",
      "#AC analysis\n",
      "Rl=1.*10.**3.;#ohm\n",
      "hfe=B;\n",
      "hie=2.*10.**3.;#ohm\n",
      "hoe_1=40.*10.**3.;#ohm      # 1/hoe\n",
      "Rac=prll(Rc,Rl);\n",
      "Av=-hfe*Rac/hie;\n",
      "print '%s %.2f %s' %(\"\\nThe voltage gain =\",Av,\"\\n\");\n",
      "\n",
      "#Siince (1/hoe) > Rac therefore entire current will flows through Rac\n",
      "Io=-100.*Ib;\n",
      "Ac=Io/Ib;\n",
      "print '%s %.2f %s' %(\"The current gain =\",Ac,\"\\n\");\n",
      "\n",
      "Ri=prll(Rb,hie);\n",
      "Ro=prll(Rl,prll(Rc,hoe_1));\n",
      "print '%s %.f %s' %(\"The input resistance =\",Ri/1000,\"kohm\\n\");\n",
      "print '%s %.1f %s' %(\"The output resistance =\",Ro/1000,\"kohm\");\n",
      "\n",
      "#In book the voltage gain is 25 due to skipping of '-' in printing\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Q point of DC analysis= 6.00 V 6.00 mA\n",
        "\n",
        "The voltage gain = -25.00 \n",
        "\n",
        "The current gain = -100.00 \n",
        "\n",
        "The input resistance = 2 kohm\n",
        "\n",
        "The output resistance = 0.5 kohm\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E5 - Pg 249"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Solve previous example using hybrid pie model\n",
      "#soltion\n",
      "#given\n",
      "def  prll(r1,r2):\n",
      "\tz=r1*r2/(r1+r2)#\n",
      "\treturn z\n",
      "Vcc=12.##V\n",
      "Rb=200.*10.**3.##ohm\n",
      "Rc=1.*10.**3.##ohm\n",
      "Rl=1.*10.**3.##ohm\n",
      "B=100.## beta\n",
      "hie=2.*10.**3.##ohm\n",
      "hoe_1=40.*10.**3.##ohm      # 1/hoe\n",
      "\n",
      "Ib=Vcc/Rb#\n",
      "Ic=B*Ib#\n",
      "Rac=prll(Rc,Rl)#\n",
      "gm=Ic/(25.*10.**-3.)#\n",
      "rpi=B/gm#\n",
      "ri=hie#\n",
      "rb=ri-rpi#\n",
      "ro=hoe_1#\n",
      "Vpi=rpi/(rpi+rb)#\n",
      "Vo=-gm*Vpi*Rac#    #output voltage\n",
      "Av=Vo#\n",
      "print '%s %.2f' %(\"The voltage gain\",Av)#\n",
      "#In book voltage gain is -24.96 due to appraoximation\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage gain -25.00\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E6 - Pg 250"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Determine the value of output voltage\n",
      "#given\n",
      "Vcc=12.;#V\n",
      "Rb=150.*10.**3.;#ohm\n",
      "Rc=5.*10.**3.;#ohm\n",
      "B=200.;# beta\n",
      "hie=2.*10.**3.;#ohm\n",
      "ro=60.*10.**3.;#ohm      # 1/hoe\n",
      "Vi=1.*10.**-3.;#V\n",
      "Ib=Vcc/Rb;\n",
      "Ic=B*Ib;\n",
      "Icsat=Vcc/Rc;\n",
      "# Icsat < Ic therefore transistor is in saturation mode and outpuut voltage wil be zero\n",
      "Vo=0;\n",
      "print '%s %.f %s' %(\"The output voltage=\",Vo,\"V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The output voltage= 0 V\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E7 - Pg 250"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate voltage gain and input resistance\n",
      "# Function definition is here\n",
      "#given\n",
      "def  prll(r1,r2):\n",
      "\tz=r1*r2/(r1+r2);\n",
      "\treturn z\n",
      "\n",
      "R1=75.*10.**3.;#ohm\n",
      "R2=7.5*10.**3.;#ohm\n",
      "Rc=4.7*10.**3.;#ohm\n",
      "Re=1.2*10.**3.;#ohm\n",
      "Rl=12.*10.**3.;#ohm\n",
      "B=150.;\n",
      "ri=2.*10.**3.;#ohm\n",
      "Vcc=15.;#V\n",
      "Vb=Vcc*R2/(R1+R2);\n",
      "Ve=Vb;        #since Vbe=0\n",
      "Ie=Ve/Re;\n",
      "Ic=Ie;\n",
      "Icsat=Vcc/(Rc+Re);\n",
      "# Ic < Icsat therefore transistor is in active mode\n",
      "Vce=Vcc-Ic*(Rc+Re);\n",
      "print '%s %.2f %s %.2f %s' %(\"The Q point of DC analysis=\",Vce,\"V\",Ic*1000,\"mA\");\n",
      "\n",
      "Rac=prll(Rc,Rl);\n",
      "Av=-B*Rac/ri;\n",
      "print '%s %.1f %s' %(\"\\nThe voltage gain =\",Av,\"\\n\");\n",
      "Ri_=prll(ri,R2);\n",
      "print '%s %.2f %s' %(\"The input resistance=\",Ri_/1000,\"kohm\\n\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Q point of DC analysis= 8.30 V 1.14 mA\n",
        "\n",
        "The voltage gain = -253.3 \n",
        "\n",
        "The input resistance= 1.58 kohm\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E8 - Pg 253"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Calculate the value of gm at different values of Vgs\n",
      "#given\n",
      "\n",
      "Idss=8.*10.**-3.;#A\n",
      "Vp=4;#V\n",
      "#At Vgs= -0.5 V\n",
      "Vgs= -0.5;#V\n",
      "gmo=2.*Idss/(abs(Vp));\n",
      "gm=gmo*(1.-(Vgs/(-Vp)));\n",
      "print '%s %.f %s' %(\"gmo =\",gmo*1000,\"mS\\n\");\n",
      "print '%s %.1f %s' %(\"gm (At Vgs = -0.5V) =\",gm*1000,\"mS\\n\");\n",
      "\n",
      "#At Vgs= -1.5 V\n",
      "Vgs= -1.5;#V\n",
      "gmo=2.*Idss/(abs(Vp));\n",
      "gm=gmo*(1.-(Vgs/(-Vp)));\n",
      "print '%s %.1f %s' %(\"gm (At Vgs = -1.5V) =\",gm*1000,\"mS\\n\");\n",
      "\n",
      "#At Vgs= -2.5 V\n",
      "Vgs= -2.5;#V\n",
      "gmo=2.*Idss/(abs(Vp));\n",
      "gm=gmo*(1.-(Vgs/(-Vp)));\n",
      "print '%s %.1f %s' %(\"gm (At Vgs = -2.5V) =\",gm*1000,\"mS\\n\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "gmo = 4 mS\n",
        "\n",
        "gm (At Vgs = -0.5V) = 3.5 mS\n",
        "\n",
        "gm (At Vgs = -1.5V) = 2.5 mS\n",
        "\n",
        "gm (At Vgs = -2.5V) = 1.5 mS\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E9 - Pg 255"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Find the output signal voltage of the amplifier\n",
      "#given\n",
      "import math\n",
      "Rd=12.*10.**3.;#ohm\n",
      "Rg=1.*10.**6.;#ohm\n",
      "Rs=1.*10.**3.;#ohm\n",
      "Cs=25.*10.**-6.;#F\n",
      "u=80.;      #amplification factor\n",
      "rd=200.*10.**3.;#ohm\n",
      "Vi=0.1;#V\n",
      "f=1.*10.**3.;#Hz      #input frequency\n",
      "Xcs=1./(2.*math.pi*f*Cs);\n",
      "#This is much smaller than Rs therefore it is bypassed\n",
      "\n",
      "gm=u/rd;\n",
      "Av=gm*(rd*Rd/(rd+Rd));\n",
      "Vo=Av*Vi;\n",
      "print '%s %.3f %s' %(\"The output voltage is =\",Vo,\"V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The output voltage is = 0.453 V\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E10 - Pg 256"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Determine the small signal voltage gain and input and output resistance\n",
      "#given\n",
      "Rd=2.*10.**3.;#ohm\n",
      "rd=100.*10.**3.;#ohm\n",
      "Rg=1.*10.**6.;#ohm\n",
      "gm=2.*10.**-3.;#S\n",
      "Av=-gm*(rd*Rd/(rd+Rd));\n",
      "Ri=Rg;\n",
      "Ro=rd*Rd/(rd+Rd);\n",
      "print '%s %.f %s %.f %s %s %.f %s' %(\"The small signal voltage gain =\",Av,\"\\ninput resistance=\",Ri/10**6,\"Mohm\",\"\\noutput resistance =\",Ro/1000,\"kohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The small signal voltage gain = -4 \n",
        "input resistance= 1 Mohm \n",
        "output resistance = 2 kohm\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E11 - Pg 256"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Determine the small signal voltage gain and input and output resistance\n",
      "#given\n",
      "R1=500.*10.**3.;#ohm\n",
      "R2=50.*10.**3.;#ohm\n",
      "Rd=5.*10.**3.;#ohm\n",
      "Rs=100.;#ohm\n",
      "Rl=5.*10.**3.;#ohm\n",
      "gm=1.5*10.**-3.;#S\n",
      "rd=200.*10.**3.;#ohm\n",
      "Rg=R1*R2/(R1+R2);\n",
      "Rac=Rd*Rl/(Rd+Rl);\n",
      "Av=-gm*Rac;\n",
      "Ri=Rg;\n",
      "Ro=(rd*Rac/(rd+Rac));\n",
      "print '%s %.2f %s %.2f %s %s %.1f %s' %(\"The small signal voltage gain =\",Av,\"\\nInput resistance =\",Ri/1000,\"kohm\",\"\\nOutput resistance =\",Ro/1000,\"kohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The small signal voltage gain = -3.75 \n",
        "Input resistance = 45.45 kohm \n",
        "Output resistance = 2.5 kohm\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E12 - Pg 257"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the voltage gain of the FET\n",
      "#given\n",
      "Idss=8.*10.**-3.##A\n",
      "Vp=4.##V\n",
      "rd=25.*10.**3.##ohm\n",
      "Rd=2.2*10.**3.##ohm     #by the help of figure\n",
      "Vgs=-1.8##V\n",
      "gmo=2.*Idss/(abs(Vp))#\n",
      "gm=gmo*(1.-(Vgs/(-Vp)))#\n",
      "Av=-gm*(rd*Rd/(rd+Rd))#\n",
      "print '%s %.2f' %(\"The voltage gain of the FET =\",Av)#\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage gain of the FET = -4.45\n"
       ]
      }
     ],
     "prompt_number": 12
    }
   ],
   "metadata": {}
  }
 ]
}