{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "CHAPTER 21 ACTIVE FILTERS"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-1, Page 806"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "Rf=39.0                               #feedback path resistance Rf (KOhm)\n",
      "R1=1.0                                #inverting input resistance R1(KOhm)\n",
      "R2=12.0*10**3                         #non-inverting input resistance R2(Ohm)\n",
      "C=680*10**-12                         #capacitance at non-inverting input(F)\n",
      "\n",
      "Av=(Rf/R1)+1                           # voltage gain\n",
      "fc=(2*math.pi*R2*C)**-1                 #cutoff frequency(Hz)\n",
      "\n",
      "print 'voltage gain Av = ',Av\n",
      "print 'cutoff frequency fc = ',round((fc/1000),2),'KHz'\n",
      "print 'frequency response:'\n",
      "print 'voltage gain is 32 dB in pass band. response breaks at 19.5 KHz.'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "voltage gain Av =  40.0\n",
        "cutoff frequency fc =  19.5 KHz\n",
        "frequency response:\n",
        "voltage gain is 32 dB in pass band. response breaks at 19.5 KHz.\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-2, Page 807"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "Rf=43.0                               #feedback path resistance Rf (KOhm)\n",
      "R1=0.220                              #non-inverting input resistance R1(KOhm)\n",
      "C=100*10**-12                         #capacitance (F)\n",
      "\n",
      "Av=(-Rf/R1)                            # voltage gain\n",
      "fc=((2*math.pi*Rf*C)**-1)/10**6         #cutoff frequency(KHz)\n",
      "\n",
      "print 'voltage gain Av = ',round(Av,2)\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'\n",
      "print 'voltage gain is 45.8 dB in pass band. response breaks at 37 KHz.'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "voltage gain Av =  -195.45\n",
        "cutoff frequency fc =  37.01 KHz\n",
        "voltage gain is 45.8 dB in pass band. response breaks at 37 KHz.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-3, Page 811"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=30                              #non-inverting input resistance R1(KOhm)\n",
      "R2=30                              #non-inverting input resistance R2(KOhm)\n",
      "C2=1.64*10**-9                     #feedback path capacitance (F)\n",
      "C1=820*10**-12                     #non-inverting input capacitance (F)\n",
      "\n",
      "Q=0.5*((C2/C1)**0.5)                               #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=fp                                             #cutoff frequency(KHz)\n",
      "\n",
      "print ' Q = ',round(Q,3)\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = fp, ',round(fc,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Q =  0.707\n",
        "pole frequency fp =  4.57 KHz\n",
        "cutoff frequency fc = fp,  4.57 KHz\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-4, Page 811"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=51                              #non-inverting input resistance R1(KOhm)\n",
      "R2=51                              #non-inverting input resistance R2(KOhm)\n",
      "C2=440*10**-12                     #feedback path capacitance (F)\n",
      "C1=330*10**-12                     #non-inverting input capacitance (F)\n",
      "kc=0.786                           #constant for bessel response \n",
      "\n",
      "Q=0.5*((C2/C1)**0.5)                               #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=kc*fp                                             #cutoff frequency(KHz) \n",
      "\n",
      "print ' Q = ',round(Q,2)\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Q =  0.58\n",
        "pole frequency fp =  8.19 KHz\n",
        "cutoff frequency fc =  6.44 KHz\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-5, Page 812"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "R1=22                              #non-inverting input resistance R1(KOhm)\n",
      "R2=22                              #non-inverting input resistance R2(KOhm)\n",
      "C2=27*10**-9                       #feedback path capacitance (F)\n",
      "C1=390*10**-12                     #non-inverting input capacitance (F)\n",
      "kc=1.38                            #constant for bessel response \n",
      "k0=0.99                            #constant for bessel response\n",
      "k3=1.54                            #constant for bessel response\n",
      "\n",
      "Q=0.5*((C2/C1)**0.5)                              #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=kc*fp                                          #cutoff frequency(KHz) \n",
      "f3=k3*fp                                          #3-dB frequency(KHz)\n",
      "\n",
      "print 'Q = ',round(Q,2)\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'\n",
      "print '3-dB frequency f(3dB) = ',round(f3,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q =  4.16\n",
        "pole frequency fp =  2.23 KHz\n",
        "cutoff frequency fc =  3.08 KHz\n",
        "3-dB frequency f(3dB) =  3.43 KHz\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-6, Page 817"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=47                              #non-inverting input resistance R1(KOhm)\n",
      "R2=47                              #non-inverting input resistance R2(KOhm)\n",
      "C2=330*10**-12                     #feedback path capacitance (F)\n",
      "C1=330*10**-12                     #non-inverting input capacitance (F)\n",
      "R3=51                              #inverting input resistance R3(KOhm)\n",
      "Rf=30.0                            #feedback path resistance Rf (KOhm)\n",
      "\n",
      "Av=(Rf/R3)+1                                      #voltage gain \n",
      "Q=(3-Av)**-1                                      #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=fp                                             #cutoff frequency(KHz) \n",
      "\n",
      "print ' Q = ',round(Q,2)\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Q =  0.71\n",
        "pole frequency fp =  10.26 KHz\n",
        "cutoff frequency fc =  10.26 KHz\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-7, Page 817"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=82                              #non-inverting input resistance R1(KOhm)\n",
      "R2=82                              #non-inverting input resistance R2(KOhm)\n",
      "C2=100*10**-12                     #feedback path capacitance (F)\n",
      "C1=100*10**-12                     #non-inverting input capacitance (F)\n",
      "R3=56                              #inverting input resistance R3(KOhm)\n",
      "Rf=15.0                            #feedback path resistance Rf (KOhm)\n",
      "kc=0.786                           #constant for bessel response \n",
      "\n",
      "Av=(Rf/R3)+1                                      #voltage gain \n",
      "Q=(3-Av)**-1                                      #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=kc*fp                                          #cutoff frequency(KHz) \n",
      "\n",
      "print 'Q = ',round(Q,2)\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q =  0.58\n",
        "pole frequency fp =  19.41 KHz\n",
        "cutoff frequency fc =  15.26 KHz\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-8, Page 818"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=56                              #non-inverting input resistance R1(KOhm)\n",
      "R2=56                              #non-inverting input resistance R2(KOhm)\n",
      "C2=220*10**-12                     #feedback path capacitance (F)\n",
      "C1=220*10**-12                     #non-inverting input capacitance (F)\n",
      "R3=20.0                            #inverting input resistance R3(KOhm)\n",
      "Rf=39.0                            #feedback path resistance Rf (KOhm)\n",
      "kc=1.414                           #constant for bessel response \n",
      "k0=1.0                             #constant for bessel response\n",
      "k3=1.55                            #constant for bessel response\n",
      "\n",
      "Av=(Rf/R3)+1                                      #voltage gain \n",
      "Q=(3-Av)**-1                                      #Q\n",
      "fp=((2*math.pi*R1*(C1*C2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=kc*fp                                          #cutoff frequency(KHz) \n",
      "f0=k0*fp                                          #resosnant frequency(KHz)\n",
      "f3=k3*fp                                          #3-dB frequency (KHz)\n",
      "Av1=((1.01*Rf)/(0.99*R3))+1                       #voltage gain considering 1% tolerance \n",
      "Q1=(3-Av1)**-1                                    #Q\n",
      "\n",
      "print 'Q = ',Q\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'\n",
      "print 'resonant frequency f0 = ',round(f0,2),'KHz'\n",
      "print '3-dB frequency f(3-dB) = ',round(f3,2),'KHz'\n",
      "print 'circuit produces 26-dB peak in response at 12.9 KHz, rolls off to 0 dB at cutoff and 3 dB down at 20 KHz'\n",
      "print 'after considering tolerance in resistance, Q changed to',Q1,'approximately'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q =  20.0\n",
        "pole frequency fp =  12.92 KHz\n",
        "cutoff frequency fc =  18.27 KHz\n",
        "resonant frequency f0 =  12.92 KHz\n",
        "3-dB frequency f(3-dB) =  20.02 KHz\n",
        "circuit produces 26-dB peak in response at 12.9 KHz, rolls off to 0 dB at cutoff and 3 dB down at 20 KHz\n",
        "after considering tolerance in resistance, Q changed to 94.2857142857 approximately\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-9, Page 820"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "R1=24                              #non-inverting input resistance R1(KOhm)\n",
      "R2=12                              #feedback path resistance R2(KOhm)\n",
      "C=4.7*10**-9                       #non-inverting input capacitance (F)\n",
      "\n",
      "Q=0.5*((R1/R2)**0.5)                              #Q\n",
      "fp=((2*math.pi*C*(R1*R2)**0.5)**-1)/10**6         #pole frequency(KHz)\n",
      "fc=fp                                            #cutoff frequency(KHz) \n",
      "\n",
      "print 'Q = ',round(Q,2)\n",
      "print 'pole frequency fp = ',math.ceil(fp),'KHz'\n",
      "print 'cutoff frequency fc = ',math.ceil(fc),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q =  0.71\n",
        "pole frequency fp =  2.0 KHz\n",
        "cutoff frequency fc =  2.0 KHz\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-10, Page 821"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=30                              #non-inverting input resistance R1(KOhm)\n",
      "R2=30                              #feedback path resistance R2(KOhm)\n",
      "C=1*10**-9                         #non-inverting input capacitance (F)\n",
      "R3=10.0                            #inverting input resistance R3(KOhm)\n",
      "Rf=15.0                            #feedback path resistance Rf (KOhm)\n",
      "kc=1.32                            #constant for bessel response \n",
      "k0=0.94                            #constant for bessel response\n",
      "k3=1.48                            #constant for bessel response\n",
      "\n",
      "Av=(Rf/R3)+1                                      #voltage gain \n",
      "Q=(3-Av)**-1                                      #Q\n",
      "fp=((2*math.pi*R1*C)**-1)/10**6                    #pole frequency(KHz)\n",
      "fc=fp/kc                                          #cutoff frequency(KHz) \n",
      "f0=fp/k0                                          #resosnant frequency(KHz)\n",
      "f3=fp/k3                                          #3-dB frequency (KHz)\n",
      "\n",
      "print 'Q = ',Q\n",
      "print 'pole frequency fp = ',round(fp,2),'KHz'\n",
      "print 'cutoff frequency fc = ',round(fc,2),'KHz'\n",
      "print 'resonant frequency f0 = ',round(f0,2),'KHz'\n",
      "print '3-dB frequency f(3-dB) = ',round(f3,2),'KHz'\n",
      "print 'circuit produces 6.3-dB peak in response at 5.65 KHz, rolls off to 0 dB at cutoff at 4.02 KHz and 3 dB down at 3.59 KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q =  2.0\n",
        "pole frequency fp =  5.31 KHz\n",
        "cutoff frequency fc =  4.02 KHz\n",
        "resonant frequency f0 =  5.64 KHz\n",
        "3-dB frequency f(3-dB) =  3.58 KHz\n",
        "circuit produces 6.3-dB peak in response at 5.65 KHz, rolls off to 0 dB at cutoff at 4.02 KHz and 3 dB down at 3.59 KHz\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-11, Page 825"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R1=18                              #non-inverting input resistance R1(KOhm)\n",
      "R2=30                              #feedback path resistance R2(KOhm)\n",
      "C=8.2*10**-9                       #non-inverting input capacitance (F)\n",
      "R31=0.080                          #inverting max input resistance R3(KOhm)\n",
      "R32=0.015                          #inverting min input resistance R3(KOhm)\n",
      "\n",
      "BW=((2*math.pi*R1*C)**-1)/10**6                                       #bandwidth(KHz)\n",
      "f0=((2*math.pi*C*((2*R1*((R1**-1+R31**-1)**-1))**0.5))**-1)/10**6     #minimum center frequency(KHz)\n",
      "f01=((2*math.pi*C*((2*R1*((R1**-1+R32**-1)**-1))**0.5))**-1)/10**6    #minimum center frequency(KHz)\n",
      "\n",
      "print 'bandwidth BW = ',round(BW,2),'KHz'\n",
      "print 'minimum center frequency f0 = ',round(f0,2),'KHz'\n",
      "print 'maximum center frequency f0 = ',round(f01,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "bandwidth BW =  1.08 KHz\n",
        "minimum center frequency f0 =  11.46 KHz\n",
        "maximum center frequency f0 =  26.42 KHz\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-12, Page 827"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "R=22.0                             #non-inverting input resistance(KOhm)\n",
      "C=120*10**-9                       #non-inverting input capacitance (F)\n",
      "R1=13.0                            #inverting input resistance(KOhm)\n",
      "R2=10.0                            #feedback path resistance(KOhm)\n",
      "\n",
      "Av=(R2/R1)+1                                      #voltage gain \n",
      "Q=0.5/(2-Av)                                      #Q\n",
      "f0=((2*math.pi*R*C)**-1)/10**3                     #center frequency(KHz)\n",
      "\n",
      "print 'voltage gain Av = ',round(Av,2)\n",
      "print 'Q = ',round(Q,2)\n",
      "print 'center frequency f0 = ',round(f0,2),'KHz'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "voltage gain Av =  1.77\n",
        "Q =  2.17\n",
        "center frequency f0 =  60.29 KHz\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21-13, Page 833"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "R=1.0                              #non-inverting input resistance(KOhm)\n",
      "C=100*10**-9                       #non-inverting input capacitance (F)\n",
      "f=1.0                                #frequency given(KHz)\n",
      "\n",
      "f0=((2*math.pi*R*C)**-1)/10**6                     #center frequency(KHz)\n",
      "phi=(2*math.atan(f0/f))*180/math.pi                #phase shift(deg)\n",
      "\n",
      "print 'center frequency f0 = ',round(f0,2),'KHz'\n",
      "print 'phase shift = ',math.ceil(phi),'degrees'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "center frequency f0 =  1.59 KHz\n",
        "phase shift =  116.0 degrees\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}