{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1: Wavelength"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WAVELENGTH IN FREE SPACE IS  300.0 m\n",
      "WAVELENGTH IN FREE SPACE IS  11.1 m\n",
      "WAVELENGTH IN FREE SPACE IS  7.5 cm\n"
     ]
    }
   ],
   "source": [
    "# page no 7\n",
    "#calculate the wavelength in all cases\n",
    "# prob no 1.1\n",
    "#part a) freq= 1MHz(AM radio broadcast band)\n",
    "# We have the equation c=freq*wavelength\n",
    "c=3.*10**8;\n",
    "f=1.*10**6;\n",
    "#calculations\n",
    "wl=c/f;\n",
    "print 'WAVELENGTH IN FREE SPACE IS ',wl,'m'\n",
    "#part B) freq= 27MHz(CB radio band)\n",
    "f=27.*10**6;\n",
    "wl=c/f;\n",
    "print 'WAVELENGTH IN FREE SPACE IS ',round(wl,1),'m'\n",
    "#part C) freq= 4GHz(used for satellite television)\n",
    "f=4*10**9;\n",
    "wl=c/f;\n",
    "print 'WAVELENGTH IN FREE SPACE IS ',wl*100,'cm'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "noise power contributed by resistor 4.14e-17 W\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# page no 18\n",
    "#calculate the noise power\n",
    "# prob no. 1.4\n",
    "# In given problem noise power bandwidth is 10kHz; resistor temp T(0c)=27\n",
    "# First we have to convert temperature to kelvins:\n",
    "T0c=27.;\n",
    "Tk=T0c+273.;\n",
    "# noise power contributed by resistor , Pn= k*T*B\n",
    "k=1.38*10**(-23);\n",
    "B=10*10**3;\n",
    "#calculations\n",
    "Pn= k*Tk*B;\n",
    "#results\n",
    "print 'noise power contributed by resistor',Pn,'W'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The noise power is 24.3 pW\n",
      "The noise voltage is 5.4 muvolts\n"
     ]
    }
   ],
   "source": [
    " \n",
    "# page no 20\n",
    "#calculate the noise power and voltage\n",
    "# prob no 1.5\n",
    "from math import sqrt\n",
    "# In the given problem B=6MHz, Tk=293, k=1.38*10**-23\n",
    "B=6*10**6; Tk=293; k=1.38*10**-23;R=300;\n",
    "#calculations\n",
    "Pn=k*Tk*B;\n",
    "# Th noise voltage is given by Vn=sqrt(4*k*Tk*B*R)\n",
    "Vn=sqrt(4*k*Tk*B*R);\n",
    "#results\n",
    "print 'The noise power is',round(Pn*10**15,1),'pW'\n",
    "print 'The noise voltage is',round(Vn*10**6,1),'muvolts'\n",
    "# only one-half of this voltage is appears across the antenna terminals, the other appears across the source resistance. Therefore the actual noise voltag at the input is 2.7 uV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6: pg 21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Noise current is 0.133 muA\n",
      "current through the diode is 278.0 mA\n"
     ]
    }
   ],
   "source": [
    " \n",
    "# page no 21\n",
    "#calculate the current\n",
    "# prob no 1.6\n",
    "# given: FM broadcast receiver :- Vn=10uV, R=75V, B=200 kHz \n",
    "Vn=10.;#in uV\n",
    "R=75.; B=200.*10**3;\n",
    "#calculations\n",
    "#By Ohm's law\n",
    "In=Vn/R;\n",
    "print 'Noise current is',round(In,3),'muA'\n",
    "# Noise votlage is also given as In=sqrt(2*q*Io*B)\n",
    "q=1.6*10**-19;\n",
    "# solving this for Io=In**2/2*q*B;\n",
    "Io=(In*10**-6)**2/(2*q*B);\n",
    "print 'current through the diode is',round(Io*1000.,0),'mA'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7: pg 23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Open-ckt noise voltage is  0.78 muvolts\n",
      "The load power is 5.06e-16 W\n"
     ]
    }
   ],
   "source": [
    " \n",
    "#page no 23\n",
    "#calculate the load power and open-ckt noise voltage\n",
    "#pro no 1.7\n",
    "from math import sqrt\n",
    "#Given:refer fig.1.12 of page no.23;R1=100ohm,300K;R2=200ohm,400k;B=100kHz;Rl=300ohm\n",
    "R1=100.;T1=300.;R2=200.;T2=400.;B=100.*10**3;Rl=300.;k=1.38*10**-23;\n",
    "#calculations\n",
    "#open-ckt noise voltage is given by\n",
    "#Vn1 =sqrt(Vr1**2 + Vr2**2)\n",
    "#    =sqrt[sqrt(4kTBR1)**2 + sqrt(4kTBR2)**2]\n",
    "#by solving this we get Vn1=sqrt[4kB(T1R1 + T2R2)]\n",
    "Vn1=sqrt(4*k*B*(T1*R1 + T2*R2));\n",
    "# since in this case the load is equal in value to the sum of the resistors,\n",
    "# one-half of this voltage is appear across the load.\n",
    "# Now the load power is P=  Vn1**2/Rl\n",
    "P=  (Vn1/2)**2/Rl;\n",
    "#results\n",
    "print 'Open-ckt noise voltage is ',round(Vn1*1e6,2),'muvolts'\n",
    "print 'The load power is',P,'W'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8: pg 24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The power ratio in dB 13.979\n"
     ]
    }
   ],
   "source": [
    " \n",
    "# page no 24\n",
    "#Calculate the power ratio\n",
    "# prob no 1.8\n",
    "import math\n",
    "# Given: N=0.2W; S+N=5W; :. S=4.8W\n",
    "N=0.2; S=4.8;\n",
    "#calculations\n",
    "p=(S+N)/N;\n",
    "pdB=10*math.log10(p);\n",
    "#results\n",
    "print 'The power ratio in dB',round(pdB,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9: pg 25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The noise figure is 3.0\n"
     ]
    }
   ],
   "source": [
    " \n",
    "#page no 25\n",
    "#calculate the noise figure\n",
    "#prob no 1.9\n",
    "#Given: Si=100uW; Ni=1uW; So=1uW; No=0.03W\n",
    "Si=100.; Ni=1.; So=1; No= 0.03# all powers are in uW\n",
    "#calculations\n",
    "r1=Si/Ni;# input SNR\n",
    "r2=So/No;# output SNR\n",
    "NF=r1/r2;# Amplifier noise figure \n",
    "#results\n",
    "print 'The noise figure is',NF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10: pg 25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SNR at the output is  36 dB\n"
     ]
    }
   ],
   "source": [
    " \n",
    "#page no 25\n",
    "#calculate the SNR at output\n",
    "#prob no 1.10\n",
    "#giiven: SNRin=42 dB, NF=6dB\n",
    "# NF in dB is given as SNRin(dB)-SNRop(dB)\n",
    "SNRin=42 ; NF=6;\n",
    "#calculations\n",
    "SNRop=SNRin-NF;\n",
    "#results\n",
    "print 'SNR at the output is ',SNRop,'dB'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11: pg 27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The noise temperature is  169.65 K\n"
     ]
    }
   ],
   "source": [
    " \n",
    "#page no 27\n",
    "#calculate the noise temperature\n",
    "# prob no 1.11\n",
    "#Given NFdB=2dB,:.NF=antilog(NFdB)/10=1.585\n",
    "NF=1.585;\n",
    "#calculations\n",
    "Teq=290*(NF-1);\n",
    "#results\n",
    "print 'The noise temperature is ',Teq,'K'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12: pg 29"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The power gain is 7500.0\n",
      "The noise figure is 2.316\n",
      "The noise temperature is 381.64 K\n"
     ]
    }
   ],
   "source": [
    " \n",
    "#page no 29\n",
    "#calculate the power gain, noise figure, temperature\n",
    "#prob no 1.12\n",
    "#Given: \n",
    "A1=10.;A2=25.;A3=30.;NF1=2.;NF2=4.;NF3=5.;\n",
    "#calculations\n",
    "At=A1*A2*A3;\n",
    "print 'The power gain is',At\n",
    "# The noise figure is given as \n",
    "NFt=NF1+((NF2-1)/A1) + ((NF3-1)/(A1*A2));\n",
    "print 'The noise figure is',NFt\n",
    "# Noise temp can be found as \n",
    "Teq=290*(NFt-1);\n",
    "print 'The noise temperature is',Teq,'K'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13: pg 34"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A)The freq is 110.0 MHz\n",
      "The power in dBm -30 dBm\n",
      "The power is 1e-06 W\n",
      "The voltage is 0.00707 volts\n",
      "B)The freq is 7.4 MHz\n",
      "The power is 0.00794 W\n",
      "The power in dBm 9 dBm\n",
      "The voltage is 0.63008 volts\n",
      "C)The freq is 546 MHz\n",
      "The voltage is 16.8 mvolts\n",
      "The power is 5.6448 uW\n",
      "The power in dBm -22.48 dBm\n"
     ]
    }
   ],
   "source": [
    " \n",
    "# page no 34\n",
    "#calculate the power and voltage in all cases\n",
    "# prob no1.13 refer fig 1.20 of page no 34\n",
    "# part A) The signal frequency is f1=110MHz.\n",
    "from math import log10,sqrt\n",
    "f=110.;# in MHz\n",
    "#calculations and results\n",
    "print 'A)The freq is',f,'MHz'\n",
    "#The signal peak is two divisions below the reference level of -10dBm, with 10dB/division ,so its -30dBm.\n",
    "PdBm=-30;\n",
    "print 'The power in dBm',PdBm,'dBm'\n",
    "# The equivalent power can be found from P(dBm)=10logP/1 mW\n",
    "#P(mW)=antilog dBm/10= antilog -30/10=1*10**-3mW=1uW\n",
    "#the voltage can be found from the graph but it is more accurately from P=V**2/R\n",
    "P=10**-6; R=50;\n",
    "print 'The power is',P,'W'\n",
    "V=sqrt(P*R);\n",
    "print 'The voltage is',round(V,5),'volts'\n",
    "\n",
    "# part B)The signal is 1 division to theleft of center, with 100kHz/div. The freq is 100kHz less than the ref freq of 7.5MHz\n",
    "f=7.5-0.1;# in MHz\n",
    "print 'B)The freq is',f,'MHz'\n",
    "# With regards to the amplitude, the scale is 1dB/div & the signal is 1 div below the reference level. Therefore the signal has a power level given as\n",
    "PdBm=10-1;# in dBm\n",
    "# This can be converted to watts & volts as same in part A\n",
    "#P(mW)=antilog dBm/10= antilog 9/10=7.94mW\n",
    "P=7.94*10**-3; R=50;\n",
    "print 'The power is',P,'W'\n",
    "print 'The power in dBm',PdBm,'dBm'\n",
    "V=sqrt(P*R);\n",
    "print 'The voltage is',round(V,5),'volts'\n",
    "\n",
    "#part C) The signal is 3 divisions to the right of the center ref freq of 543MHz, with 1MHz/div. Therefore the freq is \n",
    "f=543+3*1;# in MHz\n",
    "print 'C)The freq is',f,'MHz'\n",
    "# from the spectrum, signal level is\n",
    "V=22.4*6/8;\n",
    "print 'The voltage is',V,'mvolts'\n",
    "# power is given as\n",
    "P=V**2/R;\n",
    "print 'The power is',P,'uW'\n",
    "PdBm=10*log10(P*10**-6/10**-3);\n",
    "print 'The power in dBm',round(PdBm,2),'dBm'"
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}