{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 11: SIGNAL GENERATORS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11-1, Page Number: 317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mimimum frequency f(min)= 106.0 Hz\n",
      "Maximum frequency f(max)= 1.06 kHz\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "R1min=500          #Minimum Value of R1(ohm)\n",
    "R1max=5*10**3      #Maximum Value of R1(ohm)\n",
    "C=300*10**-9       #in farad(C=C1=C2) \n",
    "\n",
    "#Calculation\n",
    "#Using the formula f=1/2*pi*R*C for Wein bridge oscillator\n",
    "\n",
    "fmin=1/(2*math.pi*C*R1max)   #Minimum frequency occurs when R1 is maximum(Hz)\n",
    "fmax=1/(2*math.pi*C*R1min)   #Maximum frequency occurs when R1 is minimum(Hz)\n",
    "\n",
    "print \"Mimimum frequency f(min)=\",round(fmin),\"Hz\"\n",
    "print \"Maximum frequency f(max)=\",round(fmax/1000,2),\"kHz\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11-2, Page Number: 319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R3= 1.0 kilo ohm\n",
      "R1+R2= 49.0 kilo ohm\n",
      "R1= 4.0 kilo ohm\n",
      "R2= 45.0 kilo ohm\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "Vi=5                        #Input voltage(V)\n",
    "Ib=500*10**-9               #Bias Current(A)\n",
    "\n",
    "#Calculation\n",
    "#With R1 and R2 in the circuit\n",
    "Vr3=0.1                     #As range is 0-0.1V\n",
    "Vr=Vi-Vr3                   #KVL\n",
    "\n",
    "I3=100*10**-6               #Since I3>>Ib, assume I3=100micro ampere\n",
    "R3=Vr3/I3                   #Ohm's Law \n",
    "Rr=Vr/I3                    #Ohm's Law. Rr is equivalent series resistance. Rr=R1+R2\n",
    "\n",
    "print \"R3=\",round(R3*10**-3),\"kilo ohm\"\n",
    "print \"R1+R2=\",round(Rr*10**-3),\"kilo ohm\"\n",
    "\n",
    "\n",
    "#With R2 swithed out of the circuit\n",
    "Vr3=1                       #Range 0-1V\n",
    "I3=Vr3/R3                   #Ohm's Law \n",
    "Vr1=Vi-Vr3                  #KVL\n",
    "R1=Vr1/I3                   #Ohm's Law\n",
    "R2=Rr-R1                    #Rr is equivalent series resistance                       \n",
    "print \"R1=\",R1*10**-3,\"kilo ohm\"\n",
    "print \"R2=\",R2*10**-3,\"kilo ohm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11-3, Page Number: 326"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For contact at top of R1,\n",
      "f= 1.17 kHz\n",
      "\n",
      "For R1 contact at 10% from bottom,\n",
      "f= 117.0 Hz\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "C1=0.1*10**-6                  #in farad    \n",
    "R1=1*10**3                     #in ohm\n",
    "R2=10*10**3                    #in ohm \n",
    "UTP=3.0                        #in V\n",
    "LTP=-3.0                       #in V\n",
    "Vcc=15.0                       #in V\n",
    "\n",
    "#Calculation\n",
    "\n",
    "V3=Vcc-1                       #Op-amp saturation voltage is approximately one less than Vcc\n",
    "\n",
    "#For contact at top of R1\n",
    "V1=V3                          \n",
    "I2=V1/R2\n",
    "dV=UTP-LTP\n",
    "t=C1*dV/I2                     #Using equation for a capacitor charging linearly\n",
    "f=1/(2*t)\n",
    "\n",
    "print \"For contact at top of R1,\"\n",
    "print \"f=\",round(f*10**-3,2),\"kHz\"\n",
    "\n",
    "#For R1 at 10% from bottom\n",
    "\n",
    "V1=0.1*V3\n",
    "I2=V1/R2\n",
    "t=C1* dV/I2                    #Using equation for a capacitor charging linearly\n",
    "f=1/(2*t)\n",
    "\n",
    "print \n",
    "print \"For R1 contact at 10% from bottom,\"\n",
    "print \"f=\",round(f),\"Hz\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11-4, Page Number: 332"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t= 4.13 ms\n",
      "The frequency of the sqaure wave output is  121.0 Hz\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "R1=20*10**3             #in ohm\n",
    "R2=6.2*10**3            #in ohm\n",
    "R3=5.6*10**3            #in ohm\n",
    "C1=0.2*10**-6           #in farad\n",
    "Vcc=12.0                #in volt\n",
    "\n",
    "#Calculation\n",
    "\n",
    "Vo=Vcc-1                 #Op-amp saturation voltage is approximately one less than Vcc\n",
    "\n",
    "UTP=Vo*R3/(R3+R2)        #Upper Threshold Voltage\n",
    "LTP=-UTP                 #Lower Threshold voltage              \n",
    " \n",
    "t=C1*R1*math.log((Vo-LTP)/(Vo-UTP))    #Equation to find pulse width for astable multivibrator\n",
    "f=1/(2*t)                               \n",
    "\n",
    "#Results\n",
    "print \"t=\",round(t*10**3,2),\"ms\"\n",
    "print \"The frequency of the sqaure wave output is \",round(f),\"Hz\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11-5, Page Number: 334"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pulse width(PW)= 289.0 micro second\n",
      "For Pw=6ms, C2 should be 0.2 micro farad\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "Vcc=10\n",
    "Vb=1\n",
    "R1=22*10**3\n",
    "R2=10*10**3\n",
    "C1=100*10**-12\n",
    "C2=0.01*10**-6\n",
    "\n",
    "#Calculation\n",
    "Vo_plus=Vcc-1\n",
    "Vo_minus=-(Vcc-1)\n",
    "\n",
    "PW=C2*R2*math.log((Vo_plus-Vo_minus)/Vb)\n",
    "print \"Pulse width(PW)=\",round(PW*10**6),\"micro second\"\n",
    "\n",
    "#When Pw=6ms, C2 is found as follows\n",
    "PW=6*10**-3\n",
    "C2=PW/(R2*math.log((Vo_plus-Vo_minus)/Vb))\n",
    "\n",
    "print \"For Pw=6ms, C2 should be\",round(C2*10**6,1),\"micro farad\"\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
}