summaryrefslogtreecommitdiff
path: root/Analog_and_digital_communication/Chapter8.ipynb
blob: ada93f19c7e0ecc205382eed07c6641f465e4542 (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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
{
 "metadata": {
  "name": "",
  "signature": "sha256:40e21dfb7d9d57e8191a618fb51fc2251d54b9cc53424ce90fa65f1447f5fe95"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 - Waveform coding techniques"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2 - pg 386"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the transmission bandwidth and final bit rate\n",
      "import math\n",
      "from math import log10\n",
      "#given\n",
      "f_m = 4.2*10**6#bandwidth of television signal\n",
      "q = 512. #quantization levels\n",
      "\n",
      "#calculations\n",
      "#number of bits and quantization levels are related in binary PCM as q = 2^v \n",
      "#where v is code word length\n",
      "v = (log10(q)/log10(2));#code word length\n",
      "BW = v*f_m#transmission channel bandwidth which is greater than or equal to obtained value\n",
      "f_s = 2*f_m#sampling frequency which is greater than or equal to obtained value\n",
      "r = v*f_s#signaling rate of final bit rate\n",
      "SbyN_dB = 4.8 + 6*v#output signal to noise ratio which is less than or equal to obtained value\n",
      "\n",
      "#results\n",
      "print \"i.  Code word length (bits) = \",v\n",
      "print \"ii. Transmission bandwidth (MHz) = \",round(BW/10**6,1)\n",
      "print \"iii.Final bit rate (bits/sec) = \",r\n",
      "print \"iv.Output signal to quantization noise ratio (dB) = \",SbyN_dB\n",
      "print \"Note:There is misprint in the question i.e TV signal bandwidth \"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.  Code word length (bits) =  9.0\n",
        "ii. Transmission bandwidth (MHz) =  37.8\n",
        "iii.Final bit rate (bits/sec) =  75600000.0\n",
        "iv.Output signal to quantization noise ratio (dB) =  58.8\n",
        "Note:There is misprint in the question i.e TV signal bandwidth \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - pg 387"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the number of bits required, bandwidth required and signalling rate\n",
      "import math\n",
      "#given\n",
      "f_m = 4.*10**3#maximum frequency or bans\n",
      "x_max = 3.8#maximun input signal\n",
      "P = 30.*10**-3#average power of signal\n",
      "SbyN_dB= 20.#signal to noise ratio in db\n",
      "\n",
      "#calculations\n",
      "SbyN = math.exp((SbyN_dB/10)*math.log(10));\n",
      "v = round((math.log10((SbyN*(x_max)**2)/(3*P))/math.log10(2.)/2.));#number of bits required per sample\n",
      "BW = 30*v*f_m#transmission channel bandwidth which is greater than or equal to obtained value\n",
      "r=BW*2#wkt signalling rate is two times the transmission bandwidth\n",
      "\n",
      "#resulta\n",
      "print \"i.Number of bits required (bits) = \",round(v,2)\n",
      "print \"ii.Bandwidth required for 30 PCM coders (kHz) = \",round(BW/1000.,0)\n",
      "print \"iii.Signalling rate (bitspersecond) = \",round(r/1000.,0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Number of bits required (bits) =  7.0\n",
        "ii.Bandwidth required for 30 PCM coders (kHz) =  840.0\n",
        "iii.Signalling rate (bitspersecond) =  1680.0\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4 - pg 388"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the minumum sampling rate and minumum bit rate required\n",
      "import math\n",
      "#given\n",
      "e_max = .001#maximum quantization error\n",
      "x_max = 10.#maximum amplitude\n",
      "x_min = -10.#minumum amplitude\n",
      "f_m = 100.#bandwidth of ;input signal\n",
      "\n",
      "#calculations\n",
      "delta = 2*e_max#step size\n",
      "q = (2*x_max)/delta#quantization levels\n",
      "f_s = 2*f_m#sampling frequency\n",
      "v = math.ceil(math.log10(q) /math.log10(2));#number of bits in the PCM word\n",
      "r = v * f_s#bit rate required in the PCM signal which is greater than or equal to obtained value\n",
      "BW = .5*r#transmission channel bandwidth which is greater than or equal to obtained value\n",
      "\n",
      "#results\n",
      "print \"i.Minimum sampling rate required (Hz) = \",f_s\n",
      "print \"ii.Number of bits in each PCM word (bits) = \",round(v,2)\n",
      "print \"iii.Minimum bit rate required in the PCM signal (bits/sec) = \",round(r,0)\n",
      "print \"iv.Transmission bandwidth (Hz) = \",round(BW,0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Minimum sampling rate required (Hz) =  200.0\n",
        "ii.Number of bits in each PCM word (bits) =  14.0\n",
        "iii.Minimum bit rate required in the PCM signal (bits/sec) =  2800.0\n",
        "iv.Transmission bandwidth (Hz) =  1400.0\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5 - pg 389"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the transmission bandwidth and sampling frequency\n",
      "#given\n",
      "f_m = 3.4*10**3#maximum frequency in the signal\n",
      "N =24.#number of voice signals\n",
      "r = 1.5*10**6#signaling rate\n",
      "v  = 8.#bits  of encoder\n",
      "\n",
      "#calculations\n",
      "BW = N * f_m#transmission bandwidth\n",
      "r_1 = r/N#bit rate for one channel\n",
      "f_s = r_1/v#sampling frquency\n",
      "\n",
      "#results\n",
      "print \"i.Transmission bandwidth (kHz) = \",BW/1000.\n",
      "print \"ii.Sampling frequency (Hz or samples per second) = \",f_s\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Transmission bandwidth (kHz) =  81.6\n",
        "ii.Sampling frequency (Hz or samples per second) =  7812.5\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6 - pg 389"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the maximum message bandwidth and signal to noise ratio\n",
      "\n",
      "#given\n",
      "v = 7.#bits  of encoder\n",
      "r = 50.*10**6#bit rate of the system\n",
      "\n",
      "#calculations\n",
      "f_m = r/(2*v)#maximum message bandwidth which is less than or equal to obtained value\n",
      "SbyN_dB = 1.8 + 6*v#signal to noise ratio in dB\n",
      "\n",
      "#results\n",
      "print \"i.Maximum message bandwidth (Hz) = \",round(f_m/10**6,2)\n",
      "print \"ii.Signal to noise ratio when modulating frquency is 1MHz applied (dB) = \",SbyN_dB\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Maximum message bandwidth (Hz) =  3.57\n",
        "ii.Signal to noise ratio when modulating frquency is 1MHz applied (dB) =  43.8\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7 - pg 390"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the Minimum sampling rate and bit transmission rate\n",
      "import math\n",
      "from math import log\n",
      "#given\n",
      "f_m = 3*10**3#maximum frequency\n",
      "M = 16.#number of quantization levels\n",
      "q = M #number of quantization levels\n",
      "\n",
      "#calculations\n",
      "v = log(q)/log(2);#number of bits\n",
      "f_s = 2*f_m#sampling frequency or rate which is greater than or equal to obtained value\n",
      "r = v*f_s#bit transmission rate which is greater than or equal to obtained value\n",
      "\n",
      "#results\n",
      "print \"i.Number of bits in a codeword (bits) = \",v\n",
      "print \"ii.Minimum sampling rate (kHz) =  \",f_s/1000.\n",
      "print \"iii.Bit transmission rate (bits/sec) = \",r\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Number of bits in a codeword (bits) =  4.0\n",
        "ii.Minimum sampling rate (kHz) =   6.0\n",
        "iii.Bit transmission rate (bits/sec) =  24000.0\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8 - pg 391"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the signal to noise ratio\n",
      "import math\n",
      "from math import log10\n",
      "#given\n",
      "f_m = 3.5*10**3#maximum frequency\n",
      "r = 50*10**3#bit rate \n",
      "v_rms = .2#rms value of input signal\n",
      "R = 1#resistance\n",
      "x_max = 2#maximum peak voltage\n",
      "\n",
      "#calculations\n",
      "f_s = 2*f_m;#sampling frequency\n",
      "v = math.ceil(r/f_s);#number of bits\n",
      "P = v_rms**2 / R#Normalized signal power\n",
      "SbyN = ((3*P) * 2**(2*v)) /(x_max**2);#signal to noise ratio\n",
      "SbyN_dB = 10*log10(SbyN)#signal to noise ratio in dB\n",
      "\n",
      "#results\n",
      "print \"i.Signal to noise ratio in dB = \",round(SbyN_dB,0)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Signal to noise ratio in dB =  33.0\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10 - pg 392"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the signal to noise ratio and number of bits needed\n",
      "import math\n",
      "#given\n",
      "#x(t) = 3*cos(500*%pi*t)\n",
      "v = 10.#number of bits\n",
      "A_m = 3.#peak voltage\n",
      "SbyN_2 = 40.#signal to noise to noise ratio in second condition\n",
      "\n",
      "#calculations\n",
      "SbyN = 1.8 +6*v#signal to noise ratio in dB\n",
      "v_2 = (40 - 1.8)/6#number of bits needed for SbyN = 40\n",
      "\n",
      "#results\n",
      "print \"i.Signal to noise to ratio in dB \",SbyN\n",
      "print \"ii.Number of bits needed for noise ratio 40 (bits) = \",math.ceil(v_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Signal to noise to ratio in dB  61.8\n",
        "ii.Number of bits needed for noise ratio 40 (bits) =  7.0\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11 - pg 393"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the maximum frequency\n",
      "\n",
      "#given\n",
      "v = 7.#number of bits\n",
      "r = 56*10**3#signaling rate\n",
      "\n",
      "#calculations\n",
      "SbyN = 1.8 +6*v#signal to noise ratio in dB\n",
      "f_s = r/v#sampling frequency\n",
      "f_m = f_s/2#maximum frequency which is less than or equal to obtained value\n",
      "\n",
      "#results\n",
      "print \"Maximum frequency (Hz) = \",f_m\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum frequency (Hz) =  4000.0\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13 - pg 404"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the maximum amplitude\n",
      "import math\n",
      "#given\n",
      "f_m = 3.*10**3#bandwidth or maximum frequency\n",
      "n = 5.#system operation times\n",
      "delta = 250.*10**-3#step size in volts\n",
      "f_m1 = 2.*10**3#given maximum frequency to calculate amplitude\n",
      "\n",
      "#calculations\n",
      "NR = 2 * f_m#nyquist rate\n",
      "f_s = n * NR#sampling frequency\n",
      "T_s = 1/f_s#sampling interval\n",
      "A_m =(delta/(2 * math.pi * f_m1* T_s))#Maximum amplitude\n",
      "\n",
      "#result\n",
      "print \"Maximum amplitude for 2KHz input sinusoid (V) = \",round(A_m,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum amplitude for 2KHz input sinusoid (V) =  0.6\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14 - pg 406"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the signalling rate\n",
      "import math\n",
      "from math import log\n",
      "#given\n",
      "f_s = 8*10**3#sampling rate\n",
      "q = 64.#quantization levels\n",
      "delta = 31.25#step size\n",
      "\n",
      "#calculations\n",
      "v = log(q)/log(2);#no fo bits in the PC\n",
      "f_s= (2*math.pi*3*10**3)/delta#signalling rate which should be greater than the obtaining value\n",
      "\n",
      "#results\n",
      "print \"Signalling rate (kHz) = \",round(f_s,2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Signalling rate (kHz) =  603.19\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15 - pg 407"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the signal to noise ratio\n",
      "import math\n",
      "#given\n",
      "f_m = 2.*10**3#maximum frequency\n",
      "f_s = 64.*10**3#sampling frequency\n",
      "f_M = 4.*10**3#cut off frequency of low pass filter\n",
      "\n",
      "#calculation\n",
      "SNR_0 = (3 * f_s**3) /(8 * math.pi**2 * f_m**2 * f_M);#signal to noise ratio of linear delta modulation system\n",
      "SNR_dB = 10*math.log10(SNR_0);#SNR in dB\n",
      "\n",
      "#result\n",
      "print \"Signal to noise ratio of linear delta modulation system (dB) = \",round(SNR_dB,2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Signal to noise ratio of linear delta modulation system (dB) =  27.94\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16 - pg 407"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the signal to noise ratio\n",
      "\n",
      "#given\n",
      "r = 64.*10**3#data rate\n",
      "f_s = 8.*10**3#sampling frequency\n",
      "N = 8.#number of samples\n",
      "\n",
      "#calcualtion\n",
      "SNR_q = 1.8 + 6*N#signal to noise ratio\n",
      "\n",
      "#result\n",
      "print \"Signla to noise ratio (dB) = \",SNR_q\n",
      "print \"The SNR of a DM system is 27.94dB which is too poor as \\ncompared to 49.8db of an 8 bit PCM system. Thus, for all\\n the simplicity of Dm,it cannot perform as well as an\\n 8 bit PCM\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Signla to noise ratio (dB) =  49.8\n",
        "The SNR of a DM system is 27.94dB which is too poor as \n",
        "compared to 49.8db of an 8 bit PCM system. Thus, for all\n",
        " the simplicity of Dm,it cannot perform as well as an\n",
        " 8 bit PCM\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17 - pg 413"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the sampling frequency and quantizing level\n",
      "import math\n",
      "#given\n",
      "r = 36000.#bit rate of a channel\n",
      "f_m = 3.2*10**3#maximum frequency\n",
      "\n",
      "#calculations\n",
      "f_s = 2*f_m#sampling frequency\n",
      "v  = math.floor(r/f_s)#number of binary digits\n",
      "q = 2**v#quantizing level\n",
      "f_s2=r/v\n",
      "#results\n",
      "print \"i.Sampling frequency (Hz) = \",f_s\n",
      "print \"ii.Number of binary digits = \",round(v,1)\n",
      "print \"iii.Quantizing level = \",round(q,0)\n",
      "print \"iv. Sampling rate (Hz) = \",f_s2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.Sampling frequency (Hz) =  6400.0\n",
        "ii.Number of binary digits =  5.0\n",
        "iii.Quantizing level =  32.0\n",
        "iv. Sampling rate (Hz) =  7200.0\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 20 - pg 415"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the number of required levels and output signal to quantizing noise ratio\n",
      "import math\n",
      "from math import log, exp, sqrt\n",
      "#given\n",
      "SbyN_0dB = 40.#signal to noise ratio in dB\n",
      "SbyN_0 = exp((SbyN_0dB/10)*log(10))#signal to noise ratio\n",
      "q = sqrt((2. / 3) * (SbyN_0));#quantizing level\n",
      "v = math.ceil(log(q)/log(2.))#number of binary bits\n",
      "q_1 = 2**v#number of levels required \n",
      "SbyN_dB1 = 1.76 + 6.02*v#output signal-to-quantizing noise ratio in dB\n",
      "\n",
      "#results\n",
      "print \"Number of required levels = \",v\n",
      "print \"Output signal-to-quantizing noise ratio (dB) = \",SbyN_dB1\n",
      "print \"Note : In the textbook they took number of levels as approximation so we get change\\n in SbyN\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of required levels =  7.0\n",
        "Output signal-to-quantizing noise ratio (dB) =  43.9\n",
        "Note : In the textbook they took number of levels as approximation so we get change\n",
        " in SbyN\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21 - pg 416"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the minimum number of quantizing levels and bits, bandwidth required\n",
      "import math\n",
      "from math import log,exp,sqrt\n",
      "#given\n",
      "SbyN_dB = 30.#signal to noise ratio\n",
      "f_s = 8000.#sampling rate\n",
      "\n",
      "#calculations\n",
      "#for Sbyn_dB = 1.76 + 20*logq\n",
      "x1 = (1./ 20)*(SbyN_dB - 1.76)\n",
      "q1 = exp(x1*log(10))#quantizing level for first case\n",
      "v1 = math.ceil(log(q1)/log(2))# number of bits  for first case\n",
      "f_PCM1 = (v1 / 2) * f_s#minimum required bandwidth  for first case\n",
      "#for SbyN = 20logq - 10.1\n",
      "x2 = (1./20) * (SbyN_dB + 10.1)\n",
      "q2 =  exp(x2*log(10))#quantizing level for second case\n",
      "v2 = math.ceil(log(q2)/log(2))# number of bits for second case\n",
      "f_PCM2 =  (v2 / 2) * f_s#minimum required bandwidth for second case\n",
      "\n",
      "#results\n",
      "print \"i.a.Minimum number of quantizing levels for first case = \",round(q1,2)\n",
      "print \"  b.Number of bits for first case = \",v1\n",
      "print \"  c.Minimum system bandwidth required for first case (kHz) = \",f_PCM1/1000.\n",
      "print \"ii.a.Minimum number of quantizing levels for second case = \",round(q2,1)\n",
      "print \"   b.Number of bits for second case = \",v2\n",
      "print \"   c.Minimum system bandwidth required for second case (kHz) = \",f_PCM2/1000.\n",
      "print \"Note:In the text book they took approximation in\\nquantization levels and number bits\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i.a.Minimum number of quantizing levels for first case =  25.82\n",
        "  b.Number of bits for first case =  5.0\n",
        "  c.Minimum system bandwidth required for first case (kHz) =  20.0\n",
        "ii.a.Minimum number of quantizing levels for second case =  101.2\n",
        "   b.Number of bits for second case =  7.0\n",
        "   c.Minimum system bandwidth required for second case (kHz) =  28.0\n",
        "Note:In the text book they took approximation in\n",
        "quantization levels and number bits\n"
       ]
      }
     ],
     "prompt_number": 19
    }
   ],
   "metadata": {}
  }
 ]
}