summaryrefslogtreecommitdiff
path: root/Wireless_Communications_and_Networking_by_V._Garg/ch9.ipynb
blob: 7efd7e54d09fe2dc8da4f167ab36dd08b4fec4ee (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
{
 "metadata": {
  "name": "",
  "signature": "sha256:4f7509b378d9baa23589f40ce770175499b6cadfd03b87969971e1834bcae9ad"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 9: Modulation Schemes"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.1, Page 259"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import scipy\n",
      "from scipy.optimize import fsolve\n",
      "\n",
      "#Variable declaration\n",
      "Pe=10**-6;#Probability of error\n",
      "e=2.71828; #Euler's Number\n",
      "\n",
      "#Calculations\n",
      "# For BPSK\n",
      "#Pe(=10**-6)=e**(-x)/(2*sqrt(%pi*x)); where x=Eb/No\n",
      "def f(x):\n",
      "    y=2.71828**(-x)/(2*math.sqrt(math.pi*x))-10**-6\n",
      "    return y\n",
      "x = fsolve(f,0.1);\n",
      "\n",
      "#Results\n",
      "print 'Eb/No For BPSK is %.2f dB'%(10*math.log10(x));\n",
      "print 'FSK requires 3 dB more in terms of Eb/N0 to give the same Pe as BPSK so it comes out to be %.2f dB'%(10*math.log10(x)+3);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Eb/No For BPSK is 10.54 dB\n",
        "FSK requires 3 dB more in terms of Eb/N0 to give the same Pe as BPSK so it comes out to be 13.54 dB\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.2, Page 259"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Pe=10.**-6;#Probability of error\n",
      "No=10.**-10;  # PSD in W/Hz\n",
      "R=100*10**3;  #data rate in bps\n",
      "\n",
      "#Calculations\n",
      "#From Example 9.1, Eb/N0= 10.54dB (11.32) for Pe=10**-6 \n",
      "#Therefore\n",
      "Eb_No=11.32; #From Exa. 9.1\n",
      "# Eb/No = A**2/(2*No*R);\n",
      "A=math.sqrt(2*No*(Eb_No)*R);\n",
      "\n",
      "#Result\n",
      "print 'Amplitude of a carrier signal is %.3f mV'%(A*1000);\n",
      "#Incorrect answer in textbook"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Amplitude of a carrier signal is 15.047 mV\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.3, Page 267"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "B=['00','10','01','11','01','00','11','10','10','01','01','00'];#Given Bit stream\n",
      "\n",
      "#Calculations&Results\n",
      "print \"Phase transition table for pi/4-DQPSK Modulation is given as \"\n",
      "print \" By Referring Table 9.1 on page No 266 i.e\"\n",
      "print \"Symbol    Phase transition\"\n",
      "print \"00     =>    45\u00b0\"\n",
      "print \"01     =>   135\u00b0\"\n",
      "print \"10     =>   -45\u00b0\"\n",
      "print \"11     =>  -135\u00b0\"\n",
      "print \"sym      Dell phi(k)   Phi(k)\"\n",
      "#BitStream='001001110100111010010100';\n",
      "\n",
      "phase=0; #Taking initial phase as zero\n",
      "for i in range(0,12):\n",
      "    if(B[i]=='00'):\n",
      "        phase=phase+45;  \n",
      "        print ' %s          45          %d'%(B[i],phase);\n",
      "    \n",
      "    if(B[i]=='01'):\n",
      "        phase=phase+135;\n",
      "        print ' %s         135          %d'%(B[i],phase);\n",
      "    \n",
      "    if(B[i]=='10'):\n",
      "        phase=phase-45;\n",
      "        print ' %s         -45          %d'%(B[i],phase);\n",
      "    \n",
      "    if(B[i]=='11'):\n",
      "        phase=phase-135;\n",
      "        print ' %s        -135          %d'%(B[i],phase);\n",
      "   \n",
      "\n",
      "print 'final phase for the pi/4-DQPSK modulation method for given bitstream is %d degree'%phase"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Phase transition table for pi/4-DQPSK Modulation is given as \n",
        " By Referring Table 9.1 on page No 266 i.e\n",
        "Symbol    Phase transition\n",
        "00     =>    45\u00b0\n",
        "01     =>   135\u00b0\n",
        "10     =>   -45\u00b0\n",
        "11     =>  -135\u00b0\n",
        "sym      Dell phi(k)   Phi(k)\n",
        " 00          45          45\n",
        " 10         -45          0\n",
        " 01         135          135\n",
        " 11        -135          0\n",
        " 01         135          135\n",
        " 00          45          180\n",
        " 11        -135          45\n",
        " 10         -45          0\n",
        " 10         -45          -45\n",
        " 01         135          90\n",
        " 01         135          225\n",
        " 00          45          270\n",
        "final phase for the pi/4-DQPSK modulation method for given bitstream is 270 degree\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.4, Page 270"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "CHBW=200; #Channel BW in KHz\n",
      "R=270.83; #Data rate in kbps\n",
      "Fc=900;  #carrier frequency in MHz\n",
      "\n",
      "#Calculations\n",
      "FreqShift=0.5*R;\n",
      "#Transmitted Frequencies\n",
      "Fh=Fc*1000+0.25*R;#Max\n",
      "Fl=Fc*1000-0.25*R;#Min\n",
      "BWEff=R/CHBW;\n",
      "\n",
      "#Results\n",
      "print 'The frequency shift between binary 1 and binary 0 is %.3f kHz'%FreqShift;\n",
      "print 'Maximum and Minimum value of transmitted frequencies are %.4f mHz and %.4f mHz respectively'%(Fh/1000,Fl/1000);\n",
      "print 'Bandwidth efficiency is %.2f bps/Hz'%BWEff"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The frequency shift between binary 1 and binary 0 is 135.415 kHz\n",
        "Maximum and Minimum value of transmitted frequencies are 900.0677 mHz and 899.9323 mHz respectively\n",
        "Bandwidth efficiency is 1.35 bps/Hz\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.5, Page 271"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "R=270.; #data rate in kbps\n",
      "Eb_No=6.; # in dB\n",
      "GMSK=0.3; #Gaussian minimum shift keying\n",
      "\n",
      "#Calculations&Results\n",
      "Tb=1./R *10**3; #in microsec\n",
      "B=GMSK/Tb;\n",
      "print '3-dB BW for a gaussian low pass filter is %.f kHz'%(B*1000);\n",
      "PowerBW=1.41*R;\n",
      "DegradFac=0.89;\n",
      "Pe=math.erfc(math.sqrt(2*DegradFac*10**(0.1*Eb_No)));\n",
      "print 'Power bandwidth in the RF channel is %.1f kHz'%PowerBW\n",
      "print 'Bit error probability for GMSK is %.1e'%Pe;  #Incorrect answer in textbook"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "3-dB BW for a gaussian low pass filter is 81 kHz\n",
        "Power bandwidth in the RF channel is 380.7 kHz\n",
        "Bit error probability for GMSK is 1.7e-04\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.6, Page 273"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "Rs=19200; #symbols per second\n",
      "states=64;\n",
      "\n",
      "#Calculations\n",
      "Bits_symbol=math.log(states,2);\n",
      "BitRate=Bits_symbol*Rs;\n",
      "\n",
      "#Result\n",
      "print 'Bit Rate of the modulator is %.1f kbps'%(BitRate/1000)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Bit Rate of the modulator is 115.2 kbps\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.7, Page 274"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import scipy\n",
      "from scipy.optimize import fsolve\n",
      "\n",
      "#Variable declaration\n",
      "Rb=144; #data rate in kbps\n",
      "BW=36; #in MHz\n",
      "Pb=3*10**-5;#probability of bit error\n",
      "\n",
      "#Calculations\n",
      "Seff=Rb/BW;  #spectral efficiency in bps/Hz\n",
      "M=2**(Rb/BW); #since the channel is band limited\n",
      "\n",
      "#since Q[sqrt(2*Eb_No)]=(1/2)*erfc[sqrt(Eb_No)]            # refer page no 257 equ 9.35\n",
      "def f(x):\n",
      "    y=(3./8)*math.erfc(math.sqrt((2./5)*x))-Pb       #from eqn 9.66 and 9.35\n",
      "    return y\n",
      "               \n",
      "x = fsolve(f,0.1)\n",
      "\n",
      "#Result\n",
      "print 'For a rectangular constellation (refer Figure 9.12), with a Gaussian channel and matched \ufb01lter reception, the calculated Eb/No value is %.1f dB'%(10*math.log10(x));"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For a rectangular constellation (refer Figure 9.12), with a Gaussian channel and matched \ufb01lter reception, the calculated Eb/No value is 12.9 dB\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.8, Page 274"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import scipy\n",
      "from scipy.optimize import fsolve\n",
      "\n",
      "#Variable declaration\n",
      "Pb=10**-8;#BER probability\n",
      "\n",
      "#Calculations&Results\n",
      "print \"For 16-PSK:\"\n",
      "# Pb=0.5*Q(0.552*sqrt(Eb_No));\n",
      "#since Q[sqrt(2*Eb_No)]=(1/2)*erfc[sqrt(Eb_No)]            # refer page no 257 equ 9.35\n",
      "def f(x):\n",
      "    y=0.25*math.erfc(math.sqrt(0.5*0.552**2*x))-Pb\n",
      "    return y\n",
      "\n",
      "x = fsolve(f,0.1)\n",
      "\n",
      "print 'Using equation 9.50 we get Eb/No as %d dB (approx)'%round(10*math.log10(x));\n",
      "\n",
      "print \"For 16-QAM\"\n",
      "#Pb=0.75*Q(sqrt(0.8*Eb_No));\n",
      "def f(x1):\n",
      "    y=(3./8)*math.erfc(math.sqrt(0.4*x1))-Pb\n",
      "    return y\n",
      "    \n",
      "x1 = fsolve(f,0.1)\n",
      "\n",
      "#since Q[sqrt(2*Eb_No)]=(1/2)*erfc[sqrt(Eb_No)] # refer page no 257 equ 9.35\n",
      "print 'Using equation 9.66 we get Eb/No as %d dB (approx)'%round(10*math.log10(x1));\n",
      "print 'Thus 16-QAM has an advantage of about %d dB compared to 16-PSK'%(10*math.log10(x)-10*math.log10(x1));"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For 16-PSK:\n",
        "Using equation 9.50 we get Eb/No as 20 dB (approx)\n",
        "For 16-QAM\n",
        "Using equation 9.66 we get Eb/No as 16 dB (approx)\n",
        "Thus 16-QAM has an advantage of about 4 dB compared to 16-PSK\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.9, Page 277"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "M=8; #number of different signal elements\n",
      "Fc=250; #carrier frequency in kHz\n",
      "DelF=25; #kHz\n",
      "Pe=10**-6;#probability of error\n",
      "\n",
      "#Calculations\n",
      "TotalBW=2*M*DelF;\n",
      "nb=2*math.log(M,2)/(M+3);\n",
      "#Pe=7*Q(z) and z=approx(5.08)\n",
      "z=5.08;\n",
      "Eb_No=(z)**2/math.log(M,2);\n",
      "bits_sym=math.log(M,2);\n",
      "\n",
      "#Results\n",
      "print 'Total bandwidth required is %d kHz \\n '%TotalBW;\n",
      "print 'The bandwidth efficiency is %.4f \\n '%nb;\n",
      "print 'The required Eb/No is %.3f dB \\n '%(10*math.log10(Eb_No));\n",
      "print 'Carried bits per symbol are %d \\n '%bits_sym;"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Total bandwidth required is 400 kHz \n",
        " \n",
        "The bandwidth efficiency is 0.5455 \n",
        " \n",
        "The required Eb/No is 9.346 dB \n",
        " \n",
        "Carried bits per symbol are 3 \n",
        " \n"
       ]
      }
     ],
     "prompt_number": 10
    }
   ],
   "metadata": {}
  }
 ]
}