{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 4:ANALOG ELECTRONIC VOLT-OHM-MILLIAMMETER"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-1, Page Number 88"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "When E=10 V, meter current is 1 mA\n",
      "\n",
      "Input Impedance,\n",
      "with transistor= 1.0 mega ohm\n",
      "without transistor= 9.3 kilo ohm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "Vcc=20              #Supply Voltage(V)\n",
    "Rsm=9.3*10**3       #Rsm=Rs+Rm(ohm)\n",
    "Im=1*10**-3         #Emitter Current(A)\n",
    "hfe=100             #Transistor h parameter\n",
    "Vb1=0.7             #Base Emitter Voltage drop(V)\n",
    "#Calculation\n",
    "#To obtain meter current when E=10V\n",
    "E=10                #Base input voltage(V)\n",
    "Ve=E-Vb1            #Emitter Voltage(V) found using KVL aclong base loop\n",
    "Im=Ve/Rsm           #Emitter current \n",
    "\n",
    "#With the transistor\n",
    "Ib=Im/hfe           #Base current is approximately equlat to Ie/hfe\n",
    "Ri=E/Ib             #Input resistance with transistor\n",
    "\n",
    "#Without transistor\n",
    "Ri1=Rsm             #Input resistance without transistor\n",
    "\n",
    "#Results\n",
    "\n",
    "print \"When E=10 V, meter current is\",int(Im*10**3),\"mA\"\n",
    "print \n",
    "print \"Input Impedance,\"\n",
    "print \"with transistor=\",round(Ri/10**6),\"mega ohm\"\n",
    "print \"without transistor=\",Ri1/10**3,\"kilo ohm\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-2, Page Number 89"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "When E=0V, I2=I3= 2.9 mA\n",
      "When E=1V, meter circuit voltage(V)= 1.0 V\n",
      "When E=0.5, meter circuit voltage= 0.5 V\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "R2=3.9*10**3           #in ohm\n",
    "R3=3.9*10**3           #in ohm\n",
    "Vcc=12                 #in V\n",
    "Vee=-12                #in V \n",
    "Vbe=0.7                #Base Emitter voltage in V\n",
    "\n",
    "#Calculation \n",
    "\n",
    "#When E=0\n",
    "E=0                         \n",
    "Vr2=E-Vbe-Vee          #KVL \n",
    "Vr3=E-Vbe-Vee          #KVL\n",
    "I2=Vr2/R2              #Ohm's Law\n",
    "I3=I2               \n",
    "\n",
    "print \"When E=0V, I2=I3=\",round(I3*10**3,1),\"mA\"\n",
    "\n",
    "#When E=1\n",
    "E=1                   #in V\n",
    "Vp=0                  #in V\n",
    "Ve1=E-Vbe             #KVL\n",
    "Ve2=Vp-Vbe            #KVL\n",
    "V=Ve1-Ve2             #KVL\n",
    "print \"When E=1V, meter circuit voltage(V)=\",V,\"V\"\n",
    "\n",
    "#When E=0.5\n",
    "E=0.5                 #in V\n",
    "Vp=0                  #in V\n",
    "Ve1=E-Vbe             #KVL \n",
    "Ve2=Vp-Vbe            #KVL\n",
    "V=Ve1-Ve2             #KVL  \n",
    "print \"When E=0.5, meter circuit voltage=\",V,\"V\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-3, Page Number: 93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Im is 0.75 which is 75.0 % of full scale\n",
      "As the meter is in 10V range, 75% of full scale is 7.5 V\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "E=7.5                      #in V\n",
    "Vgs=-5                     #FET gate source voltage in V\n",
    "Vp=5                       #in V\n",
    "Rsm=1*10**3                #Rs+Rm in ohm\n",
    "Im=1*10**-3                #in A\n",
    "Ra=800*10**3               #in ohm\n",
    "Rb=100*10**3               #in ohm\n",
    "Rc=60*10**3                #in ohm\n",
    "Rd=40*10**3                #in ohm\n",
    "\n",
    "Eg=E*(Rc+Rd)/(Ra+Rb+Rc+Rd) #Voltage Divider Rule \n",
    "Vs=Eg-Vgs                  #KVL              \n",
    "\n",
    "Ve1=Vs-Vbe                 #KVL \n",
    "Ve2=Vp-Vbe                 #KVL\n",
    "V=Ve1-Ve2                  #KVL\n",
    "Im=V/Rsm                   #Ohm's Law\n",
    "\n",
    "print \"Im is\",round(Im*10**3,2),\"which is\",round(Im*10**3,2)*100,\"% of full scale\"\n",
    "print \"As the meter is in 10V range, 75% of full scale is\",10*0.75,\"V\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-4, Page Number: 97"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R3= 100.0 ohm\n",
      "R4= 4.9 kilo ohm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "Im=100*10**-6            #Full scale current in A\n",
    "Rm=10*10**3              #Meter resistance in ohm \n",
    "Ib=0.2*10**-6            #Op-amp input current in A\n",
    "E=20*10**-3              #Maximum input in V\n",
    "\n",
    "#Calculations\n",
    "\n",
    "I4=1000*Ib               #Since I4>>Ib\n",
    "Vout=Im*Rm               #Ohm's Law  \n",
    "\n",
    "R3=E/I4                  #Ohm's Law  \n",
    "R4=(Vout-E)/I4           #Ohm's Law\n",
    "\n",
    "#Results\n",
    "\n",
    "print \"R3=\",R3,\"ohm\"\n",
    "print \"R4=\",round(R4*10**-3,1),\"kilo ohm\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-5, Page Number: 98"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R3= 1.0 kilo Ohm\n",
      "Maximum voltage at output terminal= 1.1 V\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "E=1.0                #in V\n",
    "I=1*10**-3           #in A\n",
    "Rm=100               #in ohm\n",
    "\n",
    "R3=E/I               #Ohm's Law\n",
    "Vo=I*(R3+Rm)         #Maximum Output voltage\n",
    "\n",
    "print \"R3=\",R3/1000,\"kilo Ohm\"\n",
    "print \"Maximum voltage at output terminal=\",round(Vo,1),\"V\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4-7, Page Number: 107"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R3= 45.0 ohm\n",
      "When input is 50mV, meter deflection is 0.5 mA(half scale)\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "Iav=1*10**-3                          #in A \n",
    "Rm=1.2*10**3                          #in ohm\n",
    "E=100*10**-3                          #in V\n",
    "\n",
    "#With half wave rectifiers,\n",
    "Ip=2*Iav/0.637                        #Using relation between Ip and Iav for HWR\n",
    "\n",
    "#Peak value of Er3=input peak voltage\n",
    "Ep=E/0.707                            #Relation between peak voltage and rms \n",
    "R3=Ep/Ip                              #in ohm\n",
    "print \"R3=\",round(R3),\"ohm\"\n",
    "\n",
    "#When E=50mV\n",
    "E=50*10**-3                           #in V\n",
    "Ep=E/0.707                            #Peak Voltage in V \n",
    "Ip=Ep/R3                              #Peak current in A \n",
    "\n",
    "Iav=0.637*Ip/2                        #Average Current in A\n",
    "\n",
    "print \"When input is 50mV, meter deflection is\",round(Iav*10**3,1),\"mA(half scale)\"\n"
   ]
  }
 ],
 "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
}