summaryrefslogtreecommitdiff
path: root/Wireless_Communications_and_Networking_by_V._Garg/ch8.ipynb
blob: ccf24614d0ec6deb7f46994708adf21fa8a5dce6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
{
 "metadata": {
  "name": "",
  "signature": "sha256:f50ddd5f96951e3a4bd117adfc40133b15c129b8f04d9b391396a08431c3aae2"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8: Speech Coding and Channel Coding"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.1, Page 227"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Pdiff=-3.;  #in dB\n",
      "AMR1=12.2; #in kbps\n",
      "AMR2=7.95;  #in kbps\n",
      "AMR3=4.75;  #in kbps\n",
      "\n",
      "#Calculations\n",
      "#CG(dB)=10math.log{(DPDCH(kbps)+DPCCH)/(DPDCH(AMR bit rate (kbps))+ DPCCH)}\n",
      "CG1=10*math.log10((AMR1+AMR1*10**(Pdiff/10))/(AMR2+AMR1*10**(Pdiff/10)));\n",
      "CG2=10*math.log10((AMR1+AMR1*10**(Pdiff/10))/(AMR3+AMR1*10**(Pdiff/10)));\n",
      "\n",
      "#Results\n",
      "print 'By reducing the AMR bit rate from 12.2 to 7.95 kbps coverage gain becomes %.2f dB'%CG1;\n",
      "print 'By reducing the AMR bit rate from 7.95 to 4.75 kbps coverage gain becomes %.2f dB'%CG2;"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "By reducing the AMR bit rate from 12.2 to 7.95 kbps coverage gain becomes 1.15 dB\n",
        "By reducing the AMR bit rate from 7.95 to 4.75 kbps coverage gain becomes 2.27 dB\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.2, Page 239"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import sympy\n",
      "from sympy import symbols\n",
      "\n",
      "#Variable declaration\n",
      "K=4; #constraint length\n",
      "r=1./2; #code rate(n/k)\n",
      "x=symbols('x');#Defining x as a ploynomial variable\n",
      "G1=1+x**2+x**3;\n",
      "G2=1+x+x**2+x**3;\n",
      "ins=np.array([1, 0, 1, 1, 1]);#input(first bit first)\n",
      "\n",
      "#Calculations&Results\n",
      "#with reference to Fig 8.9 on page no 239\n",
      "g1=np.array([1, 0, 1, 1]); #converting from G1 polynomial to bit form\n",
      "g2=[1, 1, 1, 1];##converting from G2 polynomial to bit form\n",
      "x1=np.convolve(g1,ins)\n",
      "x2=np.convolve(g2,ins)\n",
      "V1=x1%2;\n",
      "V2=x2%2;\n",
      "print \"Multiplexing the V1 and V2 to get required output sequence as\"\n",
      "a=5;\n",
      "for i in range(0,6):\n",
      "   print '%d%d'%(V2[a],V1[a]);\n",
      "   a=a-1;\n",
      "  "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Multiplexing the V1 and V2 to get required output sequence as\n",
        "10\n",
        "10\n",
        "10\n",
        "00\n",
        "10\n",
        "11\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.3, Page 246"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "\n",
      "#Variable declaration\n",
      "BitStream=np.array([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1]);#Last bit to first bit\n",
      "\n",
      "# Interleaver\n",
      "Input1=[[1, 0, 0, 0],[1,0,0,0],[1,1,1,0],[0,0,0,0]]      #Writing data row wise\n",
      "\n",
      "#Calculations&Results\n",
      "print \"GIven Bit stream is\",BitStream\n",
      "print \"Input to interleaver is\",Input1\n",
      "\n",
      "Output1=np.array([0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1]);    # Reading data column wise\n",
      "print \"Output of interleaver is\",Output1\n",
      "#De-interleaver\n",
      "Input2=[[1, 1, 1, 0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]  #Writing o/p data row wise\n",
      " # Let From 6th to 9th bits have Burst Error \n",
      "print \"Input to de-interleaver is\",Input2\n",
      " #Output of deinterleaver\n",
      "                             \n",
      "Output2= [0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1]; \n",
      "print \"Output of de-interleaver is\",Output2\n",
      "print  \"Bits with Burst error were from 6th to 9th. But in output of de-interleaver, they relocated to positions 3rd, 6th, 10th and 14th.\";"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "GIven Bit stream is [0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 1]\n",
        "Input to interleaver is [[1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]]\n",
        "Output of interleaver is [0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1]\n",
        "Input to de-interleaver is [[1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]]\n",
        "Output of de-interleaver is [0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1]\n",
        "Bits with Burst error were from 6th to 9th. But in output of de-interleaver, they relocated to positions 3rd, 6th, 10th and 14th.\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}