{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : Digital Instruments"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.1\n",
      " : Page No - 4.5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "#Given data\n",
      "Vi = 5.1 #input voltage in V\n",
      "n = 8 # number of bit\n",
      "Resolution = 2**n \n",
      "Resolution = Vi/(Resolution-1) # in V/LSB\n",
      "Resolution= Resolution*10**3 # in mV/LSB\n",
      "print \"The Resolution = %0.f mV/LSB \" %Resolution\n",
      "Resolution= Resolution*10**-3 # in V/LSB\n",
      "Vi = 1.28 # in V\n",
      "D = Vi/Resolution #digital output in LSBs\n",
      "DigitalOutput= bin(int(D)) # digital output in binary\n",
      "print \"The binary equivalent digital output = \" ,DigitalOutput\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Resolution = 20 mV/LSB \n",
        "The binary equivalent digital output =  0b1000000\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.2\n",
      " : Page No - 4.5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "n = 12 #number of bit\n",
      "Vi = 4.095 #input voltage in V\n",
      "Q_E = Vi/(((2**n)-1)*2) #quantizing error in V\n",
      "Q_E = Q_E * 10**3 # in mV\n",
      "print \"The quantizing error = %0.1f mV \" %Q_E"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The quantizing error = 0.5 mV \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.3\n",
      " : Page No - 4.10"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "# When Vi=100 mV\n",
      "Vi = 100 # in mV\n",
      "V_R = 100 # in mV\n",
      "t1 = 83.33 # in ms\n",
      "t2 = (Vi/V_R)*t1 # in ms\n",
      "print \"When Vi=100 mV, the value of t2 = %0.2f ms \" %t2\n",
      "# When Vi=200 mV\n",
      "Vi = 200 # in mV\n",
      "t2 = (Vi/V_R)*t1 # in ms\n",
      "print \"When Vi=200 mV, the value of t2 = %0.1f ms \" %t2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "When Vi=100 mV, the value of t2 = 83.33 ms \n",
        "When Vi=200 mV, the value of t2 = 166.7 ms \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.4\n",
      " : Page No - 4.10"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "t1 = 83.33 # in ms\n",
      "V_R = 100 # in mV\n",
      "Vi = 100 # in mV\n",
      "fc = 12 #clock frequency in kHz\n",
      "fc = fc* 10**3 # in Hz\n",
      "Digitaloutput = round(fc*t1*(Vi/V_R)*10**-3) #digital output in counts \n",
      "print \"The Digital output = %0.f counts \" %Digitaloutput"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Digital output = 1000 counts \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.5\n",
      " : Page No - 4.13"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "f = 1 # in MHz\n",
      "f = f * 10**6 # in Hz\n",
      "T = 1/f # in sec\n",
      "T = T * 10**6 # in \u00b5sec\n",
      "n = 8 \n",
      "# Conversion time \n",
      "T_C = T*(n+1) # in \u00b5sec\n",
      "print \"The conversion time = %0.f \u00b5sec \" %T_C"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The conversion time = 9 \u00b5sec \n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.6\n",
      " : Page No - 4.15"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi\n",
      "#Given data\n",
      "n = 8 # number of bit\n",
      "T_C = 9 #conversion time in \u00b5s\n",
      "T_C = T_C * 10**-6 # in s\n",
      "# The maximum frequency \n",
      "f_max = 1/(2*pi*T_C*(2**n)) # in Hz\n",
      "print \"The maximum frequency = %0.2f Hz \" %f_max"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The maximum frequency = 69.08 Hz \n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.7\n",
      " : Page No - 4.39 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "n = 3 # number of bit\n",
      "R = 1/(10**n) \n",
      "V = 1 # in V\n",
      "# For 1V range,\n",
      "Resolution = V*R # in V\n",
      "print \"For 1 V range, the resolution = %0.3f V \" %Resolution\n",
      "# For 50 V range,\n",
      "V = 50 # in V\n",
      "Resolution = V*R # in V\n",
      "print \"For 50 V range, the resolution = %0.2f V \" %Resolution"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For 1 V range, the resolution = 0.001 V \n",
        "For 50 V range, the resolution = 0.05 V \n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example - 4.8\n",
      " : Page No - 4.39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given data\n",
      "n = 4 # number of bit\n",
      "R = 1/(10**n) \n",
      "print \"Part (i) : The resolution = %0.4f \" %R\n",
      "# There are 5 digit places in 4 1/2 digits, so\n",
      "print \"Part (ii) : 11.87 would be displayed as 11.870\"\n",
      "Reading= 0.5573 \n",
      "print \"Part (iii) : On 1 V range, 0.5573 will be displayed as = %0.3f \" %Reading\n",
      "print \"On 10 V range, 0.5573 will be displayed as = %0.4f  \" %Reading"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i) : The resolution = 0.0001 \n",
        "Part (ii) : 11.87 would be displayed as 11.870\n",
        "Part (iii) : On 1 V range, 0.5573 will be displayed as = 0.557 \n",
        "On 10 V range, 0.5573 will be displayed as = 0.5573  \n"
       ]
      }
     ],
     "prompt_number": 14
    }
   ],
   "metadata": {}
  }
 ]
}