{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 : Active Filters"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.1 Page No.269"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import math\n",
      "# Given Data\n",
      "fh = 10**3\n",
      "C = 0.1*10**-6\n",
      "Rf = 5.86*10**3\n",
      "Ri = 10**4\n",
      "\n",
      "# Solution \n",
      "\n",
      "R = 1/(2*np.pi*C*fh)\n",
      "Ao = (1 + Rf/Ri)\n",
      "\n",
      "a = np.array([100, 200, 500, 1000, 5000, 10000])\n",
      "print \" The value of R is =\",round(R/1000,1),\"Kilo ohms\"\n",
      "print \" The value of Ao   =\",Ao\n",
      "print \" Frequency in Hz            Gain magnitude in dB 2o log (Vo/Vi)\"\n",
      "print \" ========================================================\" \n",
      "for i in a:\n",
      "\n",
      "    val = round(20 * math.log10(Ao/(math.sqrt(1 + (i/fh)**4))),3)\n",
      "    print i,\"            ||               \",val\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of R is = 1.6 Kilo ohms\n",
        " The value of Ao   = 1.586\n",
        " Frequency in Hz            Gain magnitude in dB 2o log (Vo/Vi)\n",
        " ========================================================\n",
        "100             ||                4.006\n",
        "200             ||                4.006\n",
        "500             ||                4.006\n",
        "1000             ||                0.996\n",
        "5000             ||                -23.96\n",
        "10000             ||                -35.994\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2 Page No.270"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Design of a 4th order Butter worth Low pss filter \n",
      "\n",
      "fh = 10**3\n",
      "C = 0.1*10**-6\n",
      "a1 = 0.765\n",
      "a2 = 1.848\n",
      "\n",
      "Ao1 = 3 - a1\n",
      "Ao2 = 3 - a2\n",
      "\n",
      "# let Rf1 = 12.35 kilo Ohm and Rf2 = 15.2 kilo ohm finding the Ri1 and Ri2 \n",
      "\n",
      "Rf1 = 12.35*10**3\n",
      "Rf2 = 15.2*10**3\n",
      "\n",
      "Ri1 = Rf1/(Ao1 - 1)\n",
      "Ri2 = Rf2/(Ao2 - 1)\n",
      "\n",
      "print \" The value of Ao1 = \",Ao1\n",
      "print \" The value of Ao2 = \",Ao2\n",
      "print \" The value of Rf1 = \",Rf1/1000,\"Kilo Ohm\"\n",
      "print \" The value of Rf2 = \",Rf2/1000,\"Kilo Ohm\"\n",
      "print \" The value of Ri1 = \",int(Ri1/1000),\"Kilo Ohm\"\n",
      "print \" The value of Ri2 = \",int(Ri2/1000),\"Kilo Ohm\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of Ao1 =  2.235\n",
        " The value of Ao2 =  1.152\n",
        " The value of Rf1 =  12.35 Kilo Ohm\n",
        " The value of Rf2 =  15.2 Kilo Ohm\n",
        " The value of Ri1 =  10 Kilo Ohm\n",
        " The value of Ri2 =  100 Kilo Ohm\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3 Page No.271 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Solution to fing out the value of n or order\n",
      "\n",
      "# We know the equation is 20 log|(H(jw)| = 20 log (Ao/(math.sqrt(1+(w/wh)**n))\n",
      "# putig the values into the equation we will get 0.01**2 = 1/(1 + 2**2*n)\n",
      "# solving the equation to get the value of n\n",
      "\n",
      "# 2**(2*n) = 1/(1 + (0.01)**2)\n",
      "# taking log to the base 2 on both sides\n",
      "n =  math.log(((10**4)-1),2)/2\n",
      "\n",
      "print \" The order of the filter will be =\",int(math.ceil(n))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The order of the filter will be = 7\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.4 Page No.272"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import math\n",
      "# Given Data\n",
      "fl = 10**3\n",
      "C = 0.1*10**-6\n",
      "Rf = 5.86*10**3\n",
      "Ri = 10**4\n",
      "\n",
      "# Solution \n",
      "\n",
      "R = 1/(2*np.pi*C*fl)\n",
      "Ao = (1 + Rf/Ri)\n",
      "\n",
      "a = np.array([100, 200, 500, 1000, 5000, 10000])\n",
      "print \" The value of R is =\",round(R/1000,1),\"Kilo ohms\"\n",
      "print \" The value of Ao   =\",Ao\n",
      "print \" Frequency in Hz            Gain magnitude in dB 2o log (Vo/Vi)\"\n",
      "print \" ========================================================\" \n",
      "for i in a:\n",
      "\n",
      "    val = round(Ao/math.sqrt(1 + (fl/i)**4),3)\n",
      "    print i,\"            ||               \",val\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of R is = 1.6 Kilo ohms\n",
        " The value of Ao   = 1.586\n",
        " Frequency in Hz            Gain magnitude in dB 2o log (Vo/Vi)\n",
        " ========================================================\n",
        "100             ||                0.016\n",
        "200             ||                0.063\n",
        "500             ||                0.385\n",
        "1000             ||                1.121\n",
        "5000             ||                1.586\n",
        "10000             ||                1.586\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.5 Page No.276"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Given Data \n",
      "\n",
      "fl = 400\n",
      "fh = 2*10**3\n",
      "Ao = 4\n",
      "\n",
      "# For design top get  Ao = 2 the values of Rf = Ri\n",
      "\n",
      "Rf = Ri = 10*10**3\n",
      "\n",
      "# for LPF \n",
      "\n",
      "C1 = 0.01*10**-6\n",
      "R1 = 1/(2*math.pi*fh*C1)\n",
      "\n",
      "# for HPF \n",
      "\n",
      "C2 = 0.01*10**-6\n",
      "R2 = 1/(2*math.pi*fl*C2)\n",
      "\n",
      "fo = math.sqrt(fh*fl)\n",
      "Q = fo/(fh - fl)\n",
      "\n",
      "print \"The value of c1 =\",C1*10**6,\"uF\"\n",
      "print \"The value of R1 =\",round(R1/1000,1),\"kilo Ohms\"\n",
      "print \"The value of c2 =\",C2*10**6,\"uF\"\n",
      "print \"The value of R2 =\",round(R2/1000,1),\"Kilo Ohms\"\n",
      "print \"The value of Q  =\",round(Q,2)\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of c1 = 0.01 uF\n",
        "The value of R1 = 8.0 kilo Ohms\n",
        "The value of c2 = 0.01 uF\n",
        "The value of R2 = 39.8 Kilo Ohms\n",
        "The value of Q  = 0.56\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.6 Page No.279"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Given Data \n",
      "\n",
      "fo = 50\n",
      "C = 0.1*10**-6\n",
      "\n",
      "# Solution \n",
      "\n",
      "R = 1/(2*math.pi*fo*C)\n",
      "\n",
      "print \"The value of Capasitor = \",C*10**6,\"uF\"\n",
      "print \"The value of Resistor  = \",round(R/1000,1),\"Kilo Ohm\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Capasitor =  0.1 uF\n",
        "The value of Resistor  =  31.8 Kilo Ohm\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.7 Page No.280"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Given Data \n",
      "\n",
      "fl = 400\n",
      "fh = 2*10**3\n",
      "Ao = 4\n",
      "\n",
      "# For design top get  Ao = 2 the values of Rf = Ri\n",
      "\n",
      "Rf = Ri = 10*10**3\n",
      "\n",
      "# for LPF \n",
      "\n",
      "C1 = 0.1*10**-6\n",
      "R1 = 1/(2*math.pi*fh*C1)\n",
      "\n",
      "# for HPF \n",
      "\n",
      "C2 = 0.1*10**-6\n",
      "R2 = 1/(2*math.pi*fl*C2)\n",
      "\n",
      "fo = math.sqrt(fh*fl)\n",
      "Q = fo/(fh - fl)\n",
      "\n",
      "print \"The value of c1 =\",C1*10**6,\"uF\"\n",
      "print \"The value of R1 =\",round(R1/1000,1),\"kilo Ohms\"\n",
      "print \"The value of c2 =\",C2*10**6,\"uF\"\n",
      "print \"The value of R2 =\",round(R2/1000),\"Kilo Ohms\"\n",
      "print \"The value of Q  =\",round(Q,2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of c1 = 0.1 uF\n",
        "The value of R1 = 0.8 kilo Ohms\n",
        "The value of c2 = 0.1 uF\n",
        "The value of R2 = 4.0 Kilo Ohms\n",
        "The value of Q  = 0.56\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.10 Page No.298 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# given data \n",
      "\n",
      "fc = 400\n",
      "Ao = -2\n",
      "Vcc = 5\n",
      "R1 = 10*10**3\n",
      "HoLP = 2\n",
      "\n",
      "R2 = HoLP * R1 \n",
      "\n",
      "# for second order butterworth filter Q = 0.707\n",
      "Q = 0.707\n",
      "R3 = Q * R2\n",
      "\n",
      "fclock = 50 * fc\n",
      "\n",
      "# Dispalying the outputs \n",
      "\n",
      "print \"The value of R1 =\",R1/1000,\"Ohms\"\n",
      "print \"The value of R2 =\",R2/1000,\"Kilo Ohms\"\n",
      "print \"The value of R3 =\",R3/1000,\"Kilo Ohms\"\n",
      "print \"The value of clock frequency =\",fclock/1000,\"Kilo Hertz\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R1 = 10 Ohms\n",
        "The value of R2 = 20 Kilo Ohms\n",
        "The value of R3 = 14.14 Kilo Ohms\n",
        "The value of clock frequency = 20 Kilo Hertz\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}