{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 15: Active Filters"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1, Page 377"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "fc=1000#fc=given cut-off frequency in Hz\n",
      "A=-56.#A=required gain to be dropped by this much amount in dB\n",
      "#Also,A=normalized gain of Butterworth filter=|A(jw)/Ao|\n",
      "f=10*1000#f=given frequency in Hz where the normalized gain is dropped by given amount\n",
      "\n",
      "#Calculations\n",
      "#|A(jw)/Ao|=(-20)*n*log10(w/wc) where n=order of the filter\n",
      "#|A(jw)/Ao|=(-20)*n*log10(f/fc)\n",
      "n=A/((-20)*math.log10(f/fc))#n=order of Butterworth low-pass filter\n",
      "print \"Order of given filter to be designed is (n)=%.f\"%(math.ceil(n))\n",
      "#As n=3 (from above calculation) we need cascading of first-order section and second-order section\n",
      "#For n=3\n",
      "k=0.5#k=damping factor\n",
      "Ao=3-(2*k)#Ao=DC gain for each op-amp in a given Butterworth Filter to be designed\n",
      "R1=10*1000#R1=Assumed resistance in ohms\n",
      "#Ao=(R1+R2)/R1\n",
      "R2=(Ao*R1)-R1\n",
      "#fc=1/(2*%pi*R*C)\n",
      "R=1000#R=Assumed resistance in ohms\n",
      "C=1/(2*math.pi*R*fc)\n",
      "\n",
      "#Results\n",
      "print \"The designed values of resistance and capacitance for a low-pass Butterworth filter are:\"\n",
      "print \"R1=%.f k ohm\"%(R1/1000)\n",
      "print \"R2=%.f k ohm\"%(R2/1000)\n",
      "print \"R=%.f k ohm\"%(R/1000)\n",
      "print \"C=%.2f uF\"%(C/10**-6)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Order of given filter to be designed is (n)=3\n",
        "The designed values of resistance and capacitance for a low-pass Butterworth filter are:\n",
        "R1=10 k ohm\n",
        "R2=10 k ohm\n",
        "R=1 k ohm\n",
        "C=0.16 uF\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, Page 378"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Ao=5#Ao=high frequency gain of a given first-order Butterworth active HP filter\n",
      "#Ao=(R1+R2)/R1\n",
      "R1=1000#R1=Assumed resistance in ohms\n",
      "\n",
      "#Calculations\n",
      "R2=(Ao*R1)-R1\n",
      "fc=200#fc=given cut-off frequency in Hz\n",
      "#fc=1/(2*%pi*R*C)\n",
      "R=5*1000#R=Assumed resistance in ohms\n",
      "C=1/(2*math.pi*R*fc)\n",
      "\n",
      "#Results\n",
      "print \"The designed values of resistance and capacitance for a high-pass Butterworth filter are:\"\n",
      "print \"R1=%.f k ohm\"%(R1/1000)\n",
      "print \"R2=%.f k ohm\"%(R2/1000)\n",
      "print \"R=%.f k ohm\"%(R/1000)\n",
      "print \"C=%.2f uF\"%(C/10**-6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The designed values of resistance and capacitance for a high-pass Butterworth filter are:\n",
        "R1=1 k ohm\n",
        "R2=4 k ohm\n",
        "R=5 k ohm\n",
        "C=0.16 uF\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, Page 378"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "fo=1000.#fo=centre frequency in Hz\n",
      "f=100#f=bandwidth in Hz\n",
      "\n",
      "#Calculations\n",
      "#Q=wo/w=Quality factor\n",
      "Q=(2*math.pi*fo)/(2*math.pi*f)\n",
      "C1=0.02*10**-6\n",
      "C2=0.02*10**-6#C1=C2=Assumed Capacitances in Farad\n",
      "Ao=2#Ao=gain at the centre frequency\n",
      "#R1*C1=Q/(wo*Ao) for active band pass Butterworth filter\n",
      "wo=2*math.pi*fo\n",
      "R1=Q/(Ao*wo*C1)\n",
      "R3=Q/(wo*((C1*C2)/(C1+C2)))\n",
      "Rp=1./((wo**2)*R3*C1*C2)\n",
      "R2=(R1*Rp)/(R1-Rp)\n",
      "\n",
      "#Results\n",
      "print \"The designed values of resistance and capacitance for a second order band-pass Butterworth filter are:\"\n",
      "print \"R1=%.f k ohm\"%(math.ceil(R1/1000))\n",
      "print \"R2=%.f ohm\"%(math.floor(R2))\n",
      "print \"R3=%.f k ohm\"%(math.ceil(R3/1000))\n",
      "print \"C1=%.2f uF\"%(C1/10**-6)\n",
      "print \"C2=%.2f uF\"%(C2/10**-6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The designed values of resistance and capacitance for a second order band-pass Butterworth filter are:\n",
        "R1=40 k ohm\n",
        "R2=401 ohm\n",
        "R3=160 k ohm\n",
        "C1=0.02 uF\n",
        "C2=0.02 uF\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, Page 379"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "fo=400#fo=centre frequency in Hz\n",
      "Q=10#Q=wo/w=Quality factor\n",
      "C1=0.1*10**-6\n",
      "C2=0.1*10**-6#C1=C2=Assumed Capacitances in Farad\n",
      "Ao=2#Ao=gain at the centre frequency\n",
      "\n",
      "#Calculations\n",
      "#R1*C1=Q/(wo*Ao) for active band pass Butterworth filter\n",
      "wo=2*math.pi*fo\n",
      "R1=Q/(Ao*wo*C1)\n",
      "R3=Q/(wo*((C1*C2)/(C1+C2)))\n",
      "Rp=1/((wo**2)*R3*C1*C2)\n",
      "R2=(R1*Rp)/(R1-Rp)\n",
      "#Assuming arbitrarily (R6/R5)=10=a\n",
      "a=10\n",
      "R6=10*1000#R6=Assumed resistance in ohms\n",
      "R5=R6/a\n",
      "R4=R5/Ao\n",
      "\n",
      "#Results\n",
      "print \"The designed values of resistance and capacitance for a notch filter are:\"\n",
      "print \"R1=%.2f k ohm\"%(R1/1000)\n",
      "print \"R2=%.f ohm\"%R2\n",
      "print \"R3=%.2f k ohm\"%(R3/1000)\n",
      "print \"R4=%.f ohm\"%R4\n",
      "print \"R5=%.f k ohm\"%(R5/1000)\n",
      "print \"R6=%.f k ohm\"%(R6/1000)\n",
      "print \"C1=%.1f uF\"%(C1/10**-6)\n",
      "print \"C2=%.1f uF\"%(C2/10**-6)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The designed values of resistance and capacitance for a notch filter are:\n",
        "R1=19.89 k ohm\n",
        "R2=201 ohm\n",
        "R3=79.58 k ohm\n",
        "R4=500 ohm\n",
        "R5=1 k ohm\n",
        "R6=10 k ohm\n",
        "C1=0.1 uF\n",
        "C2=0.1 uF\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}