{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5 - BJT Amplifier"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 283 example 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   -50.00\n",
      "input resistance   =   2600.00 ohm\n",
      "ce removed\n",
      "voltage gain   =   -50.00\n",
      "input resistance   =   12600.00 ohm\n"
     ]
    }
   ],
   "source": [
    "ic=1*10**-3##ampere\n",
    "vcc=5##volt\n",
    "colres=2*10**3##ohm\n",
    "r1=1.4*10**3##ohm\n",
    "re=100##ohm\n",
    "beta1=100\n",
    "rb=100##ohm\n",
    "v1=0.026\n",
    "c1=25*10**-6##farad\n",
    "g1=ic/v1\n",
    "freque=10*10**3##hertz\n",
    "xc=1/(2*freque*3.14*c1)\n",
    "volgai=-beta1*colres/(r1+0.1*10**3+2.5*10**3)\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "ri=(0.1+2.5)*10**3-((xc.imag)*(1+beta1))\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "#ce removed\n",
    "volgai=-beta1*colres/((r1+0.1*10**3+2.5*10**3)+(101/1000)*10**3*100)\n",
    "print \"ce removed\"\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "ri=(0.1+2.5)*10**3+100*101/1000*10**3\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 285 example 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   260.00 <180\n",
      "voltage gain reduced ce removed\n",
      "when cb is   short circuited the voltage gain increased\n"
     ]
    }
   ],
   "source": [
    "ic=1.3*10**-3##ampere\n",
    "colres=2*10**3##ohm\n",
    "re=500##ohm\n",
    "v1=0.026##volt\n",
    "beta1=100\n",
    "vcc=15##volt\n",
    "c1=10*10**-6##farad\n",
    "ib=ic/beta1\n",
    "ri=0.01/ib\n",
    "volgai=beta1*colres*ib/0.01\n",
    "print \"voltage gain   =   %0.2f\"%((volgai)),\"<180\"\n",
    "print \"voltage gain reduced ce removed\"\n",
    "print \"when cb is   short circuited the voltage gain increased\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 286 example 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current gain   =   -11.62\n",
      "voltage gain   =   -46.46\n",
      "transconductance   =   -0.01 ampere per volt\n",
      "transresistance   =   -46464.08 ohm\n",
      "input resistance   =   1042.65 ohm\n",
      "output resistance   =   3636.00 ohm\n"
     ]
    }
   ],
   "source": [
    "colres=4*10**3##ohm\n",
    "r1=4*10**3##ohm\n",
    "\n",
    "rb=20*10**3##ohm\n",
    "r=1*10**3##ohm\n",
    "hie=1.1*10**3##ohm\n",
    "\n",
    "#current gain\n",
    "ri=rb*hie/(rb+hie)\n",
    "curgai=(1/2.04)*(rb/(rb+(hie)))*(-50*colres/(colres+(r1)))\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "#voltage gain\n",
    "volgai=curgai*r1/r\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "#transconductance\n",
    "conduc=volgai/r1\n",
    "print \"transconductance   =   %0.2f\"%((conduc)),\"ampere per volt\"\n",
    "#transresistance\n",
    "resist=volgai*r\n",
    "print \"transresistance   =   %0.2f\"%((resist)),\"ohm\"\n",
    "#input resistance\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "#output resistance\n",
    "resist=40*10**3*colres/(40*10**3+colres)\n",
    "\n",
    "\n",
    "\n",
    "print \"output resistance   =   %0.2f\"%((resist)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 287 example 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rb   =   235000.00 ohm\n",
      "rb including emitter resistance   =   230000.00 ohm\n"
     ]
    }
   ],
   "source": [
    "ib=20*10**-6##ampere\n",
    "beta1=500\n",
    "re=10##ohm correction in the book\n",
    "r1=4.7*10**2##ohm correction in the book\n",
    "ic=ib*beta1\n",
    "voltag=ic*r1##voltage drop at 4.7*10**3ohm\n",
    "vc=(10-voltag)\n",
    "rb=(vc-0.6)/ib\n",
    "print \"rb   =   %0.2f\"%((rb)),\"ohm\"\n",
    "#re included\n",
    "voltag=ic*re##voltage drop at re\n",
    "vb=(0.6+voltag)\n",
    "rb=(vc-vb)/ib\n",
    "print \"rb including emitter resistance   =   %0.2f\"%((rb)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 288 example 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain with fedback   =   73.92 decibel\n",
      "beta   =   1.20e-04\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import log10\n",
    "av=12480\n",
    "fedbac=8##decibel\n",
    "volgai=20*log10(av)##gain without fedback\n",
    "volga1=volgai-fedbac\n",
    "beta1=((av/5000)-1)/av\n",
    "\n",
    "print \"voltage gain with fedback   =   %0.2f\"%((volga1)),\"decibel\"\n",
    "print \"beta   =   %0.2e\"%((beta1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 288 example 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "collector current   =   3.00e-03 ampere\n",
      "emitter current   =   3.00e-03 ampere\n",
      "base current   =   3.00e-05 ampere\n"
     ]
    }
   ],
   "source": [
    "beta1=100\n",
    "r1=1.5*10**3##ohm\n",
    "vcc=10##volt\n",
    "r=100*10**3##ohm\n",
    "vb=((vcc)/(r+10*10**3))*10*10**3\n",
    "ie=0.3/100\n",
    "ib=ie/beta1\n",
    "print \"collector current   =   %0.2e\"%((ie)),\"ampere\"\n",
    "print \"emitter current   =   %0.2e\"%((ie)),\"ampere\"\n",
    "print \"base current   =   %0.2e\"%((ib)),\"ampere\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 268 example 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   -125.00\n",
      "power gain   =   6250.00\n",
      "error without hoe   =   10.00\n",
      "error   =   21.00\n"
     ]
    }
   ],
   "source": [
    "hie=800##ohm\n",
    "he=50*10**-6##mho\n",
    "hfe=-55\n",
    "z1=2*10**3##ohm\n",
    "curgai=hfe/(1+he*z1)\n",
    "zi=hie\n",
    "volgai=curgai*z1/zi\n",
    "powgai=volgai*curgai\n",
    "#if hoe neglected\n",
    "av=137.5\n",
    "hfe=-55\n",
    "w=((av-abs(volgai))*100)/abs(volgai)\n",
    "ap=hfe*(-av)\n",
    "w1=((ap-powgai)*100)/powgai\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "\n",
    "\n",
    "print \"power gain   =   %0.2f\"%((powgai))\n",
    "print \"error without hoe   =   %0.2f\"%((w))\n",
    "print \"error   =   %0.2f\"%((w1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 289 example 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "emitter current   =   1.92e-03 ampere\n",
      "vc   =   18.12 volt\n",
      "collector emitter voltage   =   8.53 volt\n"
     ]
    }
   ],
   "source": [
    "rb=5*10**3##ohm\n",
    "vcc=20##volt\n",
    "r=10*10**3##ohm\n",
    "colres=5*10**3##ohm\n",
    "vb=vcc*r/(r+r)\n",
    "beta1=50\n",
    "v1=0.6##volt\n",
    "ib=(vb-v1)/(1+beta1*colres)\n",
    "ic=beta1*ib\n",
    "vc=vcc-ic*1*10**3\n",
    "vce=vc-rb*(ic+ib)\n",
    "print \"emitter current   =   %0.2e\"%((ic+ib)),\"ampere\"\n",
    "print \"vc   =   %0.2f\"%((vc)),\"volt\"\n",
    "print \"collector emitter voltage   =   %0.2f\"%((vce)),\"volt\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 290 example 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   395.49\n"
     ]
    }
   ],
   "source": [
    "hib=25##ohm\n",
    "hfb=0.999\n",
    "hob=10**-6##ohm\n",
    "colres=10*10**3##ohm\n",
    "#voltage gain\n",
    "curgai=hfb/(1+hob*colres)\n",
    "zi=hib+hob*colres*curgai\n",
    "volgai=curgai*colres/(zi)\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "#correction required in the book"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 290 example 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   1.00\n",
      "input resistance   =   101050.00 ohm\n"
     ]
    }
   ],
   "source": [
    "re=1*10**3##ohm\n",
    "hie=100##ohm\n",
    "hfe=100\n",
    "#voltage gain\n",
    "volgai=1/((1+(hie/(2*(1+hfe)*re))))\n",
    "#ri\n",
    "ri=(hie/2)+(1+hfe)*re\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 292 example 11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "emitter current   =   4.16e-03 ampere\n",
      "vce   =   11.68 volt\n"
     ]
    }
   ],
   "source": [
    "beta1=90\n",
    "re=2*10**3##ohm\n",
    "rb=240*10**3##ohm\n",
    "vcc=20\n",
    "ib=(vcc-0.7)/(rb+(1+beta1)*(re))\n",
    "ic=beta1*ib\n",
    "vce=vcc-(ib+ic)*re\n",
    "print \"emitter current   =   %0.2e\"%((ib+ic)),\"ampere\"\n",
    "print \"vce   =   %0.2f\"%((vce)),\"volt\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 292 example 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   -313.90\n",
      "current gain   =   -100.55\n",
      "impedance   =   86666.67 ohm\n",
      "parameters using approxmiate\n",
      "voltage gain   =   -323.12\n",
      "current gain   =   -110.00\n",
      "impedance   =   86666.67 ohm\n"
     ]
    }
   ],
   "source": [
    "hfe=110\n",
    "hie=1.6*10**3##ohm\n",
    "hoe=20*10**-6##ohm\n",
    "colres=4.7*10**3##ohm\n",
    "hre=2*10**-4\n",
    "r1=470*10**3##ohm\n",
    "curgai=-hfe/(1+hoe*colres)\n",
    "ri=hie+hre*curgai*colres\n",
    "volgai=curgai*colres/ri\n",
    "y1=hoe-((hfe*hre)/(hie+1*10**3))\n",
    "z1=1/y1\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "print \"impedance   =   %0.2f\"%((z1)),\"ohm\"\n",
    "r0=z1*colres/(z1+colres)\n",
    "curgai=-hfe\n",
    "ri=hie\n",
    "print \"parameters using approxmiate\"\n",
    "volgai=curgai*(colres)/ri\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "#correction required in the book\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "print \"impedance   =   %0.2f\"%((z1)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 293 example 13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input resistance   =   1.00e+07 ohm\n",
      "voltage gain   =   1.00\n",
      "current gain   =   -10000.00\n"
     ]
    }
   ],
   "source": [
    "re=1*10**3##ohm\n",
    "hie=1000##ohm\n",
    "hfe=99\n",
    "#inptut resistance\n",
    "ri=hie+((1+hfe)*(hie+1+hfe*re))\n",
    "\n",
    "\n",
    "print \"input resistance   =   %0.2e\"%((ri)),\"ohm\"##correction in the book\n",
    "#voltage gain\n",
    "volgai=((1+hfe)*(1+hfe)*re)/ri\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "\n",
    "\n",
    "#current gain\n",
    "curgai=-((1+hfe)*(1+hfe))\n",
    "\n",
    "\n",
    "print \"current gain   =   %0.2f\"%((curgai))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 294 example 14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   250.00 <180\n",
      "input impedance   =   2000.00 ohm\n",
      "current gain   =   100.00\n"
     ]
    }
   ],
   "source": [
    "hie=2*10**3##ohm\n",
    "beta1=100\n",
    "colres=5*10**3##ohm\n",
    "volgai=beta1*colres/hie\n",
    "print \"voltage gain   =   %0.2f\"%((volgai)),\"<180\"\n",
    "print \"input impedance   =   %0.2f\"%((hie)),\"ohm\"\n",
    "print \"current gain   =   %0.2f\"%((beta1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 294 example 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   253.29\n",
      "input impedance   =   1546.39\n",
      "coordinates ic   =   1.14e-03 ampere vce   =  8.30 volt\n"
     ]
    }
   ],
   "source": [
    "colres=4.7*10**3##ohm\n",
    "beta1=150\n",
    "r1=12*10**3##ohm\n",
    "vcc=15##volt\n",
    "re=1.2*10**3##ohm\n",
    "rac=colres*r1/(colres+r1)\n",
    "r=2*10**3##ohm\n",
    "#voltage gain\n",
    "volgai=beta1*rac/r\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "r1=75*10**3##ohm\n",
    "r2=7.5*10**3##ohm\n",
    "#input impedance\n",
    "zin=(r1*r2)/(r1+r2)\n",
    "zin=zin*r/(zin+r)\n",
    "print \"input impedance   =   %0.2f\"%((zin))\n",
    "#coordinates\n",
    "vb=vcc*r2/(r1+r2)\n",
    "ie=vb/re\n",
    "vce=vcc-((colres+re)*(ie))\n",
    "print \"coordinates ic   =   %0.2e\"%((ie)),\"ampere vce   =  %0.2f\"%((vce)),\"volt\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 296 example 16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current gain   =   57.14\n",
      "input impedance   =   115485.71 ohm\n",
      "voltage gain   =   0.99\n",
      "output resistance   =   32558.14 ohm\n"
     ]
    }
   ],
   "source": [
    "r1=2000##ohm\n",
    "r=900##ohm\n",
    "hie=1200##ohm\n",
    "hre=2*10**-4\n",
    "hfe=60\n",
    "hoe=25*10**-6##ampere per volt\n",
    "curgai=(hfe)/(1+hoe*r1)\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "ri=hie+(curgai*r1)\n",
    "print \"input impedance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "volgai=curgai*r1/ri\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "admita=1/ri\n",
    "admita=hoe-(-hfe*hre)/(hie+r)\n",
    "r=1/admita\n",
    "print \"output resistance   =   %0.2f\"%((r)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 296 example 17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   -609.86\n",
      "current gain   =   -60.00\n",
      "input impedance   =   501.75 ohm\n",
      "output impedance   =   5100.00 ohm\n"
     ]
    }
   ],
   "source": [
    "hfe=60\n",
    "hie=500##ohm\n",
    "ic=3*10**-3##ampere\n",
    "zi=hie\n",
    "rb=220*10**3##ohm\n",
    "colres=5.1*10**3##ohm\n",
    "z=colres\n",
    "volgai=-hfe*colres/hie\n",
    "curgai=-hfe\n",
    "vcc=12##volt\n",
    "ib=(vcc-0.6)/rb\n",
    "ie=hfe*ib\n",
    "re=0.026/ie\n",
    "zi=hfe*re\n",
    "z=colres\n",
    "volgai=-colres/re\n",
    "curgai=-hfe\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "print \"input impedance   =   %0.2f\"%((zi)),\"ohm\"\n",
    "print \"output impedance   =   %0.2f\"%((z)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 297 example 18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input impedance   =   1817.30 ohm\n",
      "output impedance   =   4000.00 ohm\n",
      "voltage gain   =   -125.00\n",
      "current gain   =   -56.79\n",
      "parameters in re\n",
      "input impedance   =   1745.41 ohm\n",
      "output impedance   =   4000.00 ohm\n",
      "voltage gain   =   -134.07\n",
      "current gain   =   -58.50\n"
     ]
    }
   ],
   "source": [
    "hie=3.2*10**3##ohm\n",
    "hfe=100\n",
    "r=40*10**3##ohm\n",
    "r1=4.7*10**3##ohm\n",
    "colres=4*10**3##ohm\n",
    "rb=r*r1/(r+r1)\n",
    "zi=hie*rb/(hie+rb)\n",
    "z=colres\n",
    "re=1.2*10**3##ohm\n",
    "volgai=-hfe*colres/hie\n",
    "print \"input impedance   =   %0.2f\"%((zi)),\"ohm\"\n",
    "print \"output impedance   =   %0.2f\"%((z)),\"ohm\"\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "curgai=-hfe*rb/(rb+hie)\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "hie=833\n",
    "#(1) load open\n",
    "vi=1\n",
    "ib=vi/hie\n",
    "volgai=hfe*ib*1.5*10**3\n",
    "#load closed\n",
    "hoe=50\n",
    "r2=2*10**3##ohm\n",
    "ib=vi/(r2+hie)\n",
    "vb=1.682\n",
    "ib=(vb-0.6)/(rb+(1+hfe)*(re))\n",
    "ic=hfe*ib\n",
    "ie=ic+ib\n",
    "re=0.026/ie\n",
    "zi=rb*hfe*re/((rb)+(hfe*re))\n",
    "print \"parameters in re\"\n",
    "print \"input impedance   =   %0.2f\"%((zi)),\"ohm\"\n",
    "z=colres\n",
    "print \"output impedance   =   %0.2f\"%((z)),\"ohm\"\n",
    "volgai=colres/(-re)\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "curgai=-hfe*rb/(rb+hfe*re)\n",
    "print \"current gain   =   %0.2f\"%((curgai))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 299 example 19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   -0.006\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "hfe=120\n",
    "hie=0.02##ohm\n",
    "r1=5.8*10**3##ohm\n",
    "r=27*10**3##ohm\n",
    "colres=1.5*10**3##ohm\n",
    "re=330*10**3##ohm\n",
    "vcc=10##volt\n",
    "vb=vcc*r1/(r1+r)\n",
    "rb=(r*r1)/(r+r1)\n",
    "ib=(vb-0.7)/(rb+((1+hfe)*re))\n",
    "volgai=-hfe*ib*2*10**3\n",
    "print \"voltage gain   =   %0.3f\"%((volgai))\n",
    "#correction required in the book"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 300 example 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "upper frequency voltage gain   =   7.21e+06 hertz\n",
      "upper current gain   =   3.61e+06 hertz\n"
     ]
    }
   ],
   "source": [
    "freque=6*10**6##hertz\n",
    "hfe=50\n",
    "r1=500##ohm\n",
    "g=0.04\n",
    "rbb=100##ohm\n",
    "\n",
    "\n",
    "c1=10*10**-12##farad\n",
    "r=1000##ohm\n",
    "rbe=hfe/g\n",
    "ce=g/(2*3.14*freque)\n",
    "c1=ce+c1*(1+g*r)\n",
    "hie=rbb+rbe\n",
    "resist=(r1+rbb)*rbe/(r1+rbb+rbe)\n",
    "frequ2=1/(2*3.14*resist*c1)\n",
    "curgai=-hfe*r1/(r1+hie)\n",
    "volgai=(-hfe*r)/(r1+hie)\n",
    "q=volgai*frequ2\n",
    "print \"upper frequency voltage gain   =   %0.2e\"%(abs(q)),\"hertz\"##correction in the book\n",
    "q=curgai*frequ2\n",
    "print \"upper current gain   =   %0.2e\"%(abs(q)),\"hertz\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 301 example 21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current gain   =   -48.78\n",
      "input resistance   =   990.24 ohm\n",
      "voltage gain   =   -49.26\n",
      "output resistance   =   51428.57 ohm\n",
      "approximate\n",
      "current gain   =   -50.00\n",
      "input resistance   =   1000.00 ohm\n",
      "voltage gain   =   -50.00\n"
     ]
    }
   ],
   "source": [
    "hie=1*10**3##ohm\n",
    "hre=2*10**-4\n",
    "hoe=25*10**-6##ampere per volt\n",
    "hfe=50\n",
    "colres=1*10**3##ohm\n",
    "curgai=-hfe/(1+hoe*colres)\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "ri=hie-hfe*hre/(hoe+1/colres)\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "volgai=curgai*colres/ri\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "y1=hoe-((hfe*hre)/(hie+800))\n",
    "r1=1/y1\n",
    "print \"output resistance   =   %0.2f\"%((r1)),\"ohm\"\n",
    "#approximate\n",
    "print \"approximate\"\n",
    "curgai=-hfe\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "ri=hie\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "volgai=-hfe*colres/hie\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 301 example 22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "voltage gain   =   174.11\n"
     ]
    }
   ],
   "source": [
    "rb1=7.5*10**3##ohm\n",
    "rb2=6.8*10**3##ohm\n",
    "\n",
    "rb3=3.3*10**3##ohm\n",
    "re=1.3*10**3##ohm\n",
    "colres=2.2*10**3##ohm\n",
    "beta1=120\n",
    "vcc=18##volt\n",
    "vb1=rb3*vcc/(rb3+rb2+rb1)\n",
    "ie1=(vb1-0.7)/(re)\n",
    "re1=0.026/ie1\n",
    "re2=0.026/ie1\n",
    "volgai=colres/re2\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 302 example 23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "forced beta   =   114.29\n"
     ]
    }
   ],
   "source": [
    "vcc=5##volt\n",
    "colres=250##ohm\n",
    "v1=5##volt\n",
    "rb=25*10**3##ohm\n",
    "beta1=200\n",
    "vbs=0.8##volt\n",
    "vcon=0.3##volt\n",
    "icon=(vcc-vcon)/colres\n",
    "ibon=icon/beta1\n",
    "ibs=(v1-vbs)/rb\n",
    "ic=(vcc-0.2)/colres\n",
    "beta1=ic/ibs\n",
    "print \"forced beta   =   %0.2f\"%((beta1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 303 example 24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "resistance r1   =   40847.46 ohm\n",
      "resistance r3   =   2197.00 ohm\n"
     ]
    }
   ],
   "source": [
    "vb=0.6##volt\n",
    "beta1=100\n",
    "ic=1*10**-3##ampere\n",
    "vce=2.5##volt\n",
    "re=300##ohm\n",
    "vcc=5##volt\n",
    "ib=ic/beta1\n",
    "ie=ic+ib\n",
    "ve=ie*re\n",
    "vce=vce+ve\n",
    "r3=(vcc-vce)/ic\n",
    "vb=ve+vb\n",
    "r1=(vcc-vb)/(vb/(10*10**3)+(ib))\n",
    "print \"resistance r1   =   %0.2f\"%((r1)),\"ohm\"\n",
    "print \"resistance r3   =   %0.2f\"%((r3)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 304 example 25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input impedance q1   =   1.75e+04 ohm\n",
      "input impedance q2   =   3.50e+06 ohm\n"
     ]
    }
   ],
   "source": [
    "vce2=7.5##volt\n",
    "vb=0.7##volt\n",
    "beta1=200\n",
    "v1=25##volt\n",
    "r1=10*10**3##ohm\n",
    "vcc=15##volt\n",
    "i1=(vcc-vb)/r1\n",
    "r=(vcc-vce2)/i1\n",
    "z1=beta1*v1/i1\n",
    "z=v1/i1\n",
    "print \"input impedance q1   =   %0.2e\"%((z)),\"ohm\"##correction in the book\n",
    "print \"input impedance q2   =   %0.2e\"%((z1)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 305 example 26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "make input   =   0\n",
      "ground dc\n",
      "output resistance   =   19.61 ohm\n"
     ]
    }
   ],
   "source": [
    "beta1=99\n",
    "r1=1*10**3##ohm\n",
    "g=beta1/r1\n",
    "r=r1*((r1+r1)/(100))/((r1+((r1+r1)/(100))))\n",
    "print \"make input   =   0\"\n",
    "print \"ground dc\"\n",
    "print \"output resistance   =   %0.2f\"%((r)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 305 example 27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output resistance   =   1000.00 ohm\n",
      "input resistance very low\n",
      "voltage gain   =   19.23\n"
     ]
    }
   ],
   "source": [
    "ic=0.5*10**-3##ampere\n",
    "rb=100*10**3##ohm\n",
    "v1=0.026##volt\n",
    "r1=50##ohm\n",
    "colres=1*10**3##ohm\n",
    "g=ic/v1\n",
    "volgai=g*colres\n",
    "print \"output resistance   =   %0.2f\"%((colres)),\"ohm\"\n",
    "print \"input resistance very low\"##not given in the book\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 306 example 28"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "current gain   =   -12.27\n",
      "voltage gain   =   -49.07\n",
      "transconductance   =   -0.01 ampere per volt\n",
      "transresistance   =   -490686.77 ohm\n",
      "input resistance   =   990.99 ohm\n",
      "output resistance   =   4444.44 ohm\n"
     ]
    }
   ],
   "source": [
    "re=4*10**3##ohm\n",
    "r1=4*10**3##ohm\n",
    "hie=1.1*10**3##ohm\n",
    "resist=10*10**3##ohm\n",
    "hfe=50\n",
    "rb=10*10**3##ohm\n",
    "r=1*10**3##ohm\n",
    "colres=5*10**3##ohm\n",
    "#(1) current gain\n",
    "ri=rb*hie/(rb+hie)\n",
    "curgai=(1/2.04)*((rb)/(rb+hie))*((-hfe*colres)/(colres+r1))\n",
    "print \"current gain   =   %0.2f\"%((curgai))\n",
    "#(2) voltage gain\n",
    "volgai=curgai*r1/r\n",
    "print \"voltage gain   =   %0.2f\"%((volgai))\n",
    "#(3) tranconductance\n",
    "conduc=volgai/r1\n",
    "print \"transconductance   =   %0.2f\"%((conduc)),\"ampere per volt\"\n",
    "#transresistance\n",
    "resist=resist*volgai\n",
    "print \"transresistance   =   %0.2f\"%((resist)),\"ohm\"\n",
    "print \"input resistance   =   %0.2f\"%((ri)),\"ohm\"\n",
    "r=(40*10**3*colres)/(40*10**3+colres)\n",
    "print \"output resistance   =   %0.2f\"%((r)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 307 example 29"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "base resistance   =   235000.00 ohm\n",
      "base resistance with re\n",
      "base resistance   =   230000.00 ohm\n"
     ]
    }
   ],
   "source": [
    "beta1=500\n",
    "ib=20*10**-6##ampere\n",
    "re=100##ohm\n",
    "ic=beta1*ib\n",
    "vc=ic*0.47*10**3##voltage drop across collector resistance\n",
    "v1=(10-vc)\n",
    "vb=v1-0.6\n",
    "rb=vc/ib\n",
    "print \"base resistance   =   %0.2f\"%((rb)),\"ohm\"\n",
    "ve=re*ic\n",
    "print \"base resistance with re\"\n",
    "b=0.6+0.1\n",
    "rb=(v1-b)/ib\n",
    "print \"base resistance   =   %0.2f\"%((rb)),\"ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PageNumber 308 example 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "collector current   =   3.00e-03 ampere\n",
      "base current   =   3.00e-05 ampere\n",
      "emitter current   =   3.00e-03 ampere\n"
     ]
    }
   ],
   "source": [
    "beta1=100\n",
    "re=100##ohm\n",
    "vcc=10##volt\n",
    "colres=1.5*10**3##ohm\n",
    "r=100*10**3##ohm\n",
    "r1=10*10**3##ohm\n",
    "vb=vcc*r1/(r1+r)\n",
    "ie=0.3/re\n",
    "ib=ie/beta1\n",
    "print \"collector current   =   %0.2e\"%((ie)),\"ampere\"\n",
    "print \"base current   =   %0.2e\"%((ib)),\"ampere\"\n",
    "print \"emitter current   =   %0.2e\"%((ie)),\"ampere\""
   ]
  }
 ],
 "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
}