{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 16 - Acoustics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 552"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ratio =  1.0017\n",
      "delta_v (m/s) =  0.6\n"
     ]
    }
   ],
   "source": [
    "#pg 552\n",
    "#calculate the Ratio and delta_v\n",
    "#Given :\n",
    "delta_t = 1; # temperature in degrees\n",
    "t1 = 27.; # temperature in degrees\n",
    "v1 = 343;# speed of sound at room temperature in m/s\n",
    "#calculations\n",
    "#Ratio = v2/v1 = 1+ (delta_t/(t1+273))\n",
    "Ratio = 1 + (delta_t /(2*(t1+273)));\n",
    "v2 = v1*Ratio; # speed of sound in air in m/s\n",
    "delta_v = v2-v1; # speed in m/s\n",
    "#results\n",
    "print \"Ratio = \",round(Ratio,4)\n",
    "print \"delta_v (m/s) = \",round(delta_v,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 553"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum displacement amplitude = 11.0 pm\n",
      "Maximum displacement amplitude = 11.0 mu m\n"
     ]
    }
   ],
   "source": [
    "#pg 553\n",
    "#calculate the Maximum displacement amplitude\n",
    "#Given :\n",
    "import math\n",
    "p_rms = 0.0002; # in microbar\n",
    "p_rms1 = 20.; # in pascal\n",
    "v = 343.; # speed of sound in m/s\n",
    "rho_0 = 1.21; # density of air in kg/m^3\n",
    "f = 1000.; # frequency in Hz\n",
    "# p_rms = pm_min/(2)^0.5\n",
    "#1 microbar = 0.1 N/m^2\n",
    "#calculations\n",
    "pm_min = math.sqrt(2)*p_rms*0.1; #in N/m^2\n",
    "# 1 pascal = 1 N/m^2\n",
    "pm_max =math.sqrt(2)*p_rms1*1; # in N/m^2\n",
    "# sm = pm/(v*rho_0*omega);\n",
    "#omega = 2*pi*f\n",
    "sm_min = pm_min/(v*rho_0*2* math.pi*f); # displacement amplitude in m\n",
    "sm_max = pm_max/(v*rho_0*2*math.pi*f);# displacement amplitude in m\n",
    "#results\n",
    "print \"Minimum displacement amplitude =\",round(sm_min*10**12,0),\"pm\"\n",
    "print \"Maximum displacement amplitude =\",round(sm_max*10**6),\"mu m\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 555"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I_max/I_min = 1.0 x 10**12 \n"
     ]
    }
   ],
   "source": [
    "#pg 555\n",
    "#calculate the ratio of max to min intensity\n",
    "#Given :\n",
    "import math\n",
    "sm_min = 11*10**-12;# Minimum displacement amplitude in m\n",
    "sm_max = 11*10**-6;# Maximum displacement amplitude in m\n",
    "v = 343;# speed of sound in m/s\n",
    "f = 1000; # frequency in Hz\n",
    "rho_0 = 1.21; # density of air in kg/m**3\n",
    "# Sound intensity = (rho_0*v*omega**2*sm**2)/2\n",
    "#omega = 2*pi*f\n",
    "#calculations\n",
    "I_max = (rho_0*v*((2*math.pi*f)**2)*(sm_max**2))/2; # Maximum Intensity\n",
    "I_min =  (rho_0*v*((2*math.pi*f)**2)*(sm_min**2))/2; # Minimum Intensity\n",
    "Ratio = I_max/I_min ;\n",
    "#results\n",
    "print \"I_max/I_min =\",Ratio*10**-12,\"x 10**12 \"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 556"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hearing Threshold : 1.0 x 10**-12 W/m^2\n",
      "Speech Activity : 1.0 x 10**-6 W/m^2\n",
      "Pain Threshold (W/m^2) =  1.0\n"
     ]
    }
   ],
   "source": [
    "#pg 556\n",
    "#calculate the Hearing Threshold,Speech Activity and Pain Threshold\n",
    "#Given :\n",
    "I0 = 10**-12; # in W/m**2\n",
    "beta1 = 0.; # in dB\n",
    "beta2 = 60.;# in dB\n",
    "beta3 = 120.; # in dB\n",
    "#calculations\n",
    "# Intensity level = beta = 10*log10(I/I0)\n",
    "I1 = 10**(beta1/10)*I0; # Intensity in W/m**2\n",
    "I2 = 10**(beta2/10)*I0; # Intensity in W/m**2\n",
    "I3 = 10**(beta3/10)*I0; # Intensity in W/m**2\n",
    "#results\n",
    "print \"Hearing Threshold :\",I1*10**12,\"x 10**-12 W/m^2\"\n",
    "print \"Speech Activity :\",I2*10**6,\"x 10**-6 W/m^2\"\n",
    "print \"Pain Threshold (W/m^2) = \",I3\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 563"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For auditorium  reverberation time (s) =  1.68\n",
      "When people are present, reverberation time (s) =  1.39\n"
     ]
    }
   ],
   "source": [
    "#pg 563\n",
    "#calculate the reverberation time\n",
    "#Given :\n",
    "l = 200.; # in ft\n",
    "b = 50.; # in ft\n",
    "h = 30.;# in ft\n",
    "alpha = 0.25; #average absorption coefficient\n",
    "#calculations\n",
    "V  = l*b*h; # Volume in ft^3\n",
    "S = 2*((l*b)+(l*h)+(b*h)); #total surface area in ft^2\n",
    "a = alpha*S;# in sabins\n",
    "T = (0.049*V)/a; # reverberation time in s\n",
    "#400 people present in the auditorium, 1 person is equivalent to 4.5 sabins\n",
    "a1 = a+ 400*4.5; # in sabins\n",
    "T1 = (0.049*V)/a1;# reverberation time in s\n",
    "#results\n",
    "print \"For auditorium  reverberation time (s) = \",T\n",
    "print \"When people are present, reverberation time (s) = \",round(T1,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 564"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha =  0.02\n",
      "alpha_e =  0.52\n"
     ]
    }
   ],
   "source": [
    "#pg 564\n",
    "#calculate the absorption coefficients\n",
    "#Given :\n",
    "V = 9.*10*11; # Volume in ft^3\n",
    "T = 4.; # reverberation time in s\n",
    "S = 2*((9*10.)+(10*11)+(11*9));# total surface area in ft^2\n",
    "S1 = 50.; # total surface area in ft^2\n",
    "T1 = 1.3; # reverberation time in s\n",
    "#calculations\n",
    "#T = (0.049*V)/(alpha*S)\n",
    "alpha = (0.049*V)/(S*T);#average absorption coefficient \n",
    "alpha_e =(((0.049*V)/S1)*((1/T1)-(1/T))) + alpha ; # effective absorption coefficient \n",
    "#results\n",
    "print \"alpha = \",round(alpha,2)\n",
    "print \"alpha_e = \",round(alpha_e,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 565"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Frequency is (kHz) =  34.3\n"
     ]
    }
   ],
   "source": [
    "#pg 565\n",
    "#calculate the frequency\n",
    "#Given :\n",
    "v = 343.; # velocity of sound in m/s\n",
    "lambd = 1; # wavelength in cm\n",
    "# 1 cm = 1.0*10^-2 m\n",
    "#calculations\n",
    "f = v/(lambd*10**-2); #frequency in Hz\n",
    "#results\n",
    "print \"Frequency is (kHz) = \",f*10**-3\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8 - pg 568"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Piezoelectric generator\n",
      "For  n = 1 , Frequency (MHz) =  1.42\n",
      "For  n = 2 , Frequency (MHz) =  2.84\n",
      "For  n = 3 , Frequency (MHz) =  4.26\n",
      "Magnetostriction generator\n",
      "For  n = 1 , Frequency (kHz) =  48.9\n",
      "For  n = 2 , Frequency (kHz) =  97.7\n",
      "For  n = 3 , Frequency (kHz) =  146.6\n",
      "Results differ from those in textbook, because in the formulae (n/(2*t))*sqrt(E/rho) and (n/(2*l))*sqrt(E/rho) , 2 is not multiplied with either t or l.\n"
     ]
    }
   ],
   "source": [
    "#pg 568\n",
    "#calculate the frequency required\n",
    "#Given :\n",
    "import math\n",
    "from math import sqrt\n",
    "E1 = 8.55*10**10; #Modulus of elasticity in N/m**2\n",
    "E2 = 21.*10**10; # Modulus of elasticity in N/m**2\n",
    "rho1 = 2650.; # density of Quartz in kg/m**3\n",
    "rho2 = 8800.;# density of Nickel in kg/m**3\n",
    "t = 2.; # thickness of crystal in mm\n",
    "l = 50.; # rod length in mm\n",
    "#Piezoelectric generator\n",
    "#calculations and results\n",
    "print (\"Piezoelectric generator\");\n",
    "for n in range(1,4):\n",
    "    # 1 mm = 1.0*10**-3 m\n",
    "    nu1 = (n/(2*t*10**-3))*sqrt(E1/rho1);# frequency in Hz \n",
    "    print \"For  n =\",n,\", Frequency (MHz) = \",round(nu1*10**-6,2)\n",
    "#Magnetostriction generator\n",
    "print \"Magnetostriction generator\"\n",
    "for n1 in range (1,4):\n",
    "     # 1 mm = 1.0*10**-3 m\n",
    "    nu2 = (n1/(2*l*10**-3))*sqrt(E2/rho2);# frequency in Hz \n",
    "    print \"For  n =\",n1,\", Frequency (kHz) = \",round(nu2*10**-3,1)\n",
    "print 'Results differ from those in textbook, because in the formulae (n/(2*t))*sqrt(E/rho) and (n/(2*l))*sqrt(E/rho) , 2 is not multiplied with either t or l.'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 569"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Amplified Rock Music (W/m^2) =  0.1\n",
      "Jet plane   1.0 x 10^3 W/m^2 \n",
      "Rocket engine : 1.0 x 10^6 W/m^2\n"
     ]
    }
   ],
   "source": [
    "#pg 569\n",
    "#calculate the Amplified Rock Music, Jet plane and Rocket engine\n",
    "#Given :\n",
    "I0 = 10**-12; # in W/m**2\n",
    "beta1 = 110.; # in dB\n",
    "beta2 = 150.;# in dB\n",
    "beta3 = 180.; # in dB\n",
    "#calculations\n",
    "# Intensity level = beta = 10*log10(I/I0)\n",
    "I1 = 10**(beta1/10)*I0; # Intensity in W/m**2\n",
    "I2 = 10**(beta2/10)*I0; # Intensity in W/m**2\n",
    "I3 = 10**(beta3/10)*I0; # Intensity in W/m**2\n",
    "#results\n",
    "print \"Amplified Rock Music (W/m^2) = \",I1\n",
    "print \"Jet plane  \",I2*10**-3,\"x 10^3 W/m^2 \"\n",
    "print \"Rocket engine :\",I3*10**-6,\"x 10^6 W/m^2\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10 - pg 572"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Depth (m) =  600.0\n"
     ]
    }
   ],
   "source": [
    "#pg 572\n",
    "#calculate the depth required\n",
    "#Given :\n",
    "v = 1500.; # velocity of ultrasound in m/s\n",
    "rt = 0.8; # recorded time in s\n",
    "#calculations\n",
    "t = rt/2.; # time in s\n",
    "#Ultrasound velocity = D/t\n",
    "D = v*t; # sea depth in m\n",
    "#results\n",
    "print \"Depth (m) = \",D\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
}
