{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 11 Digital To Analog Converter(D/A Converter)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.1 Pg 313"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the full scale voltage of D/A converter VFS is = 24.00  V \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt, pi\n",
    "# to determine the full scale voltage of D/A\n",
    "Vref = 12 #\n",
    "Rf = 10 # # K ohm\n",
    "R = 5 # # K ohm\n",
    "\n",
    "# the full scale voltage of D/A converter \n",
    "VFS = Vref*(Rf/R) #\n",
    "print 'the full scale voltage of D/A converter VFS is = %0.2f'%VFS,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.2 Pg 313"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For BI 10101010 the output of D/A converter is =  2.04  V \n",
      "For BI 11001100 the output of D/A converter is =  2.448  V \n",
      "For BI 11101110 the output of D/A converter is =  2.856  V \n",
      "For BI 00010001 the output of D/A converter is =  0.204  V \n"
     ]
    }
   ],
   "source": [
    " # determine the output voltage of D/A converter for the binary inputs a) 10101010  b) 11001100  c) 11101110 d) 00010001  \n",
    "Del = 12*10**-3 #  # mA\n",
    "\n",
    "# the input voltage of D/A converter \n",
    " #Vo = Del*binary input (BI)\n",
    "\n",
    "# For BI 10101010 the output\n",
    "BI = '10101010' #\n",
    "BI = int(BI,2)#\n",
    "Vo = Del*BI #\n",
    "print 'For BI 10101010 the output of D/A converter is = ',Vo,' V '\n",
    "\n",
    "# For BI 11001100 the output\n",
    "BI = '11001100' #\n",
    "BI = int(BI,2)#\n",
    "Vo = Del*BI #\n",
    "print 'For BI 11001100 the output of D/A converter is = ',Vo,' V '\n",
    "\n",
    "# For BI 11101110 the output\n",
    "BI = '11101110' #\n",
    "BI = int(BI,2)#\n",
    "Vo = Del*BI #\n",
    "print 'For BI 11101110 the output of D/A converter is = ',Vo,' V '\n",
    "\n",
    "# For BI 00010001 the output\n",
    "BI = '00010001' #\n",
    "BI = int(BI,2)#\n",
    "Vo = Del*BI #\n",
    "print 'For BI 00010001 the output of D/A converter is = ',Vo,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.3 Pg 314"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the resolution of 4-bit D/A converter is = 0.80  V \n"
     ]
    }
   ],
   "source": [
    "# determine the resolution of 4-bit D/A converter\n",
    "VFS = 12 #\n",
    "N = 4 #\n",
    "\n",
    "# the resolution of 4-bit D/A converter is defined as\n",
    "Resolution = VFS/(2**N-1) #\n",
    "print 'the resolution of 4-bit D/A converter is = %0.2f'%Resolution,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.4 314"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the number of bit required to design a 4-bit D/A converter is = 8.97    = 9 \n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# determine the number of bit required to design a 4-bit D/A converter\n",
    "VFS = 5 #\n",
    "Resolution = 10*10**-3 # # A\n",
    "\n",
    "# the resolution of 4-bit D/A converter is defined as\n",
    "# Resolution = VFS/(2**N-1) #\n",
    "N = (VFS/Resolution)+1 #   \n",
    "N = log10(N)/log10(2)#\n",
    "print 'the number of bit required to design a 4-bit D/A converter is = %0.2f'%N,'   = 9 '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.5 Pg 315"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 101 analog output is = -60.00  V \n",
      "for the binary input 111 analog output is = -84.00  V \n",
      "for the binary input 011 analog output is = -72.00  V \n",
      "for the binary input 001 analog output is = -48.00  V \n",
      "for the binary input 100 analog output is = -12.00  V\n"
     ]
    }
   ],
   "source": [
    "# determine the analog output voltage\n",
    "Vref = 12  #   \n",
    "BI = 101 #   BI = 111 #   BI = 011 # BI = 001 #  BI = 100 #\n",
    "Rf = 40*10**3 #\n",
    "R = 0.25*Rf #\n",
    "\n",
    "# The output voltage of given binary weighted resistor D/A converter is defined as\n",
    "\n",
    "# Vo = -(Rf*Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# Vo = -(Rf*Vref/R)*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the given value Rf,R and Vref the output voltage\n",
    "\n",
    "# Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the binary input 101 analog output is\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 101 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 111 analog output is\n",
    "b2 = 1 #\n",
    "b1 = 1 #\n",
    "b0 = 1 #\n",
    "Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 111 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 011 analog output is\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 1 #\n",
    "Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 011 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 001 analog output is\n",
    "b2 = 0 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 001 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 100 analog output is\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 0 #\n",
    "Vo = -48*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 100 analog output is = %0.2f'%Vo,' V'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.6 Pg 316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 1001 analog output is = -67.50  V \n",
      "the feedback current If is = 2.70  mA \n",
      "for the binary input 1101 analog output is = -82.50  V \n",
      "the feedback current If is = 3.30  mA \n",
      "for the binary input 1010 analog output is = -37.50  V \n",
      "the feedback current If is = 1.50  mA \n",
      "for the binary input 0011 analog output is = -90.00  V \n",
      "the feedback current If is = 3.60  mA \n"
     ]
    }
   ],
   "source": [
    "# determine the analog output voltage and feed back current If\n",
    "Vref = 12  #   \n",
    "BI = 1001 #   BI = 1101 #   BI = 1010 # BI = 0011 #\n",
    "Rf = 25 #  # K ohm\n",
    "R = 0.25*Rf #\n",
    "\n",
    "# The output voltage of given binary weighted resistor D/A converter is defined as\n",
    "\n",
    "# Vo = -(Rf*Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# Vo = -(Rf*Vref/R)*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# for the given value Rf,R and Vref the output voltage\n",
    "\n",
    "# Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# for the binary input 1001 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 0 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1001 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 1101 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1101 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 1010 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 0 #\n",
    "Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1010 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 0011 analog output is\n",
    "b3 = 0 #\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 1 #\n",
    "Vo = -60*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 0011 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.7 Pg 319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 001 analog output is = 1.60  mA \n",
      "An analog output voltage Vo is = -40.00  V \n",
      "for the binary input 010 analog output is = 0.80  mA\n",
      "An analog output voltage Vo is = -20.00  V \n",
      "for the binary input 110 analog output is = 1.20  mA \n",
      "An analog output voltage Vo is = -30.00  V \n"
     ]
    }
   ],
   "source": [
    "# determine the feed back current If and analog output voltage\n",
    "Vref = 8  #   # V\n",
    "BI = 001 #\n",
    "BI = 010 #\n",
    "BI = 110 #\n",
    "Rf = 25*10**3 # # Hz\n",
    "R = 0.2*Rf #\n",
    "\n",
    "# The output current of given binary weighted resistor D/A converter is defined as\n",
    "\n",
    "# If = -(Vref/R)*(2**0*b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# If = -(Vref/R)*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the given value Rf,R and Vref the output current\n",
    "\n",
    "# If = -(1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the binary input 001 the feedback current If is given by\n",
    "b2 = 0 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 001 analog output is = %0.2f'%(If*1000),' mA '\n",
    "\n",
    "# An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 010 the feedback current If is given by\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 0 #\n",
    "If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 010 analog output is = %0.2f'%(If*1000),' mA'\n",
    "\n",
    "# the An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.2f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 110 the feedback current If is given by\n",
    "b2 = 1 #\n",
    "b1 = 1 #\n",
    "b0 = 0 #\n",
    "If = (1.6*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 110 analog output is = %0.2f'%(If*1000),' mA '\n",
    "\n",
    "# the An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.2f'%Vo,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.8 Pg 320"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 101 analog output is = 0.625  mA \n",
      "An analog output voltage Vo is = -15.625  V \n",
      "for the binary input 011 analog output is = 0.75  mA\n",
      "An analog output voltage Vo is = -18.750  V \n",
      "for the binary input 100 analog output is = 0.125 mA \n",
      "An analog output voltage Vo is = -3.12  V \n",
      "for the binary input 001 analog output is = 0.5  mA \n",
      "An analog output voltage Vo is = -12.50  V \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# determine the feed back current If and analog output voltage\n",
    "Vref = 5  #   \n",
    "BI = 101 #   BI = 011 #   BI = 100 #  BI = 001 #\n",
    "Rf = 25*10**3 # \n",
    "R = 0.2*Rf #\n",
    "\n",
    "# The output current of given R-2R ladder D/A converter is defined as\n",
    "\n",
    "# If = -(Vref/2*R)*(2**0*b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# If = -(Vref/2*R)*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the given value Rf,R and Vref the output current\n",
    "\n",
    "# If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "\n",
    "# for the binary input 101 the feedback current If is given by\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 101 analog output is = %0.3f'%(If*1e3),' mA '\n",
    "\n",
    "# An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.3f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 011 the feedback current If is given by\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 1 #\n",
    "If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 011 analog output is = %0.2f'%(If*1e3),' mA'\n",
    "\n",
    "# the An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.3f'%Vo,' V '\n",
    "\n",
    "\n",
    "# for the binary input 100 the feedback current If is given by\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 0 #\n",
    "If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 100 analog output is = %0.3f'%(If*1e3),'mA '\n",
    "\n",
    "# the An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.2f'%Vo,' V '\n",
    "\n",
    "# for the binary input 001 the feedback current If is given by\n",
    "b2 = 0 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "If = (0.5*10**-3)*(b0+2**-1*b1+2**-2*b2) #\n",
    "print 'for the binary input 001 analog output is = %0.1f'%(If*1e3),' mA '\n",
    "\n",
    "# the An analog output voltage Vo is\n",
    "Vo = -If*Rf #\n",
    "print 'An analog output voltage Vo is = %0.2f'%Vo,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.9 Pg 322"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 1001 analog output is = -14.0625  V \n",
      "the feedback current If is = 0.28  mA \n",
      "for the binary input 1100 analog output is = -4.6875  V \n",
      "the feedback current If is = 0.09  mA \n",
      "for the binary input 1010 analog output is = -7.8125  V \n",
      "the feedback current If is = 0.16  mA \n",
      "for the binary input 0011 analog output is = -18.75  V \n",
      "the feedback current If is = 0.375  mA \n"
     ]
    }
   ],
   "source": [
    " # determine the analog output voltage and feed back current If\n",
    "Vref = 10  #   \n",
    "BI = 1001 #   BI = 1100 #   BI = 1010 # BI = 0011 #\n",
    "Rf = 50 #  # K ohm\n",
    "R = 0.4*Rf #\n",
    "\n",
    "# The output voltage of given R-2R ladder D/A converter is defined as\n",
    "\n",
    "# Vo = -(Rf*Vref/2R)*(2**0*b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# Vo = -(Rf*Vref/2R)*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# for the given value Rf,R and Vref the output voltage\n",
    "\n",
    "# Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "\n",
    "# for the binary input 1001 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 0 #\n",
    "b1 = 0 #\n",
    "b0 = 1 #\n",
    "Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1001 analog output is = %0.4f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 1100 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 1 #\n",
    "b1 = 0 #\n",
    "b0 = 0 #\n",
    "Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1100 analog output is = %0.4f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 1010 analog output is\n",
    "b3 = 1 #\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 0 #\n",
    "Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 1010 analog output is = %0.4f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.2f'%If,' mA '\n",
    "\n",
    "\n",
    "# for the binary input 0011 analog output is\n",
    "b3 = 0 #\n",
    "b2 = 0 #\n",
    "b1 = 1 #\n",
    "b0 = 1 #\n",
    "Vo = -12.5*(b0+2**-1*b1+2**-2*b2+2**-3*b3) #\n",
    "print 'for the binary input 0011 analog output is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.3f'%If,' mA '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.10 Pg 324"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the binary input 1000 output voltage is = 18.75  V \n",
      "the feedback current If is = -0.469  mA \n"
     ]
    }
   ],
   "source": [
    " # determine the analog output voltage and feed back current If\n",
    "Vref = 15  #   \n",
    "BI = 1000 #\n",
    "Rf = 40 #  # K ohm\n",
    "R = 0.4*Rf #\n",
    "\n",
    "# by using voltage divider rule Vin can be calculated as\n",
    "Vin = -(Vref*2*R)/(2*R+2*R) #\n",
    " \n",
    "# The output voltage of given R-2R ladder D/A converter is defined as\n",
    "\n",
    "# Vo = -(Rf*Vin/R)\n",
    "\n",
    "Vo = (Vref*Rf)/(2*R)\n",
    "print 'for the binary input 1000 output voltage is = %0.2f'%Vo,' V '\n",
    "\n",
    "# the feedback current If is given by\n",
    "If = -(Vo/Rf) #\n",
    "print 'the feedback current If is = %0.3f'%If,' mA '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11.11 Pg 326"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For the BI 10101111 output analog voltage is = 6.86  V \n",
      "For the BI 11100010 output analog voltage is = 8.8627  V \n",
      "For the BI 00101001 output analog voltage is = 1.6078  V \n",
      "For the BI 01000110 output analog voltage is = 2.745  V \n"
     ]
    }
   ],
   "source": [
    "# to find the resolution and analog output voltage of 8-bit D/A converter\n",
    "VFS = 10 #\n",
    "N = 8 #\n",
    "BI = 10101111 #\n",
    "BI = 11100011 # \n",
    "BI = 00101001 #\n",
    "BI = 01000110\n",
    "\n",
    "# the resolution of 8-bit D/A converter is defined as\n",
    "Resolution = VFS/(2**N-1) #\n",
    "\n",
    "# An analog output voltage of D/A converter is given by\n",
    "# Vo = Resolution*(2**-0*b0+2**-1*b1+....+2**-N*bn-1)\n",
    "# Vo = Resolution*(2**-0*b0+2**-1*b1+2**-2*b2+2**-3*b3+2**-4*b4+2**-5*b5+2**-6*b6+2**-7*b7)#\n",
    "\n",
    "# For the BI 10101111 output analog voltage is\n",
    "BI = '10101111'#\n",
    "BI = int(BI,2)#\n",
    "Vo = Resolution*BI #\n",
    "print 'For the BI 10101111 output analog voltage is = %0.2f'%Vo,' V '\n",
    "\n",
    "# For the BI 11100010 output analog voltage is\n",
    "BI = '11100010'#\n",
    "BI = int(BI,2)#\n",
    "Vo = Resolution*BI #\n",
    "print 'For the BI 11100010 output analog voltage is = %0.4f'%Vo,' V '\n",
    "\n",
    "# For the BI 00101001 output analog voltage is\n",
    "BI = '00101001'#\n",
    "BI = int(BI,2)#\n",
    "Vo = Resolution*BI #\n",
    "print 'For the BI 00101001 output analog voltage is = %0.4f'%Vo,' V '\n",
    "\n",
    "# For the BI 01000110 output analog voltage is\n",
    "BI = '01000110'#\n",
    "BI = int(BI,2)#\n",
    "Vo = Resolution*BI #\n",
    "print 'For the BI 01000110 output analog voltage is = %0.3f'%Vo,' V '"
   ]
  }
 ],
 "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
}