{
 "metadata": {
  "name": "",
  "signature": "sha256:7f84289e42d01b19d3ca56822b4d2fb25574e2434ae2096a05b0c50827f2c4a4"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter -5 Waveform Generators"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.1 - Page 143"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C= 0.01 # in \u00b5F\n",
      "C=C*10**-6 # in F\n",
      "R_A= 2 # in k\u03a9\n",
      "R_A=R_A*10**3 # in \u03a9\n",
      "R_B= 100 # in k\u03a9\n",
      "R_B=R_B*10**3 # in \u03a9\n",
      "T_HIGH= 0.693*(R_A+R_B)*C #charging period in second\n",
      "T_LOW= 0.693*R_B*C # discharging period in second\n",
      "T= T_HIGH+T_LOW # overall period of oscillations in second\n",
      "f= 1/T # frequency of oscillations in Hz\n",
      "D= T_HIGH/T*100 # duty cycle in %\n",
      "print \"The frequency of oscillations = %0.1f Hz\" %f\n",
      "print \"Duty cycle = %0.1f %%\" %D"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency of oscillations = 714.4 Hz\n",
        "Duty cycle = 50.5 %\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2 - Page 143"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C= 1 # in \u00b5F\n",
      "C=C*10**-6 # in F\n",
      "R_A= 4.7 # in k\u03a9\n",
      "R_A=R_A*10**3 # in \u03a9\n",
      "R_B= 1 # in k\u03a9\n",
      "R_B=R_B*10**3 # in \u03a9\n",
      "T_on= 0.693*(R_A+R_B)*C #positive pulse width in second\n",
      "T_on= T_on*10**3 # in ms\n",
      "T_off= 0.693*R_B*C # pulse width in second\n",
      "T_off= T_off*10**3 # in ms\n",
      "f= 1.4/((R_A+2*R_B)*C) # free running frequency in Hz\n",
      "D= round((R_A+R_B)/(R_A+2*R_B)*100) # in %\n",
      "print \"The positive pulse width = %0.2f ms\" %T_on\n",
      "print \"The negative pulse width = %0.3f ms\" %T_off\n",
      "print \"The frequency of oscillations = %0.1f Hz\" %f\n",
      "print \"Duty cycle = %0.f %%\" %D"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The positive pulse width = 3.95 ms\n",
        "The negative pulse width = 0.693 ms\n",
        "The frequency of oscillations = 209.0 Hz\n",
        "Duty cycle = 85 %\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3 - Page 144"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C= 0.01 # in \u00b5F\n",
      "C= C*10**-6 # in F\n",
      "f= 1 # in kHz\n",
      "f= f*10**3 # in Hz\n",
      "# For 50% duty cycle, Ton= Toff = T/2 and R_A= R_B\n",
      "# From equation, f= 1.44/((R_A+R_B)*C)= 1.44/(2*R_A*C)\n",
      "R_A= 1.44/(2*f*C) # in \u03a9\n",
      "R_A= R_A*10**-3 # in k\u03a9\n",
      "R_B= R_A # in k\u03a9\n",
      "print \"The value of R_A and R_B = %0.f k\u03a9 (Standard value 68 k\u03a9)\" %R_A\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R_A and R_B = 72 k\u03a9 (Standard value 68 k\u03a9)\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4 - Page 144"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "f= 700 # in Hz\n",
      "C= 0.01 # in \u00b5F (assumed)\n",
      "C= C*10**-6 # in F\n",
      "# For 50% duty cycle, Ton= Toff = T/2 and R_A= R_B\n",
      "# From equation, f= 1.44/((R_A+R_B)*C)= 1.44/(2*R_A*C)\n",
      "R_A= 1.44/(2*f*C) # in \u03a9\n",
      "R_A= R_A*10**-3 # in k\u03a9\n",
      "R_B= R_A # in k\u03a9\n",
      "C= C*10**6 # in \u00b5F\n",
      "print \"The value of R_A and R_B = %0.f k\u03a9 (Standard value 100 k\u03a9)\" %R_A\n",
      "print \"The value of C = %0.2f \u00b5F\" %C"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R_A and R_B = 103 k\u03a9 (Standard value 100 k\u03a9)\n",
        "The value of C = 0.01 \u00b5F\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.5 - Page 144"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "f= 800 # in Hz\n",
      "C= 0.01 # in \u00b5F (assumed)\n",
      "C= C*10**-6 # in F\n",
      "D= 60 # in duty cycle in %\n",
      "# D= (R_A+R_B)/(R_A+2*R_B)*100= 60 or\n",
      "# R_B= 2*R_A\n",
      "R_A= 1.44/(f*5*C) # in \u03a9  (From f=1.44/((R_A+2*R_B)*C))\n",
      "R_A= R_A*10**-3 #in k\u03a9\n",
      "R_B= 2*R_A # in k\u03a9\n",
      "C= C*10**6 #in F\n",
      "print \"The value of R_A = %0.f k\u03a9\" %R_A\n",
      "print \"The value of R_B = %0.f k\u03a9\" %R_B\n",
      "print \"The value of C = %0.2f \u00b5F\" %C"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R_A = 36 k\u03a9\n",
        "The value of R_B = 72 k\u03a9\n",
        "The value of C = 0.01 \u00b5F\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.6 - Page 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi\n",
      "import math\n",
      "# Given data\n",
      "Rs= 5*10**3 #series resistance in \u03a9\n",
      "Ls= 0.8 # seried inductance in H\n",
      "Cs= 0.08*10**-12 #series capacitance in F\n",
      "Cp= 1.0*10**-12 # parallel capacitance in F\n",
      "fs= 1/(2*pi*math.sqrt(Ls*Cs)) # series resonant frequency in Hz\n",
      "fs= fs*10**-3 # in kHz\n",
      "fp= 1/(2*pi)*math.sqrt((1+Cs/Cp)/(Ls*Cs)) # parallel resonant frequency in Hz\n",
      "fp= fp*10**-3 # in kHz\n",
      "print \"The series resonant frequency = %0.f kHz\" %fs\n",
      "print \"The parallel resonant frequency = %0.f kHz\" %fp"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The series resonant frequency = 629 kHz\n",
        "The parallel resonant frequency = 654 kHz\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.7 - Page 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "C1= 1000*10**-12 # in F\n",
      "C2= 100*10**-12 # in F\n",
      "f= 1*10**6 # in Hz\n",
      "R1= 1*10**6 # in \u03a9 (assume)\n",
      "R2= 10*10**3 # in \u03a9 (assume)\n",
      "Rs= 800 # in \u03a9\n",
      "VDD= 5 # in V\n",
      "C_T= C1*C2/(C1+C2) #total capacitance in F\n",
      "# At resonance, X_L= X_CT or 2*pi*f*L= 1/(2*pi*f*C_T), So\n",
      "L= 1/((2*pi*f)**2*C_T) # in H\n",
      "L= L*10**3 # in mH\n",
      "print \"The value of inductance = %0.3f mH\" %L\n",
      "i_p= VDD/(R1+R2+Rs) #current through crystal in A\n",
      "# Power dissipated in the crystal,\n",
      "P_D= (0.707*i_p)**2*Rs # in W\n",
      "P_D= P_D*10**9 #in nW\n",
      "print \"The power dissipated in the crystal = %0.1f nW\" %P_D"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of inductance = 0.279 mH\n",
        "The power dissipated in the crystal = 9.8 nW\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.8 - Page 153"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "# Given data\n",
      "R= 12*10**3 # in \u03a9\n",
      "R1= 120*10**3 # in \u03a9\n",
      "Rf= 1*10**6 # in \u03a9\n",
      "C= 0.1*10**-6 # in F\n",
      "Vsupply= 12 # in V\n",
      "Vsat= 10 #in V\n",
      "#Part (i) : Signal frequency,\n",
      "f= Rf/(4*R1*R*C) # in Hz\n",
      "f= f*10**-3 # in kHz\n",
      "print \"Part (i) : The signal frequency = %0.3f kHz\" %f\n",
      "# Part (ii) : Amplitude of triangular wave,\n",
      "Vpp= 2*R1/Rf*Vsat # Vp-p\n",
      "print \"Part (ii) : Amplitude of the triangular wave = %0.1f Vp-p\" %Vpp\n",
      "# Amplitude of square wave,\n",
      "Vpp= Vsat-(-Vsat) #Vp-p\n",
      "print \"Amplitude of the square wave = %0.f Vp-p\" %Vpp"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i) : The signal frequency = 1.736 kHz\n",
        "Part (ii) : Amplitude of the triangular wave = 2.4 Vp-p\n",
        "Amplitude of the square wave = 20 Vp-p\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.10 - Page 160"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi\n",
      "from __future__ import division\n",
      "# Given data\n",
      "I_Bmax= 500 # in nA\n",
      "I_Bmax= I_Bmax*10**-9 # in A\n",
      "VCC= 10 # in V\n",
      "f= 10*10**3 # in Hz\n",
      "I1= 500*10**-6 # current through R1 in A (assume)\n",
      "Vout= (VCC-1) #output voltage in V\n",
      "# Rf+R1= Vout/I1 and Rf= 2*R1, so\n",
      "R1= Vout/(3*I1) # in \u03a9\n",
      "R1= R1*10**-3 # in k\u03a9\n",
      "print \"The value of R1 = %0.1f k\u03a9 (standard value 5.6 k\u03a9)\" %R1\n",
      "R1= 5.6 # in k\u03a9 (standard value)\n",
      "Rf= 2*R1 # in k\u03a9\n",
      "print \"The value of Rf = %0.1f k\u03a9 (standard value 12 k\u03a9)\" %Rf\n",
      "R= R1 # in k\u03a9\n",
      "R= R*10**3 # in \u03a9\n",
      "C= 1/(2*pi*f*R) # in F\n",
      "C= C*10**12 # in pF\n",
      "print \"The value of C = %0.f pF (Standard capacitor 2700 pF)\" %C"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R1 = 6.0 k\u03a9 (standard value 5.6 k\u03a9)\n",
        "The value of Rf = 11.2 k\u03a9 (standard value 12 k\u03a9)\n",
        "The value of C = 2842 pF (Standard capacitor 2700 pF)\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.11 - Page 161"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "R= 1*10**3 # in \u03a9\n",
      "C= 4.7*10**-6 # in F\n",
      "omega= 1/(R*C) # radians/second\n",
      "f= omega/(2*pi) # in Hz\n",
      "print \"The frequency of oscillation = %0.2f Hz\" %f"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency of oscillation = 33.86 Hz\n"
       ]
      }
     ],
     "prompt_number": 6
    }
   ],
   "metadata": {}
  }
 ]
}