{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 26 : Filters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_1 Page No.  824"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency = 1591.55 Hertz\n",
      "i.e 1.592 kHz\n",
      "The Output Voltage = 7.07 Vpp\n",
      "The Phase angle (Theta z) = -45.00 Degree\n"
     ]
    }
   ],
   "source": [
    "from math import pi,sqrt,atan\n",
    "# Calculate (a)the cutoff frequency fc# (b)Vout at fc# (c)Theta at fc (Assume Vin = 10 Vpp for all frequencies)\n",
    "\n",
    "# Given data\n",
    "\n",
    "R = 10.*10**3#        # Resistor=10 kOhms\n",
    "C = 0.01*10**-6#     # Capacitor=0.01 uFarad\n",
    "Vin = 10.#           # Input Voltage=10Vpp\n",
    "# To calculate fc\n",
    "\n",
    "fc = 1./(2*pi*R*C)#\n",
    "print 'The Cutoff Frequency = %0.2f Hertz'%fc\n",
    "print 'i.e 1.592 kHz'\n",
    "\n",
    "# To calculate Vout at fc\n",
    "\n",
    "Xc = 1./(2*pi*fc*C)#\n",
    "\n",
    "Zt = sqrt((R*R)+(Xc*Xc))#\n",
    "\n",
    "Vout = Vin*(Xc/Zt)#\n",
    "print 'The Output Voltage = %0.2f Vpp'%Vout\n",
    "\n",
    "# To calculate Theta\n",
    "\n",
    "Theta = atan(-(R/Xc))*180/pi\n",
    "print 'The Phase angle (Theta z) = %0.2f Degree'%Theta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_2 Page No. 825"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency = 3183.10 Hertz i.e 3.183 kHz\n",
      "The Output Voltage = 9.54 Vpp\n",
      "approx 9.52 Volts(p-p)\n",
      "The Phase angle (Theta z) = -17.44 Degree\n"
     ]
    }
   ],
   "source": [
    "from math import pi,sqrt,atan\n",
    "# Calculate (a)the cutoff frequency fc# (b)Vout at 1 kHz# (c)Theta at 1 kHz (Assume Vin = 10 Vpp for all frequencies)\n",
    "\n",
    "# Given data\n",
    "\n",
    "R = 1.*10**3#         # Resistor=1 kOhms\n",
    "L = 50.*10**-3        # Inductor=50 mHenry\n",
    "Vin = 10.#           # Input Voltage=10Vpp\n",
    "f = 1.*10**3#         # Frequency=1 kHz\n",
    "# To calculate fc\n",
    "\n",
    "fc = R/(2*pi*L)#\n",
    "print 'The Cutoff Frequency = %0.2f Hertz'%fc,\n",
    "print 'i.e 3.183 kHz'\n",
    "\n",
    "# To calculate Vout at fc\n",
    "\n",
    "Xl = 2*pi*f*L#\n",
    "\n",
    "Zt = sqrt((R*R)+(Xl*Xl))#\n",
    "\n",
    "Vout = Vin*(R/Zt)#\n",
    "print 'The Output Voltage = %0.2f Vpp'%Vout\n",
    "print 'approx 9.52 Volts(p-p)'\n",
    "\n",
    "# To calculate Theta\n",
    "\n",
    "Theta = atan(-(Xl/R))*180/pi\n",
    "print 'The Phase angle (Theta z) = %0.2f Degree'%Theta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_3 Page No.  826"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency for RC High-Pass Filter = 10610.33 Hertz\n",
      "i.e 10.61 kHz\n",
      "The Cutoff Frequency for RL High-Pass Filter = 2387.32 Hertz\n",
      "approx 2.39 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi,sqrt\n",
    "# Calculate the cutoff frequency for (a) the RC high-pass filter# (b) the RL high-pass filter\n",
    "\n",
    "# Given data\n",
    "\n",
    "R = 1.5*10**3#       # Resistor=1.5 kOhms\n",
    "L = 100.*10**-3       # Inductor=100 mHenry\n",
    "C = 0.01*10**-6#     # Capacitor=0.01 uFarad\n",
    "\n",
    "# To calculate fc for RC high-pass filter\n",
    "\n",
    "fc = 1./(2*pi*R*C)#\n",
    "print 'The Cutoff Frequency for RC High-Pass Filter = %0.2f Hertz'%fc\n",
    "print 'i.e 10.61 kHz'\n",
    "\n",
    "# To calculate fc for RL high-pass filter\n",
    "\n",
    "fc1 = R/(2*pi*L)#\n",
    "print 'The Cutoff Frequency for RL High-Pass Filter = %0.2f Hertz'%fc1\n",
    "print 'approx 2.39 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_4 Page No.  827"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency for RC High-Pass filter = 159.15 Hertz\n",
      "i.e 159 Hz\n",
      "The Cutoff Frequency for RC High-Pass filter = 1591.55 Hertz\n",
      "i.e 1.59 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate the cutoff frequencies fc1 and fc2.\n",
    "\n",
    "#Given data\n",
    "\n",
    "R1 = 1.*10**3#        # Resistor 1=1 kOhms\n",
    "C1 = 1.*10**-6#       # Capacitor 1=1 uFarad\n",
    "R2 = 100.*10**3#      # Resistor 2=100 kOhms\n",
    "C2 = 0.001*10**-6#   # Capacitor 2=0.001 uFarad\n",
    "\n",
    "# To calculate fc1 for RC high-pass filter\n",
    "\n",
    "fc1 = 1/(2*pi*R1*C1)#\n",
    "print 'The Cutoff Frequency for RC High-Pass filter = %0.2f Hertz'%fc1\n",
    "print 'i.e 159 Hz'\n",
    "\n",
    "# To calculate fc2 for RC high-pass filter\n",
    "\n",
    "fc2 = 1/(2*pi*R2*C2)#\n",
    "print 'The Cutoff Frequency for RC High-Pass filter = %0.2f Hertz'%fc2\n",
    "print 'i.e 1.59 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_5 Page No.  828"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Notch Frequency for RC Low-Pass filter = 7957.75 Hertz\n",
      "i.e 7.96 kHz\n",
      "The Required Value of 2R1 = 2000.00 Ohms\n",
      "i.e 2 kohms\n",
      "The Required Value of 2C1 = 2.00e-08 Ohms\n",
      "0.02 uF\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate the notch frequency fn if R1 is 1 kOhms\u0004 and C1 is\u0005 0.01 \u0002uF. Also, calculate the required values for 2R1 and 2C1 in the low-pass filter.\n",
    "\n",
    "# Given data\n",
    "\n",
    "R1 = 1.*10**3#        # Resistor 1=1 kOhms\n",
    "C1 = 0.01*10**-6#    # Capacitor 1=0.01 uFarad\n",
    "\n",
    "# To calculate Notch frequency fn for RC low-pass filter\n",
    "\n",
    "fn = 1/(4*pi*R1*C1)#\n",
    "print 'The Notch Frequency for RC Low-Pass filter = %0.2f Hertz'%fn\n",
    "print 'i.e 7.96 kHz'\n",
    "\n",
    "A = 2*R1#\n",
    "print 'The Required Value of 2R1 = %0.2f Ohms'%A\n",
    "print 'i.e 2 kohms'\n",
    "\n",
    "B = 2*C1#\n",
    "print 'The Required Value of 2C1 = %0.2e Ohms'%B\n",
    "print '0.02 uF'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_6 Page No.  829"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Power Gain of Amplifier = 20.00 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# A certain amplifier has an input power of 1 W and an output power of 100 W.Calculate the dB power gain of the amplifier.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Pi = 1.#     # Input power=1 Watts\n",
    "Po = 100.#   # Output power=100 Watts\n",
    "\n",
    "N = 10*log10(Po/Pi)#\n",
    "print 'The Power Gain of Amplifier = %0.2f dB'%N"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_7 Page No.  830"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Attenuation offered by the Filter = -13.01 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# The input power to a filter is 100 mW, and the output power is 5 mW. Calculate the attenuation, in decibels, offered by the filter.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Pi = 100.*10**-3#    # Input power=1 Watts\n",
    "Po = 5.*10**-3#      # Output power=100 Watts\n",
    "\n",
    "N = 10*log10(Po/Pi)#\n",
    "print 'The Attenuation offered by the Filter = %0.2f dB'%N"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 26_8 Page No.  832"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Attenuation at 0 Hz = 0 dB\n",
      "The Attenuation at 1.592 kHz = -3.01 dB\n",
      "The Attenuation at 15.92 kHz = -20.05 dB\n"
     ]
    }
   ],
   "source": [
    "from math import pi,log10,sqrt\n",
    "# Calculate the attenuation, in decibels, at the following frequencies: (a) 0 Hz# (b) 1.592 kHz# (c) 15.92 kHz. (Assume that Vin is 10 V p-p at all frequencies.)\n",
    "\n",
    "# Given data\n",
    "\n",
    "f1 = 0#                 # Frequency 1=0 Hz\n",
    "f2 = 1.592*10**3#        # Frequency 2=1.592 kHz (cutoff frequency)\n",
    "f3 = 15.92*10**3#        # Frequency 3=15.92 kHz\n",
    "Vi = 10.#                # Voltage input=10 Volts(p-p)\n",
    "R = 10.*10**3#            # Resistor 1=10 kOhms\n",
    "C = 0.01*10**-6#         # Capacitor 1=0.01 uFarad \n",
    "\n",
    "Vo1 = Vi#\n",
    "Vo2 = 0.707*Vi#\n",
    "\n",
    "# At 0 Hz\n",
    "\n",
    "N1 = 20*log10(Vo1/Vi)#\n",
    "print 'The Attenuation at 0 Hz = %0.f dB'%N1\n",
    "\n",
    "#At 1.592 kHz (cutoff frequency)\n",
    "\n",
    "N2 = 20*log10(Vo2/Vi)#\n",
    "print 'The Attenuation at 1.592 kHz = %0.2f dB'%N2\n",
    "\n",
    "# At 15.92 kHz\n",
    "\n",
    "Xc = 1./(2*pi*f3*C)#\n",
    "\n",
    "A = R*R#\n",
    "B = Xc*Xc#\n",
    "\n",
    "Zt = sqrt (A+B)#\n",
    "\n",
    "N3 = 20*log10(Xc/Zt)#\n",
    "print 'The Attenuation at 15.92 kHz = %0.2f dB'%N3"
   ]
  }
 ],
 "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
}