Scilab Code for Digital Communication, by Simon Haykin 1

Created by Prof. R. Senthilkumar Institute of Road and Transport Technology rsenthil signalprocess@in.com Cross-Checked by Prof. Saravanan Vijayakumaran, IIT Bombay sarva@ee.iitb.ac.in 23 August 2010

by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Text Book Companion and Scilab codes written in it can be downlaoded from the website www.scilab.in

1 Funded

Book Details
Authors: Simon Haykins Title: Digital Communication Publisher: Willey India Edition: Wiley India Edition Year: Reprint 2010 Place: Delhi ISBN: 9788126508242

1

Scilab numbering policy used in this document and the relation to the above book. Prb Problem (Unsolved problem) Exa Example (Solved example) Tab Table ARC Additionally Required Code (Scilab Code that is not part of the above book but required to solve a particular Example) AE Appendix to Example(Scilab Code that is an Appednix to a particular Example of the above book) CF Code for Figure(Scilab code that is used for plotting the respective figure of the above book ) For example, Prb 4.56 means Problem 4.56 of the above book. Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means a scilab code whose theory is explained in Section 2.3 of the book.

2

Contents
List of Scilab Codes 1 Introduction 2 Fundamental Limit on Performance 3 Detection and Estimation 4 Sampling Process 5 Waveform Coding Techniques 6 Baseband Shaping for Data Transmission 7 Digital Modulation Techniques 8 Error-Control Coding 9 Spread-Spectrum Modulation 4 2 5 14 27 31 39 59 87 94

3

List of Scilab Codes
CF 1.2 Exa 2.1 Exa 2.2 Exa 2.3 Exa 2.4 Exa 2.5 Exa 2.6 Exa 2.7 Exa 3.1 Exa 3.2 Exa 3.3 Exa 3.4 Exa 3.6 CF 3.29 Exa 4.1 Exa 4.3 Exa 5.1 Exa 5.2 Digital Representation of Analog signal . . . . . . . . Entropy of Binary Memoryless source . . . . . . . . . Second order Extension of Discrete Memoryless Source Entropy, Average length, Variance of Huffman Encoding Entropy, Average length, Variance of Huffman Encoding Binary Symmetric Channel . . . . . . . . . . . . . . . Channel Capacity of a Binary Symmetric Channel . . Significance of the Channel Coding theorem . . . . . . Orthonormal basis for given set of signals . . . . . . . M ARY Signaling . . . . . . . . . . . . . . . . . . . . Matched Filter output for RF pulse . . . . . . . . . . Matched Filter output for Noise-like signal . . . . . . . Linear Predictor of Order one . . . . . . . . . . . . . . Implementation of LMS Adaptive Filter algorithm . . Bound on Aliasing error for Time-shifted sinc pulse . . Equalizier to compensate Aperture effect . . . . . . . . Average Transmitted Power for PCM . . . . . . . . . Comparision of M-ary PCM with ideal system (Channel Capacity Theorem) . . . . . . . . . . . . . . . . . . . Exa 5.3 Signal-to-Quantization Noise Ratio of PCM . . . . . . Exa 5.5 Output Signal-to-Noise ratio for Sinusoidal Modulation CF 5.13a (a) u-Law companding . . . . . . . . . . . . . . . . . . CF 5.13b (b) A-law companding . . . . . . . . . . . . . . . . . . Exa 6.1 Bandwidth Requirements of the T1 carrier . . . . . . . CF 6.1a (a) Nonreturn-to-zero unipolar format . . . . . . . . . CF 6.1b (b) Nonreturn-to-zero polar format . . . . . . . . . . . CF 6.1c (c) Nonreturn-to-zero bipolar format . . . . . . . . . . Exa 6.2 Duobinary Encoding . . . . . . . . . . . . . . . . . . . 4 2 5 5 7 8 9 10 10 14 16 19 20 22 24 27 28 31 31 32 34 36 36 39 40 40 42 44

Exa 6.3 CF 6.4 CF 6.6b CF 6.7b CF 6.9 CF 6.15

Generation of bipolar output for duobinary coder . . . Power Spectra of different binary data formats . . . . (b) Ideal solution for zero ISI . . . . . . . . . . . . . . (b) Practical solution: Raised Cosine . . . . . . . . . Frequency response of duobinary conversion filter . . . Frequency response of modified duobinary conversion filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exa 7.1 QPSK Waveform . . . . . . . . . . . . . . . . . . . . . CF 7.1 Waveform of Different Digital Modulation techniques . Exa 7.2 MSK waveforms . . . . . . . . . . . . . . . . . . . . . CF 7.2 Signal Space diagram for coherent BPSK . . . . . . . Tab 7.3 Illustration the generation of DPSK signal . . . . . . . CF 7.4 Signal Space diagram for coherent BFSK . . . . . . . CF 7.6 Signal space diagram for coherent QPSK waveform . . Tab 7.6 Bandwidth efficiency of M ary PSK signals . . . . . . Tab 7.7 Bandwidth efficiency of M ary FSK signals . . . . . . CF 7.29 Power Spectra of BPSK and BFSK signals . . . . . . . CF 7.30 Power Spectra of QPSK and MSK signals . . . . . . . CF 7.31 Power spectra of M-ary PSK signals . . . . . . . . . . CF 7.41 Matched Filter output of rectangular pulse . . . . . . Exa 8.1 Repetition Codes . . . . . . . . . . . . . . . . . . . . . Exa 8.2 Hamming Codes . . . . . . . . . . . . . . . . . . . . . Exa 8.3 Hamming Codes Revisited . . . . . . . . . . . . . . . . Exa 8.4 Encoder for the (7,4) Cyclic Hamming Code . . . . . . Exa 8.5 Syndrome calculator for the(7,4) Cyclic Hamming Code Exa 8.6 Reed-Solomon Codes . . . . . . . . . . . . . . . . . . . Exa 8.7 Convolutional Encoding - Time domain approach . . . Exa 8.8 Convolutional Encoding Transform domain approach Exa 8.11 Fano metric for binary symmetric channel using convolutional code . . . . . . . . . . . . . . . . . . . . . . . Exa 9.1 PN sequence generation . . . . . . . . . . . . . . . . . Exa 9.2 Maximum length sequence property . . . . . . . . . . Exa 9.3 Processing gain, PN sequence length, Jamming margin in dB . . . . . . . . . . . . . . . . . . . . . . . . . . . Exa 9.4Example9.5 Fast Frequency hopping: FH/MFSK . . . . Slow and Fig 9.4Figure9.6 Sequence Spread Coherent BPSK . . . . . . . . Direct ARC 1 Alaw . . . . . . . . . . . . . . . . . . . . . . . . . . . ARC 2 auto correlation . . . . . . . . . . . . . . . . . . . . . 5

47 48 49 51 53 55 59 61 63 68 70 72 74 74 76 77 78 80 82 87 87 88 89 90 90 91 92 93 94 95 97 100 100 103 106

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PCM Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . invmulaw . . . . . . . . . . . . . . . . PCM Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . sinc new . . . . . xor . . . . . . . . . . . . . . . . . . . . uniform pcm . . . . . . Hamming Encode . . . . . . . . . . . . . . . . . . . . . . . 107 108 108 110 110 111 111 112 112 6 . . . . . . . . . .ARC ARC ARC ARC ARC ARC ARC ARC ARC 3 4 5 5 6 7 8 9 10 Convolutional Coding Hamming Distance . .

. . . . . . . . . . . .1 . . . . . . .8 Figure1. . . . .6 . . . . . . . . . . . Example3. . . . . . . . . . . .3 3. . . . . . . . . . . . . . . . . . . .1 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1c Figure6. . . . . . . . . . . . . . . . . . . . . . . .2b . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Figure6. . . . . . . . . . . . . . .1 . . . . . . . Example2. . . . . . . . .1 3. . . . . . . . . .3 . . . . . . . . .3 . . . . . . . . . . . . . .2 6. . . . . . . . . . . . . . . . . . . . .4 Figure6. . . . . . . . . . . . Example2. . . . . . . . . Figure1. . . . . . . . . . . . . . Example5. . . . . . . . . .2 5. .2 2. . . . . . . . . . . . Figure5. . Example4. . . . . . . . . . .2 . . . . . . . Figure3. . . . .2 5. . . . . . . . . . . . . . . . . . . .7 6. . . .2 3. . . . . . . . . . . .1 6. . . . Figure5. . . . . . . .13a .7 Figure6. . . .1 1. . . . . . Example3. . . . . . . . . . . .7 . . . . . . . . . . . . . . . . . . . . Example3. . . . . . . . . . . . . . . .1 4.1b .29 . . . . .3 6. . . .2 2. . . . . . .2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13b . . . Figure6. . . . . . . . . 7 . . . . .9 Figure6. . . . .3 3. . . . . . . . . . . .1b Figure6. . . . . . . . .2a . . . . . . . .4 . . . . . . .6 4. . . . . . . . . 3 4 6 11 13 16 17 19 21 23 26 28 30 33 37 38 41 43 45 50 52 54 56 58 Example4. . . . . .4 6. . . . . . . . . . . . . . . . . .1a Figure6. .3 6. .6 6. . . . . . . . Example3. . . . .4 3. . .1 2. .List of Figures 1. . . . . . . . . . . . . . . . . . . . . .5 6. . . . . . .15 . . .5 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1a . . . . . . . . . . . . . . Example2. . . . . . . . Example3. . . . .

. . . . .2 9. .1a . . . . .2 7. . . . .1 9. . . .2 . . Figure7. .7. . . .6a .11 7. . Figure7.2a . . . . Figure7. . . Figure9. . . . Figure7. .4 . . . . . . . . . . . . . . . . .1c . . . . . . .12 . . . . . . Example9. . . . . . . . . . .10 7. . . . . . . . . .6 7. . . . . . . . . . . . . . .1b . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . .31 . . . . . . . . . . . .6b .9 7. . . . . . . . .30 .13 7. . . . . . . . . . Figure7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 . . . .7 7. . . . . . . . . . . . . . . . . .4 9. . . . . . . . . . .3 9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 64 65 66 69 70 73 75 77 79 81 83 85 86 98 99 103 104 105 Example9. . . . . . . . . . . . . . . . . . . . . . . . . Figure7. . .4 7. .3 7. . . . . . . . . . . . . . . . .8 7. . . . . . . . . . . . Figure9. . . . . . . . . . . . . . . . . . . . . . . . . . . .12 7. . . . . . . . .14 9. . . . . Figure7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Figure10. . . . . . . . .2b . . Figure 7. .5 Example7.5 7. Example7. . . . . . . Figure7.6 . . .1 Figure7.1 7. . .41a Figure7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Figure7. . . . . . . . . . . . . . . . . . .29 . . . . . . .41b . . . . . . . . . . . .

a .01:1. clc .1] // figure a = gca () . x_location = ” o r i g i n ” . close .3] plot (t . -9) plot2d3 ( ’ gnn ’ .0 .0 . t = -1:0. -2 .0 . 2 : Analog t o D i g i t a l C o n v e r s i o n clear .1 . data_bounds =[ -2 .0 .0 . -3.0. -0.2 . -1 .0 .1 .0 .1 .1 . . a . -9) xlabel ( ’ Time ’ ) 21 ylabel ( ’ 2 .0 .2 Digital Representation of Analog signal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // C a p t i o n : D i g i t a l R e p r e s e n t a t i o n o f Analog s i g n a l // F i g u r e 1 .0 . -9) plot2d3 ( ’ gnn ’ .1 .0 .2 .5 . x ) plot2d3 ( ’ gnn ’ . sqrt (2) . dig_data = [0 . -9) plot2d3 ( ’ gnn ’ .sqrt (2) .1 . a .Chapter 1 Introduction Scilab code CF 1.5 .0 . x = 2* sin (( %pi /2) * t ) .0 .0 . y_location = ” o r i g i n ” .

1: Figure1.0.21 .Figure 1.2a 22 23 24 25 26 27 28 Voltage ’) title ( ’ Analog Waveform ’ ) // figure a = gca () .5) title ( ’ D i g i t a l R e p r e s e n t a t i o n ’ ) 3 . a .5]. data_bounds = [0 . dig_data . plot2d2 ([1: length ( dig_data ) ] .

2b 4 .2: Figure1.Figure 1.

Po ( i ) * log2 ( Po ( i ) ) -(1 . 6 clc .Chapter 2 Fundamental Limit on Performance Scilab code Exa 2.01:1.0.1) Scilab code Exa 2.1 Entropy of Binary Memoryless source 1 // C a p t i o n : Ent ropy o f B i n a r y M e m o r y l e s s s o u r c e 2 // Example 2 . 9 for i = 2: length ( Po ) -1 10 H_Po ( i ) = . H_Po ) 14 xlabel ( ’ Symbol P r o b a b i l i t y . Po ’ ) 15 ylabel ( ’H( Po ) ’ ) 16 title ( ’ Entropy f u n c t i o n H( Po ) ’ ) 17 plot2d3 ( ’ gnn ’ .2 Second order Extension of Discrete Memoryless Source 5 . length ( Po ) ) .Po ( i )). 7 Po = 0:0. 11 end 12 // p l o t 13 plot2d ( Po .Po ( i ) ) * log2 (1 . 5 close .5 . 8 H_Po = zeros (1 . 1 : Entropy o f B i n a r y M e m o r y l e s s S o u r c e 3 // p a g e 18 4 clear .

Figure 2.1: Example2.1 6 .

P0 = 1/4. P2 * P0 . . P0 * P1 . . disp ( ’ Entropy o f D i s c r e t e M e m o r y l e s s S o u r c e ’ ) disp ( ’ b i t s ’ . P2 * P1 . ’ P r o b a b i l i t y p ( s i g m a ) . // p r o b a b i l i t y o f s o u r c e a l p h a b e t S1 P2 = 1/2. disp ( ’ T a b l e 2 . for i = 1: length ( P_sigma ) H_Ruo_Square = H_Ruo_Square + P_sigma ( i ) * log2 (1/ P_sigma ( i ) ) . 8 ’ ) disp ( ’ ’) disp ( ’ ’) H_Ruo_Square =0. 1 A l p h a b e t P a r t i c u l a r s o f Second−o r d e r Extension o f a D i s c r e t e Memoryless Source ’ ) disp ( ’ ’) disp ( ’ S e q u e n c e o f Symbols o f r u o 2 : ’ ) disp ( ’ S0 ∗ S0 S0 ∗ S1 S0 ∗ S2 S1 ∗ S0 S1 ∗ S1 S1 ∗ S2 S2 ∗ S0 S2 ∗ S1 S2 ∗ S2 ’ ) disp ( P_sigma . 2 : Entropy o f D i s c r e t e M e m o r y l e s s s o u r c e // p a g e 19 clear . ’H( R u o S q u a r e )= ’ ) disp ( ’H( R u o S q u a r e ) = 2∗H( Ruo ) ’ ) 16 17 18 19 20 21 22 23 24 25 26 7 . H_Ruo_Square . // p r o b a b i l i t y o f s o u r c e a l p h a b e t S2 H_Ruo = P0 * log2 (1/ P0 ) + P1 * log2 (1/ P1 ) + P2 * log2 (1/ P2 ) . P1 * P1 . clc . . // p r o b a b i l i t y o f s o u r c e a l p h a b e t S0 P1 = 1/4. P1 * P2 . P1 * P0 . 1 . . P0 * P2 . P2 * P2 ]. i = 0 . end disp ( ’ b i t s ’ .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // c a p t i o n : S e c o n d o r d e r E x t e n s i o n o f D i s c r e t e Memoryless Source // Example 2 . H_Ruo ) // S e c o n d o r d e r E x t e n s i o n o f d i s c r e t e M e m o r y l e s s source P_sigma = [ P0 * P0 .

Scilab code Exa 2.L ) ^2+ P4 *( L4 . A v e r a g e l e n g t h . ’ V a r i n a c e o f Huffman c o d e ’ ) Scilab code Exa 2. disp ( sigma_1 . Variance of Huffman Encoding 1 // C a p t i o n : Entropy . A v e r a g e l e n g t h .L ) ^2. disp ( ’ b i t s ’ .1.Average length. ’ A v e r a g e code −word Length L ’ ) disp ( ’ b i t s ’ . // l e n g t h o f c o d e w o r d S4 L = P0 * L0 + P1 * L1 + P2 * L2 + P3 * L3 + P4 * L4 . // l e n g t h o f c o d e w o r d S1 P2 = 0.2. // l e n g t h o f c o d e w o r d S0 P1 = 0. V a r i a n c e o f Huffman E n c o d i n g 8 . ’ A v e r a g e code − word l e n g t h L e x c e e d s t h e e n t r o p y H( Ruo ) by o n l y ’ ) sigma_1 = P0 *( L0 . clc . H_Ruo . // p r o b a b i l i t y o f c o d e w o r d ’ 0 0 ’ L0 = 2.L ) ^2+ P2 *( L2 .L ) ^2+ P3 *( L3 . H_Ruo = P0 * log2 (1/ P0 ) + P1 * log2 (1/ P1 ) + P2 * log2 (1/ P2 ) + P3 * log2 (1/ P3 ) + P4 * log2 (1/ P4 ) .4 Entropy. Variance of Huffman Encoding 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 // C a p t i o n : Entropy .((L . // l e n g t h o f c o d e w o r d S2 P3 = 0. ’ Entropy o f Huffman c o d i n g r e s u l t H’) disp ( ’ p e r c e n t ’ . // p r o b i l i t y o f c o d e w o r d ’ 0 1 1 ’ L4 = 3.4.1.3 Entropy. // p r o b i l i t y o f c o d e w o r d ’ 0 1 0 ’ L3 = 3. // p r o b a b i l i t y o f c o d e w o r d ’ 1 0 ’ L1 = 2.H_Ruo ) / H_Ruo ) *100 . // p r o b i l i t y o f c o d e w o r d ’ 1 1 ’ L2 = 2.L . V a r i a n c e o f Huffman E n c o d i n g // Example 2 .L ) ^2+ P1 *( L1 . 3 : Huffman E n c o d i n g : C a l c u l a t i o n o f // ( a ) A v e r a g e code −word l e n g t h ’ L ’ // ( b ) E ntropy ’H’ clear .2. // l e n g t h o f c o d e w o r d S3 P4 =0. P0 = 0. Average length.

H_Ruo = P0 * log2 (1/ P0 ) + P1 * log2 (1/ P1 ) + P2 * log2 (1/ P2 ) + P3 * log2 (1/ P3 ) + P4 * log2 (1/ P4 ) . // p r o b i l i t y o f c o d e w o r d ’ 0 0 0 ’ L2 = 3. 5 : B i n a r y Symmetric Channel 3 clear . // l e n g t h o f c o d e w o r d S3 P4 =0. // l e n g t h o f c o d e w o r d S4 L = P0 * L0 + P1 * L1 + P2 * L2 + P3 * L3 + P4 * L4 .L ) ^2.L ) ^2+ P3 *( L3 . 6 p = 0. // l e n g t h o f c o d e w o r d S2 P3 = 0. // p r o b a b i l i t y o f c o r r e c t r e c e p t i o n 7 pe = 1 . P0 = 0.1.2.4. e ) transition probility 8 disp (p . disp ( sigma_2 . 4 clc .L ) ^2+ P2 *( L2 .2. ’ p r o b i l i t y o f 0 r e c e i v i n g i f a 0 i s s e n t = p r o b i l i t y o f 1 r e c e i v i n g i f a 1 i s s e n t= ’ ) 9 . H_Ruo . ’ V a r i n a c e o f Huffman c o d e ’ ) Scilab code Exa 2.2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // Example2 . clc . disp ( ’ b i t s ’ . 4 : I l l u s t r a t i n g n o n u n i q u e s s o f t h e Huffman E n c o d i n g // C a l c u l a t i o n o f ( a ) A v e r a g e code −word l e n g t h ’ L ’ ( b ) Entr opy ’H’ clear . // p r o b i l i t y o f c o d e w o r d ’ 0 0 1 1 ’ L4 = 4. // p r o b i l i t y o f e r r o r r e c e p t i o n ( i .L .L ) ^2+ P4 *( L4 . ’ Entropy o f Huffman c o d i n g r e s u l t H’) sigma_2 = P0 *( L0 . // p r o b a b i l i t y o f c o d e w o r d ’ 1 ’ L0 = 1.5 Binary Symmetric Channel 1 // C a p t i o n : B i n a r y Symmetric Channel 2 // Example2 . // l e n g t h o f c o d e w o r d S0 P1 = 0.1. 5 close .4. ’ A v e r a g e code −word Length L ’ ) disp ( ’ b i t s ’ .L ) ^2+ P1 *( L1 . // p r o b a b i l i t y o f c o d e w o r d ’ 0 1 ’ L1 = 2. // p r o b i l i t y o f c o d e w o r d ’ 0 0 1 0 ’ L3 = 4. // l e n g t h o f c o d e w o r d S1 P2 = 0.p .

7 Significance of the Channel Coding theorem // C a p t i o n : S i g n i f i c a n c e o f t h e Channel Coding t h e o r e m // Example2 . elseif ( i ==1) C ( i ) =1. 7 : S i g n i f i c a n c e o f t h e c h a n n e l c o d i n g theorem 3 // A v e r a g e P r o b i l i t y o f E r r o r o f R e p e t i t i o n Code 1 2 10 . clc .6 Channel Capacity of a Binary Symmetric Channel 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n : Channel C a p a c i t y o f a B i n a r y Symmetric Channel // Example2 . 1 0 V a r i a t i o n o f c h a n n e l c a p a c i t y o f a binary symmetric channel with t r a n s i t i o n probility p ’) Scilab code Exa 2.5) xlabel ( ’ T r a n s i t i o n P r o b i l i t y . p = 0:0. C ’ ) title ( ’ F i g u r e 2 . for i =1: length ( p ) if ( i ~=1) C ( i ) = 1+ p ( i ) * log2 ( p ( i ) ) +(1 .01:0.p ( i ) ) * log2 ((1 .5.p ( i ) ) ) . ’ p r o b i l i t y o f 0 r e c e i v i n g i f a 1 i s s e n t = p r o b i l i t y o f 1 r e c e i v i n g i f a 0 i s s e n t= ’ ) Scilab code Exa 2. p ’ ) ylabel ( ’ Channel C a p a c i t y . elseif ( i == length ( p ) ) C ( i ) =0. end end plot2d (p . close .9 10 disp ( ’ T r a n s i t i o n p r o b i l i t y ’ ) disp ( pe . 6 : Channel C a p a c i t y o f B i n a r y Symmetri Channel clear .C .

Figure 2.6 11 .2: Example2.

pe . // p r o b i l i t y o f e r r o r f o r c o d e r a t e r =1/3 10 pe_5 = 10* p ^3*(1 . r =1/n ’ . pe .1/3 . pe_5 . 16 plot2d (r . 5 clc .1/5 .p ) ^2+5* p ^4*(1 . 8 pe_1 = p . 14 a = gca () .p ) + p ^7. pe_3 . Pe ’ ) 25 disp ( ’ ’) 12 .p ) + p ^3. 6 close . r ’ ) 18 ylabel ( ’ A v e r a g e P r o b a b i l i t y o f e r r o r . 7 p =10^ -2. 15 a .p ) + p ^5. data_bounds =[0 .5) 17 xlabel ( ’ Code r a t e .4 clear .p ) ^2+7* p ^6*(1 . Pe ’ ) 19 title ( ’ F i g u r e 2 .01].0. // e r r o r f o r c o d e r a t e r =1/7 12 r = [1 . ’ Code Rate .1 . ’ A v e r a g e P r o b i l i t y o f E r r o r . 13 pe = [ pe_1 . // A v e r a g e P r o b i l i t y o f e r r o r f o r code r a t e r = 1 9 pe_3 = 3* p ^2*(1 . 1 2 I l l u s t r a t i n g s i g n i f i c a n c e o f t h e channel coding theorem ’ ) 20 legend ( ’ R e p e t i t i o n c o d e s ’ ) 21 xgrid (1) 22 disp ( ’ T a b l e 2 .p ) ^3+(42/2) * p ^5*(1 . // e r r o r f o r c o d e r a t e r =1/5 11 pe_7 = ((7*6*5) /(1*2*3) ) * p ^4*(1 . 3 A v e r a g e P r o b i l i t y o f E r r o r f o r R e p e t i t i o n Code ’ ) 23 disp ( ’ ’) 24 disp (r .0. pe_7 ].1/7].

7 13 .3: Example2.Figure 2.

phi2t = sqrt (3/ T ) *[0 .1 Orthonormal basis for given set of signals 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // C a p t i o n : O r t h o n o r m a l b a s i s f o r g i v e n s e t o f s i g n a l s // Example3 . 1 : F i n d i n g o r t h o n o r m a l b a s i s f o r t h e g i v e n signals // u s i n g Gram−Schmidt o r t h o g o n a l i z a t i o n p r o c e d u r e clear . length ( t5 ) -2) . length ( t7 ) -2) .0].01:2* T /3. clc .0]. t7 = 2* T /3:0. t6 = T /3:0. s2t = [0 . T = 1. t4 = 0:0. ones (1 .01: T . phi3t = sqrt (3/ T ) *[0 . t5 = 0:0.Chapter 3 Detection and Estimation Scilab code Exa 3.01: T /3.0].01: T .0].0].01: T . s4t = [0 . s1t = [0 .0]. ones (1 . length ( t2 ) -2) . ones (1 .01: T /3. length ( t4 ) -2) . close . length ( t3 ) -2) .0]. t1 = 0:0. ones (1 . phi1t = sqrt (3/ T ) *[0 . // 14 . ones (1 . length ( t6 ) -2) . t3 = T /3:0. ones (1 .01:2* T /3. s3t = [0 . length ( t1 ) -2) . t2 = 0:0. ones (1 .

s3t .1) a = gca () .2) a = gca () .5) xlabel ( ’ t ’ ) ylabel ( ’ p h i 1 ( t ) ’ ) subplot (3 .5) xlabel ( ’ t ’ ) ylabel ( ’ s 3 ( t ) ’ ) subplot (4 .4) a = gca () .4]. s1t . plot2d2 ( t3 . data_bounds = [0 . plot2d2 ( t2 .2].1) a = gca () .1 .5) xlabel ( ’ t ’ ) ylabel ( ’ s 4 ( t ) ’ ) // figure title ( ’ F i g u r e 3 .3) a = gca () . a .2 .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 figure title ( ’ F i g u r e 3 .0.0.0.2) 15 . data_bounds = [0 . 4 ( b ) The r e s u l t i n g s e t o f o r t h o n o r m a l functions ’) subplot (3 . a .1 . a .2]. plot2d2 ( t1 . s2t .1 .1 . data_bounds = [0 . a .0.1 . a . data_bounds = [0 .1 . plot2d2 ( t5 . 4 ( a ) S e t o f s i g n a l s t o be orthonormalized ’) subplot (4 .2 .2 .0. plot2d2 ( t4 .5) xlabel ( ’ t ’ ) ylabel ( ’ s 1 ( t ) ’ ) subplot (4 . data_bounds = [0 .2 .5) xlabel ( ’ t ’ ) ylabel ( ’ s 2 ( t ) ’ ) subplot (4 .2 .2].2]. s4t . phi1t .

1 . data_bounds = [0 . a . phi3t . a . data_bounds = [0 .4]. plot2d2 ( t7 .3) a = gca () .1: Example3.2 .5) xlabel ( ’ t ’ ) ylabel ( ’ p h i 2 ( t ) ’ ) subplot (3 .5) xlabel ( ’ t ’ ) ylabel ( ’ p h i 3 ( t ) ’ ) 16 . plot2d2 ( t6 .Figure 3.0. phi2t .4].1a 59 60 61 62 63 64 65 66 67 68 69 a = gca () .0.2 .

1b 17 .2: Example3.Figure 3.

Scilab code Exa 3. D e c i s i o n i n t e r v a l s f o r received dibits ’) disp ( ’ R e c e i v e d d i b i t | 00 | | 11 | 10 ’ ) disp ( ’ 20 21 22 23 24 25 01 01 ’) 26 disp ( ’ I n t e r v a l on p h i 1 ( t ) | x1 < −a . a .0. s q r t ( 18 . clc . a = gca () .2 M ARY Signaling 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n :M −ARY S i g n a l i n g // Example3 .(3/2) * a * sqrt ( T ) . -0. data_bounds = [ -2 . s q r t (T) |− a . 2 : M −ARY SIGNALING // S i g n a l c o n s t e l l a t i o n and R e p r e s e n t a t i o n o f d i b i t s clear .0 . o f meg . 8 ( b ) . a =1. // a m p l i t u d e =1 T =1. R e p r e s e n t a t i o n o f t r a n s m i t t e d dibits ’) disp ( ’ Loc . close .( -1/2) * a * sqrt ( T ) . 8 ( c ) .0 . // Symbol d u r a t i o n i n s e c o n d s // Four m e s s a g e p o i n t s Si1 = [( -3/2) * a * sqrt ( T ) .0] . 8 ( a ) S i g n a l c o n s t e l l a t i o n ’ ) xgrid (1) disp ( ’ F i g u r e 3 .2 .5] plot2d ( Si1 .5.(1/2) * a * sqrt ( T ) ]. p o i n t | ( −3/2) a s q r t (T) | ( − 1 / 2 ) a s q r t ( T) | ( 3 / 2 ) a s q r t (T) | ( 1 / 2 ) a s q r t (T) ’ ) disp ( ’ ’) disp ( ’ T r a n s m i t t e d d i b i t | 00 | | 11 | 10 ’ ) disp ( ’ ’ ) disp ( ’ ’ ) disp ( ’ F i g u r e 3 . -10) xlabel ( ’ p h i 1 ( t ) ’ ) title ( ’ F i g u r e 3 .[0 .

2 T)<x1 <0| 0<x1<a .3 Matched Filter output for RF pulse 1 2 3 4 5 6 7 8 // C a p t i o n : Matched F i l t e r o u t p u t f o r RF p u l s e // Example3 .01: T . 3 : MATCHED FILTER FOR RF PULSE clear . clc . fc =4. s q r t (T)<x1 ’ ) Scilab code Exa 3. // c a r r i e r f r e q u e n c y i n Hz T =1.3: Example3. t1 = 0:0. close . 19 .Figure 3. s q r t (T) | a .

a . a .1 . phit ) . -1.1 . y_location = ” o r i g i n ” . t2 = 0:0. hopt ) . xlabel ( ’ t ’) ylabel ( ’ phi ( t ) ’ ) title ( ’ F i g u r e 3 . 1 3 ( b ) Matched F i l t e r o u t p u t ’ ) Scilab code Exa 3.1) a = gca () . hopt = phit . data_bounds = [0 .4 Matched Filter output for Noise-like signal 21 22 23 24 25 26 27 28 29 30 31 // C a p t i o n : Matched F i l t e r o u t p u t f o r N o i s e − l i k e signal 2 // Example3 . data_bounds = [0 . xlabel ( ’ t ’) ylabel ( ’ phi0 ( t ) ’ ) title ( ’ F i g u r e 3 .1]. a . plot2d ( t1 . a . x_location = ” o r i g i n ” . phiot ) . 1 3 ( a ) RF p u l s e i n p u t ’ ) subplot (2 . a . a . phiot = convol ( phit . phiot = phiot / max ( phiot ) . 4 : Matched F i l t e r o u t p u t f o r n o i s e l i k e 1 20 .1 .9 10 11 12 13 14 15 16 17 18 19 20 phit = sqrt (2/ T ) * cos (2* %pi * fc * t1 ) . x_location = ” o r i g i n ” . subplot (2 .2) a = gca () .1].01:2* T .1 . plot2d ( t2 . -1. y_location = ” o r i g i n ” .

3 21 .Figure 3.4: Example3.

1 6 ( b ) Matched F i l t e r o u t p u t ’ ) Scilab code Exa 3.1]. a . plot2d ([1: length ( phit ) ] .1]. x_location = ” o r i g i n ” .3 4 5 6 7 8 9 10 11 12 13 14 15 16 input clear . a . y_location = ” o r i g i n ” . 1 6 ( a ) N o i s e L i k e i n p u t s i g n a l ’ ) subplot (2 . -1. hopt = phit . phi0t ) . plot2d ([1: length ( phi0t ) ] . y_location = ” o r i g i n ” . data_bounds = [0 . phi0t = phi0t / max ( phi0t ) . data_bounds = [0 . subplot (2 .1 .1 . xlabel ( ’ t ’) ylabel ( ’ phi0 ( t ) ’ ) title ( ’ F i g u r e 3 . hopt ) . clc . phi0t = convol ( phit .6 Linear Predictor of Order one 17 18 19 20 21 22 23 24 25 26 27 22 . -1. x_location = ” o r i g i n ” . a .1 . ’ u n i f o r m ’ ) . xlabel ( ’ t ’) ylabel ( ’ phi ( t ) ’ ) title ( ’ F i g u r e 3 .1) a = gca () .1* rand (1 .2) a = gca () . phit ) . a . a . a .1 .10 . close . phit =0.

5: Example3.4 23 .Figure 3.

1) . order = 18.6]. ’ P r e d i c t o r i n p u t v a r i a n c e ’ ) if ( sigma_X > sigma_E ) disp ( ’ The p r e d i c t o r −e r r o r v a r i a n c e i s l e s s t h a n the variance of the p r e d i c t o r input ’ ) end Scilab code CF 3.order -1 buffer = ref_noise ( i : i + order -1) . Rxx ( 3 ) = Rxx ( 1 ) sigma_E = Rxx (2) .29 Implementation of LMS Adaptive Filter algorithm 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // I m p l e m e n t a t i o n o f LMS ADAPTIVE FILTER // For n o i s e c a n c e l l a t i o n a p p l i c a t i o n clear . 6 : LINEAR PREDICTION : P r e d i c t o r o f Order One clear . ’ P r e d i c t o r −e r r o r v a r i a n c e ’ ) disp ( sigma_X . ref_noise = noise * rand (10) .6 1 0. clc . close . desired ( i ) = x_n ( i ) .buffer * w . x_n = x + noise . 24 .01*( sum ( x . w = zeros ( order . disp ( sigma_E . N = length ( x ) .1 2 3 4 5 6 7 8 9 10 11 12 13 14 // C a p t i o n : L i n e a r P r e d i c t o r o f Order one // Example3 .^2) / length ( x ) ) . sigma_X = Rxx (2) .h01 * Rxx (3) . h01 = Rxx (3) / Rxx (2) . x = sin (2* %pi *5* t ) . Rxx = [0. t =0:0. // Rxx ( 2 ) = Rxx ( 0 ) . clc . noise = rand (1 . mu = 0. close . for k =1:1010 for i = 1: N . length ( x ) ) .01:1.

2) 26 plot2d (t . noise .19 w = w +( buffer * mu * desired ( i ) ) ’.3) 29 plot2d (t . x_n .1) 23 plot2d (t .1 .1 . 20 end 21 end 22 subplot (4 .5) 30 title ( ’ S i g n a l+n o i s e ’ ) 31 subplot (4 . x ) 24 title ( ’ O r i g n a l I n p u t S i g n a l ’ ) 25 subplot (4 .4) 32 plot ( desired ) 33 title ( ’ n o i s e removed s i g n a l ’ ) 25 .1 .2) 27 title ( ’ random n o i s e ’ ) 28 subplot (4 .1 .

Figure 3.6: Figure3.29

26

Chapter 4 Sampling Process
Scilab code Exa 4.1 Bound on Aliasing error for Time-shifted sinc pulse
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// C a p t i o n : Bound on A l i a s i n g e r r o r f o r Time− s h i f t e d sinc pulse // Example4 . 1 : Maximum bound on a l i a s i n g e r r o r f o r sinc pulse clc ; close ; t = -1.5:0.01:2.5; g = 2* sinc_new (2* t -1) ; disp ( max ( g ) , ’ A l i a s i n g e r r o r c a n n o t e x c e e d max | g ( t ) | ’ ) f = -1:0.01:1; G = [0 ,0 ,0 ,0 , ones (1 , length ( f ) ) ,0 ,0 ,0 ,0]; f1 = -1.04:0.01:1.04; subplot (2 ,1 ,1) a = gca () ; a . data_bounds =[ -3 , -1;2 ,2]; a . x_location = ” o r i g i n ” a . y_location = ” o r i g i n ” plot2d (t , g ) xlabel ( ’ t ’) ylabel ( ’ g( t ) ’) title ( ’ F i g u r e 4 . 8 ( a ) S i n c p u l s e g ( t ) ’ ) subplot (2 ,1 ,2) 27

Figure 4.1: Example4.1
21 22 23 24 25 26 27 28

a = gca () ; a . data_bounds =[ -2 ,0;2 ,2]; a . x_location = ” o r i g i n ” a . y_location = ” o r i g i n ” plot2d2 ( f1 , G ) xlabel ( ’ f ’) ylabel ( ’ G( f ) ’ ) title ( ’ F i g u r e 4 . 8 ( b ) A m p l i t u d e s p e c t r u m |G( f ) | ’ ) Scilab code Exa 4.3 Equalizier to compensate Aperture effect

1

// C a p t i o n : E q u a l i z e r t o c o m p e n s a t e A p e r t u r e e f f e c t 28

0.8 . 5 ∗ T Ts ) ) .2].0. plot2d ( T_Ts .8. close . 5 ( T/ Ts ) ) ’ ) title ( ’ F i g u r e 4 . E (1) =1.2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // Example4 . for i = 2: length ( T_Ts ) E ( i ) = (( %pi /2) * T_Ts ( i ) ) /( sin (( %pi /2) * T_Ts ( i ) ) ) .01:0.1. end a = gca () . a . T_Ts = 0.5) xlabel ( ’ Duty c y c l e T/ Ts ’ ) ylabel ( ’ 1/ s i n c ( 0 .E .6.01:0. data_bounds = [0 . //E = 1 / ( s i n c n e w ( 0 . 1 6 N o r m a l i z e d e q u a l i z a t i o n ( t o c o m p e n s a t e f o r a p e r t u r e e f f e c t ) p l o t t e d v e r s u s T/ Ts ’ ) 29 . 3 : E q u a l i z e r t o Compensate f o r a p e r t u r e effect clc .

3 30 .Figure 4.2: Example4.

1 : A v e r a g e T r a n s m i t t e d Power o f PCM 3 // Page 187 4 clear . 0 0 0 0 1 2 2 Scilab code Exa 5.2 Comaprision of M-ary PCM with ideal system (Channel Capacity Theorem) 31 . M = input ( ’ E n t e r t h e number o f d i s c r e t e a m p l i t u d e l e v e l s f o r NRZ p o l a r ’ ) . disp ( ’ The a v e r a g e t r a n s m i t t e d power i s : ’ ) P = ( k ^2) *( sigma_N ) *(( M ^2) -1) /12. 7 k = input ( ’ E n t e r t h e s e p a r a t i o n c o n s t a n t f o r on− o f f 8 9 10 11 12 13 14 15 16 s i g n a l i n g ’ ).Chapter 5 Waveform Coding Techniques Scilab code Exa 5. disp ( P ) // R e s u l t // E n t e r t h e n o i s e v a r i a n c e 10ˆ −6 // E n t e r t h e s e p a r a t i o n c o n s t a n t f o r on− o f f s i g n a l i n g 7 // E n t e r t h e number o f d i s c r e t e a m p l i t u d e l e v e l s f o r NRZ p o l a r 2 // The a v e r a g e t r a n s m i t t e d power i s : 0 .1 Average Transmitted Power for PCM 1 // C a p t i o n : A v e r a g e T r a n s m i t t e d Power f o r PCM 2 // Example5 . 6 sigma_N = input ( ’ E n t e r t h e n o i s e v a r i a n c e ’ ) . 5 clc .

k =7. // I n p u t s i g n a l −to −n o i s e r a t i o P/ NoB . close . children (1) .5) poly1 = a . Rb_B .5) plot2d ( P_NoB_dB . d e c i b e l s P_NoB = 10^( P_NoB_dB /10) . d e c i b e l s ’ ) ylabel ( ’ Bandwidth e f f i c i e n c y . C_B . 32 . Rb/B . thickness =2. b i t s p e r s e c o n d per hertz ’ ) title ( ’ F i g u r e 5 . poly1 . // f o r M r y PCM s y s t e m .10]. // bandwidth e f f i c i e n c y i n b i t s / s e c /Hz C_B = log2 (1+ P_NoB ) . data_bounds = [ -30 . 3 : S i g n a l −to −Q u a n t i z a t i o n n o i s e r a t i o // Channel Bandwidth B clear . plot2d ( P_NoB_dB . xlabel ( ’ I n p u t s i g n a l −to −n o i s e r a t i o P/NoB .1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 // C a p t i o n : Comparison o f M r y PCM w i t h i d e a l s y s t e m −a ( Channel C a p a c i t y Theorem ) // Example5 . a . ’PCM ’ ]) Scilab code Exa 5. line_style = 4. 2 : Comparison o f M r y PCM s y s t e m −a // Channel C a p a c i t y t h e o r e m clear . // i d e a l s y s t e m a c c o r d i n g t o Shannon ’ s c h a n n e l c a p a c i t y t h e o r e m // p l o t a = gca () . P_NoB_dB = [ -20:30]. 9 Comparison o f M r y PCM w i t h t h e −a i d e a l ssytem ’ ) legend ([ ’ I d e a l System ’ .40 . clc . poly1 . −a Rb_B = log2 (1+(12/ k ^2) * P_NoB ) .0.3 Signal-to-Quantization Noise Ratio of PCM 1 2 3 4 // C a p t i o n : S i g n a l −to −Q u a n t i z a t i o n N o i s e R a t i o o f PCM // Example5 . children (1) .

Figure 5.1: Example5.2 33 .

2.7. 6 n = input ( ’ E n t e r no . ’ Output S i g n a l t o n o i s e r a t i o i n dB : ’ ) 12 // R e s u l t 1 i f n = 8 bits 13 // E n t e r no .5 clc . o f b i t s u s e d t o e n c o d e : 9 20 // E n t e r t h e m e s s a g e s i g n a l b a n w i d t h i n Hz : 4 0 0 0 21 // Channel w i d t h i n Hz : 3 6 0 0 0 . Scilab code Exa 5. o f b i t s u s e d t o e n c o d e : 8 14 // E n t e r t h e m e s s a g e s i g n a l b a n w i d t h i n Hz : 4 0 0 0 15 // Channel w i d t h i n Hz : 32000. ’ Channel w i d t h i n Hz : ’ ) 10 SNRo = 6* n . 22 // Output S i g n a l t o n o i s e r a t i o i n dB : 4 6 .5 Output Signal-to-Noise ratio for Sinusoidal Modulation 1 2 3 4 5 6 // Example 5 : D e l t a M o d u l a t i o n − t o a v o i d s l o p e overload distortion //maximum o u t p u t s i g n a l −to −n o i s e r a t i o f o r s i n u s o i d a l modulation // p a g e 207 clear . 8 23 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 24 // C o n c l u s i o n : c o m p a r i n g r e s u l t 1 w i t h r e s u l t 2 i f 25 number o f b i t s i n c r e a s e d by 1 // c o r r e s p o n d i n g o u t p u t s i g n a l t o n o i s e i n PCM i n c r e a s e d by 6 dB . 16 // Output S i g n a l t o n o i s e r a t i o i n dB : 4 0 . clc . o f b i t s u s e d t o e n c o d e : ’ ) 7 W = input ( ’ E n t e r t h e m e s s a g e s i g n a l b a n w i d t h i n Hz : ’ ) 8 B = n*W. 9 disp (B . 34 . 11 disp ( SNRo . 8 17 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 18 // R e s u l t 2 i f n = 9 b i t s 19 // E n t e r no . a0 = input ( ’ E n t e r t h e a m p l i t u d e o f s i n u s o i d a l s i g n a l : ’ ).

7 f0 = input ( ’ E n t e r t h e f r e q u e n c y o f

sinusoidal signal

i n Hz : ’ ) ;
8 fs = input ( ’ E n t e r t h e s a m p l i n g f r e q u e n c y i n s a m p l e s

per s e c o n d s : ’ );
9 Ts = 1/ fs ; // S a m p l i n g i n t e r v a l 10 delta = 2* %pi * f0 * a0 * Ts ; // S t e p 11 12 13 14 15 16 17 18 19 20 21 22 23

s i z e to avoid s l o p e

overload Pmax = ( a0 ^2) /2; //maximum p e r m i s s i b l e o u t p u t power sigma_Q = ( delta ^2) /3; // Q u a n t i z a t i o n e r r o r o r n o i s e variance W = f0 ; //Maximum m e s s a g e bandwidth N = W * Ts * sigma_Q ; // A v e r a g e o u t p u t n o i s e power SNRo = Pmax / N ; // Maximum o u t p u t s i g n a l −to −n o i s e ratio SNRo_dB = 10* log10 ( SNRo ) ; disp ( SNRo_dB , ’ Maximum o u t p u t s i g n a l −to −n o s i e i n dB f o r Delta Modualtion : ’ ) // R e s u l t 1 f o r f s = 8 0 0 0 H e r t z // E n t e r t h e a m p l i t u d e o f s i n u s o i d a l s i g n a l : 1 // E n t e r t h e f r e q u e n c y o f s i n u s o i d a l s i g n a l i n Hz :4000 // E n t e r t h e s a m p l i n g f r e q u e n c y i n s a m p l e s p e r seconds :8000 //Maximum o u t p u t s i g n a l −to −n o s i e i n dB f o r D e l t a Modualtion : −5.1717849 // //////////////////////////////////////////////////////////////////

// R e s u l t 2 f o r f s = 1 6 0 0 0 H e r t z // E n t e r t h e a m p l i t u d e o f s i n u s o i d a l s i g n a l : 1 // E n t e r t h e f r e q u e n c y o f s i n u s o i d a l s i g n a l i n Hz :4000 27 // E n t e r t h e s a m p l i n g f r e q u e n c y i n s a m p l e s p e r seconds :16000 28 //Maximum o u t p u t s i g n a l −to −n o s i e i n dB f o r D e l t a Modualtion : 3 . 8 5 9 1 1 5 29 // //////////////////////////////////////////////////////////////////
24 25 26

35

// C o n c l u s i o n : c o m p a r i n g r e s u l t 1 w i t h r e s u l t 2 , i f the sampling frequency 31 // i s d o u b l e d t h e s i g n a l t o n o i s e i n c r e a s e d by 9 dB
30

Scilab code CF 5.13a (a) u-Law companding
1 2 3 4 5 6 7 8 9 10 11 12 13 14

15

// C a p t i o n : u−Law companding // F i g u r e 5 . 1 3 ( a ) Mulaw companding N o n l i n e a r Quantization // P l o t t i n g mulaw c h a r a c t e r i s t i c s f o r d i f f e r e n t // V a l u e s o f mu clc ; x = 0:0.01:1; // N o r m a l i z e d i n p u t mu = [0 ,5 ,255]; // d i f f e r e n t v a l u e s o f mu for i = 1: length ( mu ) [ Cx (i ,:) , Xmax ( i ) ] = mulaw (x , mu ( i ) ) ; end plot2d ( x / Xmax (1) , Cx (1 ,:) ,2) plot2d ( x / Xmax (2) , Cx (2 ,:) ,4) plot2d ( x / Xmax (3) , Cx (3 ,:) ,6) xtitle ( ’ C o m p r e s s i o n Law : u−Law companding ’ , ’ N o r m a l i z e d I n p u t | x | ’ , ’ N o r m a l i z e d Output | c ( x ) | ’ ) ; legend ([ ’ u =0 ’ ] ,[ ’ u=5 ’ ] ,[ ’ u=255 ’ ]) Scilab code CF 5.13b (b) A-law companding

1 2 3 4 5 6 7 8

// C a p t i o n : A−law companding // F i g u r e 5 . 1 3 ( b )A−law companding , N o n l i n e a r Quantization // P l o t t i n g A−law c h a r a c t e r i s t i c s f o r d i f f e r e n t // V a l u e s o f A clc ; x = 0:0.01:1; // N o r m a l i z e d i n p u t A = [1 ,2 ,87.56]; // d i f f e r e n t v a l u e s o f A for i = 1: length ( A ) 36

Figure 5.2: Figure5.13a

37

6) 14 xtitle ( ’ C o m p r e s s i o n Law : A−Law companding ’ . Cx (2 . Xmax ( i ) ] = Alaw (x . 10 end 11 plot2d ( x / Xmax (1) .:) . A ( i ) ) . ’ N o r m a l i z e d I n p u t | x | ’ .Figure 5. 5 6 ’ ]) 38 .:) .[ ’A=2 ’ ] .2) 12 plot2d ( x / Xmax (2) .:) .3: Figure5.13b 9 [ Cx (i . ’ N o r m a l i z e d Output | c ( x ) | ’ ) .4) 13 plot2d ( x / Xmax (3) .:) .[ ’A= 8 7 . Cx (1 . Cx (3 . 15 legend ([ ’A =1 ’ ] .

647∗10ˆ −6 // T r a n s m i s s i o n bandwidth f o r r a i s e d c o s i n e s p e c t r u m 39 . 1 : Bandwidth R e q u i r e m e n t s o f t h e T1 Carrier // Page 251 clear . // c o s i n e r o l l − o f f f a c t o r f1 = Bo *(1 . // minimum t r a n s m i s s i o n bandwidth o f T1 system // T r a n s m i s s i o n bandwidth f o r r a i s e d c o s i n e s p e c t r u m ’B ’ alpha = 1.alpha ) . B = 2* Bo . Tb = input ( ’ E n t e r t h e b i t d u r a t i o n o f t h e TDM s i g n a l : ’) Bo = 1/(2* Tb ) .1 Bandwidth Requirements of the T1 carrier 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // C a p t i o n : Bandwidth R e q u i r e m e n t s o f t h e T1 c a r r i e r // Example6 .Chapter 6 Baseband Shaping for Data Transmission Scilab code Exa 6. disp (B .f1 . ’ T r a n s m i s s i o n bandwidth f o r r a i s e d c o s i n e s p e c t r u m i n Hz : ’ ) // R e s u l t // E n t e r t h e b i t d u r a t i o n o f t h e TDM s i g n a l :0. clc .

children (1) . U n i p o l a r NRZ // p a g e 235 clear . children (1) . data_bounds =[0 -2. clc . poly1 = a . for i =1: L if ( x ( i ) ==0) plot ([ i *L . close . thickness =3. children (1) . binary_one ) . x = [0 1 0 0 0 1 0 0 1 1]. poly1 = a . L * L1 2]. binary_one = [1 1 1 1 1 1 1 1 1 1]. L = length ( x ) . L1 = length ( binary_zero ) . 1 Scilab code CF 6. thickness =3. poly1 . else plot ([ i *L . 1 ( a ) : D i s c r e t e PAM S i g n a l s G e n e r a t i o n // [ 1 ] . binary_zero ) .L +1: i * L ] . poly1 .1a (a) Nonreturn-to-zero unipolar format 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 // C a p t i o n : N o n r e t u r n −to −z e r o u n i p o l a r f o r m a t // F i g u r e 6 . children (1) . a . end end xgrid (1) title ( ’ U n i p o l a r NRZ ’ ) Scilab code CF 6.i n Hz : 1 5 4 5 5 9 5 . binary_zero = [0 0 0 0 0 0 0 0 0 0]. total_duration = L * L . // p l o t t i n g a = gca () .L +1: i * L ] .1b (b) Nonreturn-to-zero polar format 1 // C a p t i o n : N o n r e t u r n −to −z e r o p o l a r f o r m a t 40 .

1a 41 .Figure 6.1: Figure6.

L * L1 2].1c (c) Nonreturn-to-zero bipolar format 1 2 3 4 5 6 // C a p t i o n : N o n r e t u r n −to −z e r o b i p o l a r f o r m a t // F i g u r e 6 . children (1) . // p l o t t i n g a = gca () . 42 . P o l a r NRZ // p a g e 235 clear . clc . L = length ( x ) . poly1 = a . close . binary_positive ) . poly1 .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 // F i g u r e 6 . L1 = length ( binary_negative ) . end end xgrid (1) title ( ’ P o l a r NRZ ’ ) Scilab code CF 6. binary_negative ) . close . total_duration = L * L1 . for i =1: L if ( x ( i ) ==0) plot ([ i *L . a . children (1) . else plot ([ i *L . 1 ( b ) : D i s c r e t e PAM S i g n a l s G e n e r a t i o n // [ 2 ] . children (1) . x = [0 1 0 0 0 1 0 0 1 1]. thickness =3. thickness =3. 1 ( c ) : D i s c r e t e PAM S i g n a l s G e n e r a t i o n // [ 3 ] . data_bounds =[0 -2.L +1: i * L ] .L +1: i * L ] . binary_negative = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]. binary_positive = [1 1 1 1 1 1 1 1 1 1]. poly1 . children (1) . poly1 = a . B i P o l a r NRZ // p a g e 235 clear .

Figure 6.1b 43 .2: Figure6.

binary_zero ) . children (1) . children (1) .1 . children (1) . thickness =3. poly1 = a . end end xgrid (1) title ( ’ B i P o l a r NRZ ’ ) Scilab code Exa 6. for i =1: L if ( x ( i ) ==0) plot ([ i *L . // p l o t t i n g a = gca () . poly1 . 2 : P r e c o d e d D u o b i n a r y c o d e r and d e c o d e r 3 // Page 256 4 clc .1 . binary_negative = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]. a . binary_positive = [1 1 1 1 1 1 1 1 1 1]. children (1) . poly1 . L1 = length ( binary_negative ) . data_bounds =[0 -2. x = [0 1 1 0 0 1 0 0 1 1]. binary_positive ) . children (1) .L +1: i * L ] . binary_zero = [0 0 0 0 0 0 0 0 0 0]. // i n p u t b i n a r y s e q u e n c e : p r e c o d e r input 44 .L +1: i * L ] . L * L1 2]. elseif (( x ( i ) ==1) &( x (i -1) ~=1) ) plot ([ i *L . else plot ([ i *L . poly1 . binary_negative ) .2 Duobinary Encoding 1 // C a p t i o n : D u o b i n a r y E n c o d i n g 2 // Example6 . total_duration = L * L1 .0 .0 . poly1 = a . poly1 = a .0]. thickness =3. L = length ( x ) . thickness =3.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 clc .1 . children (1) . 5 b = [0 .L +1: i * L ] .

Figure 6.3: Figure6.1c 45 .

disp (a . for k =2: length ( a ) c ( k ) = a_volts (k -1) + a_volts ( k ) .b ( k ) ) .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 a (1) = xor (1 . end for k =2: length ( b ) a ( k ) = xor ( a (k -1) . end c = c ’. disp ( b_r . b (1) ) . disp (c . ’ D u o b i n a r y c o d e r o u t p u t i n v o l t s : ’ ) // D u o b i n a r y d e c o d e r o u t p u t by a p p l y i n g d e c i s i o n rule for k =1: length ( c ) if ( abs ( c ( k ) ) >1) b_r ( k ) = 0. end end b_r = b_r ’. if ( a ( k ) ==1) a_volts ( k ) =1. else b_r ( k ) = 1. ’ R e c o v e r e d o r i g i n a l s e q u e n c e a t d e t e c t o r oupupt : ’ ) // R e s u l t // P r e c o d e r o u t p u t i n b i n a r y form : // 46 . a_volts = a_volts ’. ’ P r e c o d e r o u t p u t i n v o l t s : ’ ) // D u o b i n a r y c o d e r o u t p u t i n v o l t s c (1) = 1+ a_volts (1) . else a_volts ( k ) = -1. end end a = a ’. ’ P r e c o d e r o u t p u t i n b i n a r y form : ’ ) disp ( a_volts . if ( a (1) ==1) a_volts (1) = 1.

0 . Scilab code Exa 6.0 . 0. // // P r e c o d e r o u t p u t i n v o l t s : // // 1 . y = y ’. 1. for k =2: length ( x ) +1 y ( k ) = xor ( x (k -1) . 0. y_delay = y_delay ’.y_delay ( k ) .0 . − 2.1 . 1.42 43 44 45 46 47 48 49 50 51 52 53 54 // 1 .0 . : 0. 0.1 . 0. d e t e c t o r oupupt : 1.y (k -1) ) . ’ Modulo −2 a d d e r o u t p u t : ’ ) disp ( y_delay . − 1. − 1. 47 . disp (y . 1. // i n p u t b i n a r y s e q u e n c e : precoder input y (1) = 1. x = [0 .1 .1 . 3 : O p e r a t i o n o f C i r c u i t i n f i g u r e 6 . 1 3 // f o r g e n e r a t i n g b i p o l a r f o r m a t // p a g e 256 and p a g e 257 // R e f e r T a b l e 6 . 0. 2. 1. − // // D u o b i n a r y c o d e r o u t p u t i n v o l t s // // 2 . − 1. 0.3 Generation of bipolar output for duobinary coder 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // C a p t i o n : G e n e r a t i o n o f b i p o l a r o u t p u t f o r d u o b i n a r y coder // Example6 . end y_delay = y (1: $ -1) . // // R e c o v e r e d o r i g i n a l s e q u e n c e a t // // 0 . 1. 1. 1. − 2. end z = z ’. 0. 4 clc . 0. ’ D e l a y e l e m e n t o u t p u t : ’ ) for k = 1: length ( y_delay ) z ( k ) = y ( k +1) . 0.1].

0. 0. 0. : 0. clc . for i = 1: length ( f ) Sxxf_NRZ_P ( i ) = ( a ^2) * Tb *( sinc_new ( f ( i ) * Tb ) ^2) . 4 : Power S p e c t a l D e n s i t i e s o f // D i f f e r e n t L i n e Coding T e c h n i q u e s // [ 1 ] . else 48 . // [ 1 ] . 0.4 Power Spectra of different binary data formats 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n : Power S p e c t r a o f d i f f e r e n t b i n a r y d a t a formats // F i g u r e 6 . volts 0. Tb = 1/ fb . 1. 1. 1. Scilab code CF 6. M a n c h e s t e r f o r m a t // Page 241 close . − 1. 0. 0. NRZ U n i p o l a r f o r m a t [ 4 ] . ’ d i f f e r e n t i a l e n c o d e r b i p o l a r o u t p u t i n : ’) // R e s u l t // Modulo −2 a d d e r o u t p u t : // 1. 0. // b i t d u r a t i o n f = 0:1/(100* Tb ) :2/ Tb . 0. 1. 1. NRZ P o l a r f o r m a t a = input ( ’ E n t e r t h e A m p l i t u d e v a l u e : ’ ) . 0. if ( i ==1) Sxxf_NRZ_UP ( i ) = ( a ^2) *( Tb /4) *(( sinc_new ( f ( i ) * Tb ) ) ^2) +( a ^2) /4. 0. // d i f f e r e n t i a l e n c o d e r b i p o l a r o u t p u t i n v o l t s // 0. 0. 1. NRZ B i p o l a r f o r m a t // [ 3 ] . 1. 0. 1. − 1.21 22 23 24 25 26 27 28 disp (z . 1. − 1. fb = input ( ’ E n t e r t h e b i t r a t e : ’ ) . NRZ P o l a r Format [ 2 ] . 0. 1. Sxxf_NRZ_BP ( i ) = ( a ^2) * Tb *(( sinc_new ( f ( i ) * Tb ) ) ^2) *(( sin ( %pi * f ( i ) * Tb ) ) ^2) . // D e l a y e l e m e n t o u t p u t : // 1.

// t h e t i c k n e s s o f a c u r v e . ’ M a n c h e s t e r f o r m a t ’ ]) . Sxxf_NRZ_UP . thickness = 2. 6 ( b ) : I d e a l S o l u t i o n f o r I n t e r s y m b o l Interference 3 // SINC p u l s e 1 2 49 . Sxxf_NRZ_BP . children (1) . Sxxf_NRZ_P ) poly1 = a . children (1) . Sxxf_Manch . // t h e t i c k n e s s o f a c u r v e . plot2d (f . poly1 . children (1) . poly1 . children (1) . // t h e t i c k n e s s o f a c u r v e . children (1) . thickness = 2.9) poly1 = a . end // P l o t t i n g a = gca () . // R e s u l t // E n t e r t h e A m p l i t u d e v a l u e : 1 // E n t e r t h e b i t r a t e : 1 Scilab code CF 6. poly1 . children (1) . plot2d (f .6b (b) Ideal solution for zero ISI // C a p t i o n : I d e a l s o l u t i o n f o r z e r o I S I // F i g u r e 6 . ’NRZ B i p o l a r f o r m a t ’ . end Sxxf_Manch ( i ) = ( a ^2) * Tb *( sinc_new ( f ( i ) * Tb /2) ^2) *( sin ( %pi * f ( i ) * Tb /2) ^2) . children (1) . children (1) . plot2d (f .5) poly1 = a . poly1 . // t h e t i c k n e s s o f a c u r v e .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 Sxxf_NRZ_UP ( i ) = ( a ^2) *( Tb /4) *(( sinc_new ( f ( i ) * Tb ) ) ^2) . thickness = 2. xlabel ( ’ f ∗Tb−−−−−−−> ’ ) ylabel ( ’ Sxx ( f )−−−−−−−> ’ ) title ( ’ Power S p e c t r a l D e n s i t i e s o f D i f f e r e n t L i n e Codinig Techniques ’ ) xgrid (1) legend ([ ’NRZ P o l a r Format ’ . ’NRZ U n i p o l a r f o r m a t ’ .2) poly1 = a . plot2d (f . thickness = 2.

Figure 6.4: Figure6.4 50 .

rb = input ( ’ E n t e r t h e b i t r a t e : ’ ) . plot (t .4 5 6 7 8 9 10 11 12 13 14 15 // p a g e 249 rb = input ( ’ E n t e r t h e b i t r a t e : ’ ) . t = -3:1/100:3. ylabel ( ’ p ( t )−−−−−−−> ’ ) .7b (b) Practical solution: Raised Cosine 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // C a p t i o n : P r a c t i c a l s o l u t i o n : R a i s e d C o s i n e // F i g u r e 6 . den = 1 -16*( Alpha ^2) *( Bo ^2) *( t ( i ) ^2) +0. i ) = sinc_new (2* Bo * t ( i ) ) . p (j .5) ) ) p (j . Alpha =0. else num = sinc_new (2* Bo * t ( i ) ) * cos (2* %pi * Alpha * Bo * t ( i ) ) . x = sinc_new (2* Bo * t ) . 7 ( b ) : P r a c t i c a l S o l u t i o n f o r I n t e r s y m b o l Interference // R a i s e d C o s i n e Spectrum // p a g e 250 close . for j =1:3 for i =1: length ( t ) if (( j ==3) &(( t ( i ) ==0.01. Bo = rb /2. title ( ’ SINC P u l s e f o r z e r o I S I ’ ) xgrid (1) // R e s u l t // E n t e r t h e b i t r a t e : 1 Scilab code CF 6. i ) = num / den . // I n t i a l i z e d t o z e r o x = t / Tb . 51 . Bo = rb /2. t = -3:1/100:3. Tb =1/ rb . x ) xlabel ( ’ t−−−−−−> ’ ) . clc .5) |( t ( i ) == -0.

6 52 .5: Figure6.Figure 6.

// B i t d u r a t i o n 53 .5 ’ . close . children (1) .21 end 22 end 23 Alpha = Alpha +0. rb = input ( ’ E n t e r t h e b i t r a t e= ’ ) . 26 plot2d (t . 35 ylabel ( ’ p ( t )−−−−−−−> ’ ) . clc . foreground =2. 34 xlabel ( ’ t /Tb−−−−−−> ’ ) . 30 plot2d (t . 32 po1y2 .:) ) 28 poly1 = a .:) ) 27 plot2d (t .:) ) 31 poly2 = a . 33 poly2 . ’ R O l l o f f F a c t o r =0. 29 poly1 . p (3 . 36 title ( ’ RAISED COSINE SPECTRUM − P r a c t i c a l 37 Solution for ISI ’) legend ([ ’ R O l l o f f F a c t o r =0 ’ . Tb =1/ rb . 24 end 25 a = gca () . children (1) .9 Frequency response of duobinary conversion filter 1 2 3 4 5 6 7 8 9 10 // C a p t i o n : F r e q u e n c y r e s p o n s e o f d u o b i n a r y c o n v e r s i o n filter // F i g u r e 6 . children (1) . 9 : F r e q u e n c y R e s p o n s e o f D u o b i n a r y Conversion f i l t e r // ( a ) A m p l i t u d e R e s p o n s e // ( b ) Phase R e s p o n s e // Page 254 clear . p (2 . foreground =4. p (1 . children (1) . line_style = 3. ’ R O l l o f f F a c t o r =1 ’ ]) 38 xgrid (1) 39 // R e s u l t 40 // E n t e r t h e b i t r a t e : 1 Scilab code CF 6.5.

7 54 .6: Figure6.Figure 6.

Phase_Response . xlabel ( ’ F r e q u e n c y f −−−−> ’ ) ylabel ( ’ <H( f ) −−−−−> ’ ) title ( ’ Phase R e p s o n s e o f D u o b i n a r y S i n g a l i n g ’ ) // R e s u l t // E n t e r t h e b i t r a t e =8 Scilab code CF 6. 1 5 : F r e q u e n c y R e s p o n s e o f M o d i f i e d duobinary conversion f i l t e r 3 // ( a ) A m p l i t u d e R e s p o n s e 4 // ( b ) Phase R e s p o n s e 1 55 .* Tb ) . plot2d (f .2) poly1 = a . xlabel ( ’ F r e q u e n c y f −−−−> ’ ) ylabel ( ’ | H( f ) | −−−−−> ’ ) title ( ’ A m p l i t u d e R e p s o n s e o f D u o b i n a r y S i n g a l i n g ’ ) subplot (2 . poly1 . children (1) . a . // t h e t i c k n e s s o f a c u r v e .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 f = . Amplitude_Response = abs (2* cos ( %pi * f . children (1) . a . x_location = ” o r i g i n ” . thickness = 2. children (1) .15 Frequency response of modified duobinary conversion filter // C a p t i o n : F r e q u e n c y r e s p o n s e o f m o d i f i e d d u o b i n a r y conversion f i l t e r 2 // F i g u r e 6 . x_location = ” o r i g i n ” .* Tb ) ) . Phase_Response = -( %pi * f . plot2d (f .1 . thickness = 2. // t h e t i c k n e s s o f a c u r v e . a .5) poly1 = a . subplot (2 . Amplitude_Response .2) a = gca () . y_location = ” o r i g i n ” . a . y_location = ” o r i g i n ” .1 . poly1 .rb /2:1/100: rb /2. children (1) .1) a = gca () .

7: Figure6.Figure 6.9 56 .

Tb =1/ rb .rb /2:1/100: rb /2. children (1) . x_location = ” o r i g i n ” . Amplitude_Response .1) a = gca () . plot2d (f .* Tb ) ) . thickness = 2.1 . a . x_location = ” o r i g i n ” .5) poly1 = a . y_location = ” o r i g i n ” . Phase_Response = -(2* %pi * f .2) a = gca () . Amplitude_Response = abs (2* sin (2* %pi * f . children (1) . a . a . xlabel ( ’ F r e q u e n c y f −−−−> ’ ) ylabel ( ’ <H( f ) −−−−−> ’ ) title ( ’ Phase R e p s o n s e o f M o d i f i e d D u o b i n a r y Singaling ’) xgrid (1) // R e s u l t // E n t e r t h e b i t r a t e =8 57 .2) poly1 = a .* Tb ) .1 . // B i t d u r a t i o n f = . clc . poly1 . children (1) . children (1) . poly1 . // t h e t i c k n e s s o f a c u r v e . rb = input ( ’ E n t e r t h e b i t r a t e= ’ ) .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 // p a g e 259 clear . close . subplot (2 . y_location = ” o r i g i n ” . thickness = 2. Phase_Response . plot2d (f . xlabel ( ’ F r e q u e n c y f −−−−> ’ ) ylabel ( ’ | H( f ) | −−−−−> ’ ) title ( ’ A m p l i t u d e R e p s o n s e o f M o d i f i e d D u o b i n a r y Singaling ’) xgrid (1) subplot (2 . a . // t h e t i c k n e s s o f a c u r v e .

Figure 6.15 58 .8: Figure6.

sin (2* %pi *2* t ) * sin ((2* i -1) * %pi /4) .1 QPSK Waveform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // C a p t i o n : Waveforms o f D i f f e r e n t D i g i t a l M o d u l a t i o n techniques // Example7 .0]. end S1 =[].2]. clc . for i =1: length ( m ) S1 = [ S1 s1 ( m ( i ) . Input_Sequence =[0 .Chapter 7 Digital Modulation Techniques Scilab code Exa 7.:) = . t = 0:0.1 .1 . S2 = [].1 . m = [3 . s2 (i . M =4. 1 S i g n a l S p a c e Diagram f o r c o h e r e n t QPSK system clear .1 .:) = cos (2* %pi *2* t ) * cos ((2* i -1) * %pi /4) . close .1 .0 .:) ]. end 59 .001:1.0 . S2 = [ S2 s2 ( m ( i ) .:) ]. S = []. i = 1: M . for i = 1: M s1 (i .0 .

x_location = ” o r i g i n ” . x_location = ” o r i g i n ” . 26 a . 1 .22 S = S1 + S2 . // a . x_location = ” o r i g i n ” . plot ( S2 ) title ( ’ B i n a r y PSK wave o f Even−numbered b i t s o f input sequence ’) subplot (3 . − 1 . x l o c a t i o n = ” o r i g i n ” .1 .1 . d a t a b o u n d s = [ − 1 .1 . ’ c o o r d i n a t e s o f m e s s a g e p o i n t s ’ ) // d i s p ( annot .2) a = gca () . imag ( y ( 4 ) ) .1) 25 a = gca () . a . y l o c a t i o n = ” o r i g i n ” . // a . −5) // p l o t 2 d ( r e a l ( y ( 4 ) ) . imag ( y ( 1 ) ) . // y l a b e l ( ’ Quadrature ’ ) . imag ( y ( 2 ) ) .3) a = gca () . // a n n o t = d e c 2 b i n ( [ 0 : l e n g t h ( y ) −1] . imag ( y ( 3 ) ) . plot ( S ) title ( ’QPSK waveform ’ ) //− s i n ( ( 2 ∗ i −1) ∗ %pi / 4 ) ∗ %i . 27 plot ( S1 ) 28 title ( ’ B i n a r y PSK wave o f Odd−numbered b i t s 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 of input sequence ’) subplot (3 . ’ d i b i t s v a l u e ’ ) // f i g u r e . // a . // d i s p ( y . 1 ] . 23 figure 24 subplot (3 . a . −2) // p l o t 2 d ( r e a l ( y ( 2 ) ) . // a =g c a ( ) . −4) // p l o t 2 d ( r e a l ( y ( 3 ) ) . // p l o t 2 d ( r e a l ( y ( 1 ) ) . 60 . l o g 2 (M) ) . −9) // x l a b e l ( ’ In− Phase ’ ) .

’ message p o in t 4 ( d i b i t 11) ’ ] . ’ message p o i nt 3 ( d i b i t 01) ’ . ’ m e s s a g e p o i nt 2 ( d i b i t 00) ’ .Figure 7.1 Waveform of Different Digital Modulation techniques // C a p t i o n : Waveforms o f D i f f e r e n t D i g i t a l M o d u l a t i o n techniques 2 // F i g u r e 7 . 5 ) Scilab code CF 7. FSK and PSk Waveforms 1 61 . 1 3 // D i g i t a l M o d u l a t i o n T e c h n i q u e s 4 //To P l o t t h e ASK.1: Example7.1 54 55 // t i t l e ( ’ C o n s t e l l a t i o n f o r QPSK ’ ) // l e g e n d ( [ ’ m e s s a g e p o i n t 1 ( d i b i t 1 0 ) ’ .

x2 = . 8 f = input ( ’ E n t e r t h e Analog C a r r i e r F r e q u e n c y i n Hz ’ 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 ). Xask ]. // G e n e r a t i o n o f ASK Waveform Xask = []. I = input ( ’ E n t e r t h e d i g i t a l b i n a r y d a t a ’ ) . x1 = sin (2* %pi * f * t ) . Xask ]. x2 = sin (2* %pi *(2* f ) * t ) . elseif (( I ( n ) ==1) &( n ~=1) ) Xask = [ Xask . 6 clc .sin (2* %pi * f * t ) . for n = 1: length ( I ) if ( I ( n ) ==1) 62 . 7 close . length ( x ) ) . x ]. length ( x ) ) ]. for n = 1: length ( I ) if (( I ( n ) ==1) &( n ==1) ) Xask = [x . elseif ( I ( n ) ~=1) Xfsk = [ Xfsk . t = 0:1/512:1.5 clear . end end // G e n e r a t i o n o f FSK Waveform Xfsk = []. x = sin (2* %pi * f * t ) . end end // G e n e r a t i o n o f PSK Waveform Xpsk = []. for n = 1: length ( I ) if ( I ( n ) ==1) Xfsk = [ Xfsk . x1 ]. x2 ]. elseif (( I ( n ) ==0) &( n ==1) ) Xask = [ zeros (1 . x1 = sin (2* %pi * f * t ) . zeros (1 . elseif (( I ( n ) ==0) &( n ~=1) ) Xask = [ Xask .

1 . 1 . 0 . 1 ] Scilab code Exa 7.Tb :0. 1 . x1 ].42 Xpsk = [ Xpsk . M =2. t1 = . 63 . Tb =1.01: Tb . 43 elseif ( I ( n ) ~=1) 44 Xpsk = [ Xpsk . x2 ]. 0 . 45 end 46 end 47 figure 48 plot (t . 0 . 2 : S e q u e n c e and Waveforms f o r MSK s i g n a l // T a b l e 7 . 2 s i g n a l s p a c e c h a r a c t e r i z a t i o n o f MSK clear clc .2 MSK waveforms 1 2 3 4 5 6 7 8 9 // C a p t i o n : S i g n a l S p a c e d i a g r a m f o r c o h e r e n t BPSK // Example7 . close . x ) 49 xtitle ( ’ Analog C a r r i e r S i g n a l 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 f o r D i g i t a l Modulation ’) xgrid figure plot ( Xask ) xtitle ( ’ A m p l i t u d e S h i f t Keying ’ ) xgrid figure plot ( Xfsk ) xtitle ( ’ F r e q u e n c y S h i f t Keying ’ ) xgrid figure plot ( Xpsk ) xtitle ( ’ Phase S h i f t Keying ’ ) xgrid // Example // E n t e r t h e Analog C a r r i e r F r e q u e n c y 2 // E n t e r t h e d i g i t a l b i n a r y d a t a [ 0 .

2: Figure7.1a 64 .Figure 7.

1b 65 .3: Figure7.Figure 7.

Figure 7.4: Figure7.1c 66 .

sin ( . disp (y . S = [ S cos (0) * cos (2* %pi * t ) . S = [ S cos (0) * cos (2* %pi * t ) . s2 ( i ) = . s1 (2) .sin ( .0]. S2 = [].%pi /2]. S = [ S cos (0) * cos (2* %pi * t ) . t = 0:0. . phi2 = sin (2* %pi * t2 ) .%pi /2) * sin (2* %pi * t ) ].0 . s2 (1) . for i = 1: M s1 ( i ) = cos ( teta_0 ( i ) ) . end for i = M : -1:1 S1 = [ S1 s1 ( i ) * phi1 ].%pi /2) * sin (2* %pi * t ) ]. s1 (2) . S = [].%pi /2) * sin (2* %pi * t ) ]. S2 = [ S2 s2 (2) * phi2 ].1 .sin ( .sin ( . 67 . S = [ S cos (0) * cos (2* %pi * t ) . S = [ S cos ( %pi ) * cos (2* %pi * t ) .%pi /2) * sin (2* %pi * t ) ]. S = [ S cos (0) * cos (2* %pi * t ) .1 .sin ( %pi /2) * sin (2* %pi * t ) ]. %pi ].sin ( %pi /2) * sin (2* %pi * t ) ]. s1 (1) .01:2* Tb .1 .0 . S2 = [ S2 s2 (1) * phi2 ]. s2 (2) .* cos (( %pi /(2* Tb ) ) * t1 ) . phi1 = cos (2* %pi * t1 ) . teta_tb = [ %pi /2 .sin ( teta_tb ( i ) ) . S1 = [ S1 s1 ( i ) * phi1 ].01:1. s2 (2) ].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 t2 = 0:0. S1 = []. y = [ s1 (1) .1) a = gca () . end Input_Sequence =[1 .* sin (( %pi /(2* Tb ) ) * t2 ) .sin ( %pi /2) * sin (2* %pi * t ) ]. teta_0 = [0 . S = [ S cos ( %pi ) * cos (2* %pi * t ) . ’ c o o r d i n a t e s o f m e s s a g e p o i n t s ’ ) figure subplot (3 .0 . s2 (1) .

imag ( y (1) ) . a .2]. ’ c o o r d i n a t e s o f m e s s a g e p o i n t s ’ ) disp ( annot . x_location = ” o r i g i n ” . plot ( S ) title ( ’ O b t a i n e d by a d d i n g s 1 ∗ p h i 1 ( t )+s 2 ∗ p h i 2 ( t ) on a b i t −by−b i t b a s i s ’ ) Scilab code CF 7. x_location = ” o r i g i n ” . a . close .42 43 44 45 46 47 48 49 50 51 52 53 54 a . data_bounds = [ -2 . M =2.2 . a .2 Signal Space diagram for coherent BPSK 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n : S i g n a l S p a c e d i a g r a m f o r c o h e r e n t BPSK // F i g u r e 7 . -5) xlabel ( ’ 68 . ’ Mes sa ge p o i n t s ’ ) figure . log2 ( M ) ) . a = gca () . y = cos (2* %pi +( i -1) * %pi ) .1 . disp (y . plot2d ( real ( y (1) ) .2) a = gca () . plot ( S2 ) title ( ’ S c a l e d t i m e f u n c t i o n s 2 ∗ p h i 2 ( t ) ’ ) subplot (3 . -9) plot2d ( real ( y (2) ) . imag ( y (2) ) .1 . y_location = ” o r i g i n ” . x_location = ” o r i g i n ” . a . x_location = ” o r i g i n ” .3) a = gca () . annot = dec2bin ([ length ( y ) -1: -1:0] . a . -2. 2 S i g n a l S p a c e Diagram f o r c o h e r e n t BPSK system clear clc . i = 1: M . plot ( S1 ) title ( ’ S c a l e d t i m e f u n c t i o n s 1 ∗ p h i 1 ( t ) ’ ) subplot (3 .

5: Example7.2 69 .Figure 7.

Figure 7.2 In−Phase ’ ) .6: Figure7. title ( ’ C o n s t e l l a t i o n f o r BPSK ’ ) legend ([ ’ m e s s a g e p o i n t 1 ( b i n a r y 1 ) ’ .3 Illustration the generation of DPSK signal 1 21 22 // C a p t i o n : I l l u s t r a t i n g t h e g e n e r a t i o n o f DPSK s i g n a l 70 . 20 ylabel ( ’ Quadrature ’ ).5) Scilab code Tab 7. ’ m e s s a g e p o i n t 2 ( b i n a r y 0 ) ’ ] .

end end disp ( ’ T a b l e 7 .0 .1 . bk = [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 // T a b l e 7 . elseif ( dk ( i ) ==0) dk_radians ( i ) = %pi . end for i =1: length ( dk ) if ( dk ( i ) ==1) dk_radians ( i ) =0. 3 G e n e r a t i o n o f D i f f e r e n t i a l Phase s h i f t keying s i g n a l clc . 3 I l l u s t r a t i n g t h e G e n e r a t i o n o f DPSK Signal ’) disp ( ’ ’) disp ( bk . // i n i t i a l v a l u e o f d i f f e r e n t i a l encoded sequence dk_1_not (1) =0& bk_not (1) .0 . // i n p u t d i g i t a l s e q u e n c e for i = 1: length ( bk ) if ( bk ( i ) ==1) bk_not ( i ) =~1. 71 29 30 31 32 . dk (1) = xor ( dk_1 (1) . ’ ( bk ) ’ ) bk_not = bk_not ’.1 .1]. end end dk_1 (1) = 1& bk (1) . disp ( bk_not .0 . ’ ( b k n o t ) ’ ) dk = dk ’. else bk_not ( i ) = 1.( dk_1_not ( i ) & bk_not ( i ) )).0 . dk_1_not ( i ) = ~ dk (i -1) . dk_1_not (1) ) // f i r s t b i t o f dpsk encoder for i =2: length ( bk ) dk_1 ( i ) = dk (i -1) . dk ( i ) = xor (( dk_1 ( i ) & bk ( i ) ) .

2) .1) . x_location = ” o r i g i n ” .y (1 .1]. ’ m e s s a g e p o i n t 2 ( b i n a r y 0 ) ’ ] .y (2 . y_location = ” o r i g i n ” . 4 S i g n a l S p a c e Diagram f o r c o h e r e n t BFSK system clear clc . a . ’ D i f f e r e n t i a l l y e n c o d e d s e q u e n c e ( dk ) ’ ) dk_radians = dk_radians ’.5) 72 . close . disp ( dk_radians .0.2 .2].1) . ’ c o o r d i n a t e s o f m e s s a g e p o i n t s ’ ) disp ( annot . -9) plot2d ( y (2 . plot2d ( y (1 . a = gca () . -5) xlabel ( ’ In−Phase ’ ) . ’ Mes sa ge p o i n t s ’ ) figure . ’ T r a n s m i t t e d p h a s e i n r a d i a n s ’ ) disp ( ’ ’) Scilab code CF 7.4 Signal Space diagram for coherent BFSK 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // C a p t i o n : S i g n a l S p a c e d i a g r a m f o r c o h e r e n t BFSK // F i g u r e 7 . 20 title ( ’ C o n s t e l l a t i o n f o r BFSK ’ ) 21 legend ([ ’ m e s s a g e p o i n t 1 ( b i n a r y 1 ) ’ . M =2. annot = dec2bin ([ M -1: -1:0] . log2 ( M ) ) . data_bounds = [ -2 . a . y = [1 . -2.0 .2) . a .33 34 35 36 disp ( dk . 19 ylabel ( ’ Quadrature ’ ). disp (y .

Figure 7.4 73 .7: Figure 7.

plot2d ( real ( y (1) ) . a = gca () . data_bounds = [ -1 . ’ m e s s a g e p o i n t 4 ( d i b i t 1 1 ) ’ ] .6 Signal space diagram for coherent QPSK waveform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // C a p t i o n : S i g n a l s p a c e d i a g r a m f o r c o h e r e n t QPSK waveform // F i g u r e 7 .sin ((2* i -1) * %pi /4) * %i . -9) xlabel ( ’ In− Phase ’ ) . disp (y . -2) plot2d ( real ( y (2) ) . y = cos ((2* i -1) * %pi /4) .1].1 . -4) plot2d ( real ( y (3) ) . a . ’ m e s s a g e p o i n t 2 ( d i b i t 00) ’ . imag ( y (3) ) . y_location = ” o r i g i n ” . 6 S i g n a l S p a c e Diagram f o r c o h e r e n t QPSK system clear clc . M =4. imag ( y (4) ) . annot = dec2bin ([0: M -1] . i = 1: M . a . imag ( y (2) ) . ’ message p o i nt 3 ( d i b i t 01) ’ . -5) plot2d ( real ( y (4) ) .5) Scilab code Tab 7. title ( ’ C o n s t e l l a t i o n f o r QPSK ’ ) legend ([ ’ m e s s a g e p o i n t 1 ( d i b i t 1 0 ) ’ . ’ c o o r d i n a t e s o f m e s s a g e p o i n t s ’ ) disp ( annot . ’ d i b i t s v a l u e ’ ) figure .6 Bndwidth efficiency of M ary PSK signals 23 24 74 . -1. x_location = ” o r i g i n ” .Scilab code CF 7. close . a . ylabel ( ’ Quadrature ’ ). log2 ( M ) ) . imag ( y (1) ) .

Figure 7.8: Figure7.6 75 .

// Ruo = Ruo ’ .8 . M = [2 ./ M .7 Bandwidth efficiency of M ary FSK signals 1 // C a p t i o n : Bandwidth e f f i c i e n c y o f M r y FSK s i g n a l s −a 2 // T a b l e 7 . 5 close .16 . // Bandwidth e f f i c i e n c y i n b i t s / s / Hz disp ( ’ T a b l e 7 . //M r y −a Ruo = log2 ( M ) .32 . ’ r i n b i t s / s /Hz ’ ) 13 disp ( ’ ’) Scilab code Tab 7.4 . clc . disp ( ’ T a b l e 7 . 7 : Bandwidth E f f i c i e n c y o f M r y FSK −a 3 clear .1 2 3 4 5 6 7 8 9 // C a p t i o n : Bandwidth e f f i c i e n c y o f M r y PSK s i g n a l s −a // T a b l e 7 .64]. //M r y −a 7 Ruo = 2* log2 ( M ) ./2.64]. close .8 . ’M’ ) disp ( ’ 10 11 ’) 12 disp ( Ruo . // Bandwidth e f f i c i e n c y i n b i t s / s /Hz //M = M’ . 7 Bandwidth E f f i c i e n c y o f M r y FSK −a signals ’) 11 disp ( ’ 8 9 10 76 .16 .4 . 6 M = [2 . 6 : Bandwidth E f f i c i e n c y o f M r y PSK −a signals clear . 4 clc . 7 Bandwidth E f f i c i e n c y o f M r y PSK −a signals ’) disp ( ’ ’) disp (M .32 .

12 ’) 12 disp (M . ’M’ ) 13 disp ( ’ ’) 14 disp ( Ruo .9: Figure7. ’ r i n b i t s / s /Hz ’ ) 15 disp ( ’ ’) Scilab code CF 7.Figure 7.29 Power Spectra of BPSK and BFSK signals 77 .

plot ( f * Tb . xlabel ( ’ N o r m a l i z e d F r e q u e n c y −−−−> ’ ) ylabel ( ’ N o r m a l i z e d Power S p e c t r a l D e n s i t y −−−> ’ ) title ( ’PSK Vs FSK Power S p e c t r a Comparison ’ ) legend ([ ’ F r e q u e n c y S h i f t Keying ’ . SB_PSK /(2* Eb ) ) poly1 = a .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 // C a p t i o n : Power S p e c t r a o f BPSK and BFSK s i g n a l s // F i g u r e 7 . rb = input ( ’ E n t e r t h e b i t r a t e= ’ ) . poly1 . foreground = 6. Eb = input ( ’ E n t e r t h e e n e r g y o f t h e b i t= ’ ) . end SB_PSK ( i ) =2* Eb *( sinc_new ( f ( i ) * Tb ) ^2) . end a = gca () . children (1) . Tb = 1/ rb . else SB_FSK ( i ) = (8* Eb *( cos ( %pi * f ( i ) * Tb ) ^2) ) /(( %pi ^2) *(((4*( Tb ^2) *( f ( i ) ^2) ) -1) ^2) ) . // B i t d u r a t i o n for i = 1: length ( f ) if ( f ( i ) ==(1/(2* Tb ) ) ) SB_FSK ( i ) = Eb /(2* Tb ) . 2 9 : Comparison o f Power S p e c t r a l D e n s i t i e s o f BPSK // and BFSK clc . f = 0:1/100:8/ rb .30 Power Spectra of QPSK and MSK signals. 3 0 : Comparison o f QPSK and MSK Power 78 . SB_FSK /(2* Eb ) ) plot ( f * Tb . ’ Phase S h i f t Keying ’ ]) xgrid (1) // R e s u l t // E n t e r t h e b i t r a t e i n b i t s p e r s e c o n d : 2 // E n t e r t h e Energy o f b i t : 1 Scilab code CF 7. children (1) . 1 2 // C a p t i o n : Power S p e c t r a o f QPSK and MSK s i g n a l s // F i g u r e 7 .

10: Figure7.Figure 7.29 79 .

plot ( f * Tb . // b i t d u r a t i o n i n s e c o n d s for i = 1: length ( f ) if ( f ( i ) ==0. 3 1 Comparison o f Power S p e c t r a l D e n s i t i e s o f M r y PSK s i g n a l s −a 80 . // c l o s e . Tb = 1/ rb . poly1 = a .31 Power spectra of M-ary PSK signals 1 2 // C a p t i o n : Power s p e c t r a o f M r y PSK s i g n a l s −a // F i g u r e 7 . Eb = input ( ’ E n t e r t h e Energy o f b i t : ’ ) . poly1 .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 Spectrums // c l e a r . // c l c . xlabel ( ’ N o r m a l i z e d F r e q u e n c y −−−−> ’ ) ylabel ( ’ N o r m a l i z e d Power S p e c t r a l D e n s i t y −−−> ’ ) title ( ’QPSK Vs MSK Power S p e c t r a Comparison ’ ) legend ([ ’ Minimum S h i f t Keying ’ . else SB_MSK ( i ) = (32* Eb /( %pi ^2) ) *( cos (2* %pi * Tb * f ( i ) ) /((4* Tb * f ( i ) ) ^2 -1) ) ^2. foreground = 3. SB_MSK /(4* Eb ) ) .5) SB_MSK ( i ) = 4* Eb * f ( i ) . plot ( f * Tb . rb = input ( ’ E n t e r t h e b i t r a t e i n b i t s p e r s e c o n d : ’ ) . children (1) . end a = gca () . children (1) . SB_QPSK /(4* Eb ) ) . f = 0:1/(100* rb ) :(4/ rb ) . end SB_QPSK ( i ) = 4* Eb * sinc_new ((2* Tb * f ( i ) ) ) ^2. ’QPSK ’ ]) xgrid (1) // R e s u l t // E n t e r t h e b i t r a t e i n b i t s p e r s e c o n d : 2 // E n t e r t h e Energy o f b i t : 1 Scilab code CF 7.

11: Figure7.Figure 7.30 81 .

for j = 1: length ( M ) for i = 1: length ( f ) SB_PSK (j .:) /(2* Eb ) ) plot2d ( f * Tb . ’M=4 ’ . i ) =2* Eb *( sinc_new ( f ( i ) * Tb * log2 ( M ( j ) ) ) ^2) * log2 ( M ( j ) ) . 8 ’ ) −a legend ([ ’M=2 ’ .:) /(2* Eb ) . clc . end end a = gca () . // B i t d u r a t i o n M = [2 . plot2d ( f * Tb . 4 . g ) ) . 4 1 // Matched F i l t e r Output clear . h = abs ( convol (g . t = 0: T . T =4. ’M=8 ’ ]) xgrid (1) // R e s u l t // E n t e r t h e b i t r a t e i n b i t s p e r s e c o n d : 2 // E n t e r t h e Energy o f b i t : 1 Scilab code CF 7.8].2) plot2d ( f * Tb . a =2. T +1) .41 Matched Filter output of rectangular pulse 1 2 3 4 5 6 7 8 9 10 11 // C a p t i o n : Matched F i l t e r o u t p u t o f r e c t a n g u l a r p u l s e // F i g u r e 7 .3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 rb = input ( ’ E n t e r t h e b i t r a t e= ’ ) . Tb = 1/ rb . Eb = input ( ’ E n t e r t h e e n e r g y o f t h e b i t= ’ ) . for i = 1: length ( h ) 82 . f = 0:1/100: rb . g = 2* ones (1 . SB_PSK (2 .4 . SB_PSK (3 .:) /(2* Eb ) . SB_PSK (1 .5) xlabel ( ’ N o r m a l i z e d F r e q u e n c y −−−−> ’ ) ylabel ( ’ N o r m a l i z e d Power S p e c t r a l D e n s i t y −−−> ’ ) title ( ’ Power S p e c t r a o f M r y s i g n a l s f o r M = 2 .

Figure 7.12: Figure7.31 83 .

6 . figure a = gca () . data_bounds = [0 .5) xlabel ( ’ t−−−> ’ ) ylabel ( ’ g ( t )−−−−> ’ ) title ( ’ R e c t a n g u l a r p u l s e d u r a t i o n T = 4 .4]. t1 = 0: length ( h ) -1.g . a . end end h = h-T.12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 if ( h ( i ) <0.01) h ( i ) =0. plot2d (t . a =2 ’ ) figure plot2d ( t1 .h .0.6) xlabel ( ’ t−−−> ’ ) ylabel ( ’ Matched F i l t e r o u t p u t ’ ) title ( ’ Output o f f i l t e r matched t o r e c t a n g u l a r p u l s e g( t ) ’) 84 .

13: Figure7.41a 85 .Figure 7.

14: Figure7.Figure 7.41b 86 .

* G . 4 clc .n . // one b i t m = 1.k ) . Scilab code Exa 8. 1 : R e p e t i t i o n Codes clear . // g e n e r a t o r m a t r i x x = m . disp (x .n . // c o e f f i c i e n t m a t r i x H = [ I P ’]. // m e s s a g e b i t s l e n g t h 87 . // c o d e word disp (G . // b i t v a l u e = 1 I = eye (n -k . ’ c o d e word f o r b i n a r y one i n p u t ’ ) . clc . ’ p a r i t y −c h e c k m a t r i x ’ ) . // p a r i t y −c h e c k m a t r i x G = [ P 1].Chapter 8 Error-Control Coding Scilab code Exa 8. // b l o c k o f i d e n t i c a l ’ n ’ b i t s k =1. 2 : Hamming c o d e s 3 clear .2 Hamming Codes 1 // C a p t i o n : Hamming Codes 2 // Example8 . 5 k = 4. // I d e n t i t y m a t r i x P = ones (1 .k ) . n =5.1 Repetition Codes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // C a p t i o n : R e p e t i t i o n Codes // Example8 . disp (H . ’ g e n e r a t o r m a t r i x ’ ) .

D = poly (0 .0 .1.3 Hamming Codes Revisited 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // C a p t i o n : Hamming Codes R e v i s i t e d // Example8 .1 .1 . ’ r e m a i n d e r i n p o l y n o m i a l form ’ ) disp (p .0 .1.1. q ] = pdiv (m . ’G ’ ) G (3 . // p a r i t y c h e c k m a t r i x disp (H .0 . // g e n e r a t o r p o l y n o m i a l m = ( D ^3) *(1+0+0+ D ^3) .1.D) . disp (G .:) = G (3 . g ) . // c o e f f i c i e n t m a t r i x disp (P .1 . g * D ^2.0.1 . ’D ’ ) .1 .0 .0 . ’ p a r i t y c h e c h k m a t r i x H ’ ) // m e s s a g e b i t s m = [0 .0. p = coeff ( r ) . 3 : ( 7 .0.:) .0 . ’ c o e f f i c i e n t m a t r i x P ’ ) G = [ P I ].:) = modulo ( G (3 . 21 disp (C . ’ g e n e r a t o r m a t r i x G ’ ) H = [ eye (k -1 .1]. ’ P a r i t y b i t s a r e : ’ ) G = [ g . 0 . 4 ) Hamming c o d e ’ ) Scilab code Exa 8. // g e n e r a t o r m a t r i x disp (G .0 . G (3 . // b l o c k l e n g t h m = n . 1 ] //D = p o l y ( 0 .0 .0 .1. ’ i d e n t i t y m a t r i x I k ’ ) P =[1 .:) + G (1 .k .0.0 . clc .1.0 . g * D ^3]. g = 1+ D +0+ D ^3.1 .0 .0 . 4 ) Hamming Code R e v i s i t e d // m e s s a g e s e q u e n c e = [ 1 .k -1) P ’]. 88 . // Number o f p a r i t y b i t s I = eye (k . G = coeff ( G ) .0 .1 .1 .1 .1 .2) .1 18 // 19 C = m * G .0.1 . k ) .0 . ’ Code words o f ( 7 . g * D .0 .:) . 20 C = modulo (C . // m e s s a g e s e q u e n c e [r . // i d e n t i t y m a t r i x disp (I .1 .1 .2) . 0 .6 7 8 9 10 11 12 13 14 15 16 17 n = 7. disp (r .0 .

H_D = [ D ^4* h . 4 ) C y c l i c hamming code // m e s s a g e s e q u e n c e = [ 1 . 7 f o r Me ss age S e q u e n c e ( 1 0 0 1 ) ’ ) disp ( ’ ’) 14 disp ( ’ S h i f t Contents ’ ) 15 disp ( ’ ’) 16 disp ( ’ 1 17 disp ( ’ 2 Input Register 1 0 89 1 1 0 ’) 0 1 1 ’) . 0 . H_num = numer ( H_D ) . 4 : E n c o d e r f o r t h e ( 7 . // m e s s a g e s e q u e n c e [r . D = poly (0 . 1 ] //D = p o l y ( 0 . D ^5* h .:) = G (1 . 4 ) C y c l i c Hamming Code // Example8 . H = coeff ( H_num ) . 3 C o n t e n t s o f t h e S h i f t R e g i s t e r i n t h e E n c o d e r o f f i g 8 .4 Encoder for the (7.2) . g = 1+ D +0+ D ^3. disp (G . q ] = pdiv (m .2) . 0 .:) = H (1 . ’ G e n e r a t o r M a t r i x G = ’ ) h = 1+ D ^ -1+ D ^ -2+ D ^ -4.:) .D) .:) = modulo ( G (4 . ’ r e m a i n d e r i n p o l y n o m i a l form ’ ) disp (p . ’D ’ ) .:) . p = coeff ( r ) . ’ P a r t i y Check m a t r i x H = ’ ) Scilab code Exa 8. H (1 . disp (r .18 19 20 21 22 23 24 25 26 27 G (4 . disp (H . G (4 . g ) . D ^6* h ].:) + G (2 . ’ P a r i t y b i t s a r e : ’ ) disp ( ’ T a b l e 8 .:) + H (3 .4) Cyclic Hamming Code 1 2 3 4 5 6 7 8 9 10 11 12 13 // C a p t i o n : E n c o d e r f o r t h e ( 7 . H (1 .:) + G (4 .:) . // g e n e r a t o r p o l y n o m i a l m = ( D ^3) *(1+0+0+ D ^3) .:) = modulo ( H (1 .:) .

4 ) C y c l i c Hamming Code // Example8 . //m i t symbol −b 90 . g ) . g ) . 0 .2) .2) .5 Syndrome calculator for the(7. 5 m =2. // e r r o r f r e e c o d e w o r d C2 = 0+ D + D ^2+0+0+0+ D ^6. 1 . ’ r e m a i n d e r i n p o l y n o m i a l form f o r e r r o r e d codeword ’ ) disp ( S2 . ’D ’ ) . 1 ] clc . disp ( r1 .4) Cyclic Hamming Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // C a p t i o n : Syndrome c a l c u l a t o r f o r t h e ( 7 . q1 ] = pdiv ( C1 . S1 = coeff ( r1 ) .6 Reed-Solomon Codes 1 // C a p t i o n : Reed−Solomon Codes 2 // Example8 . ’ Syndrome b i t s f o r e r r o r f r e e c o d e w o r d a r e : ’ ) [ r2 . // g e n e r a t o r p o l y n o m i a l C1 = 0+ D + D ^2+ D ^3+0+0+ D ^6. D = poly (0 .18 19 20 disp ( ’ 3 disp ( ’ 4 disp ( ’ ’) 0 1 1 1 1 ’) 0 1 1 ’) Scilab code Exa 8. S2 = coeff ( r2 ) . disp ( r2 . ’ Syndrome b i t s f o r e r r o r e d c o d e w o r d a r e : ’ ) Scilab code Exa 8. 5 : Syndrome c a l c u l a t o r // m e s s a g e s e q u e n c e = [ 0 . q2 ] = pdiv ( C2 . 6 : Reed−Solomon Codes 3 // S i n g l e −e r r o r −c o r r e c t i n g RS c o d e w i t h a 2− b i t b y t e 4 clc . // m i d d l e b i t i s e r r o r [ r1 . 1 . 1 . 0 . S1 = modulo ( S1 . ’ r e m a i n d e r i n p o l y n o m i a l form ’ ) disp ( S1 . S2 = modulo ( S2 . g = 1+ D +0+ D ^3.

x2 (N . clc . m ) ) . // c o d e r a t e disp (n . 1 ] // E n t e r t h e i n p u t Bottom Adder S e q u e n c e : = [ 1 .2) . 1 . m ) ) . ’ Code r a t e : r = k / n = ’ ) disp (2* t . // number o f m e s s a g e b i t s t =1. 7 : C o n v o l u t i o n a l Code G e n e r a t i o n // Time Domain Approach close .Time domain approach 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // C a p t i o n : C o n v o l u t i o n a l E n c o d i n g − Time domain approach // Example8 . x2 = round ( convol ( g2 .7 Convolutional Encoding . g1 = input ( ’ E n t e r t h e i n p u t Top Adder S e q u e n c e := ’ ) g2 = input ( ’ E n t e r t h e i n p u t Bottom Adder S e q u e n c e := ’ ) m = input ( ’ E n t e r t h e m e s s a g e s e q u e n c e := ’ ) x1 = round ( convol ( g1 . ’ n ’ ) disp (p . 1 . 1 ] // E n t e r t h e m e s s a g e s e q u e n c e : = [ 1 .i +1) . // p a r i t y b i t s l e n g t h i n 2− b i t b y t e r = k / n . 0 . ’ n−k ’ ) disp (r . end x = string ( x ) disp ( x ) // R e s u l t // E n t e r t h e i n p u t Top Adder S e q u e n c e : = [ 1 .2) . // s i n g l e b i t e r r o r c o r r e c t i o n n = 2^ m -1.i +1) ]. 1 ] // x = // ! 1 1 ! 91 . // c o d e word l e n g t h i n 2− b i t b y t e p = n . 0 . ’ I t can c o r r e c t any e r r o r u p t o = ’ ) Scilab code Exa 8.6 7 8 9 10 11 12 13 14 k = 1^2.k . x1 = modulo ( x1 . for i =1: length ( x1 ) x (i . N = length ( x1 ) .:) =[ x1 (N . x2 = modulo ( x2 . 0 .

D = poly (0 . g1D = 1+ D + D ^2. // // bottom o u t p u t s e q u e n c e // 1. 1. 1. 1. 1.25 26 27 28 29 30 31 32 33 34 35 36 // ! // ! 1 // ! // ! 1 // ! // ! 1 // ! // ! 0 // ! // ! 0 // ! // ! 1 0 1 1 1 1 1 ! ! ! ! ! ! ! ! ! ! ! ! Scilab code Exa 8. ’ t o p o u t p u t s e q u e n c e ’ ) disp ( modulo ( x2 . // bottom o u t p u t p o l y n o m i a l x1 = coeff ( x1D ) . 8 : C o n v o l u t i o n a l c o d e − T r a n s f o r m domain approach clc . // g e n e r a t o r p o l y n o m i a l 2 mD = 1+0+0+ D ^3+ D ^4. ’ bottom o u t p u t s e q u e n c e ’ ) // R e s u l t // t o p o u t p u t s e q u e n c e // 1. 0. // m e s s a g e s e q u e n c e p o l y n o m i a l representation x1D = g1D * mD . // g e n e r a t o r p o l y n o m i a l 1 g2D = 1+ D ^2. 92 . 0. ’D ’ ) .2) . 0. 1. // t o p o u t p u t p o l y n o m i a l x2D = g2D * mD . 1. x2 = coeff ( x2D ) . 1. 1.8 Convolutional Encoding Transform domain approach 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n : C o n v o l u t i o n a l E n c o d i n g T r a n s f o r m domain approach // Example8 . disp ( modulo ( x1 .2) . 1.

// t r a n s i t i o n p r o b i l i t y p = 1 . // b r a n c h m e t r i c f o r any one correct recption gamma_3 = 2* log2 ( pe ) +1. // b r a n c h m e t r i c f o r no correct reception disp ( gama_1 .pe . // b r a n c h m e t r i c f o r correct reception gamma_2 = log2 ( pe * p ) +1.04. // p r o b a b i l i t y o f c o r r e c t r e c e p t i o n gama_1 = 2* log2 ( p ) +2*(1 . ’ b r a n c h m e t r i c f o r c o r r e c t r e c e p t i o n ’ ) disp ( gamma_2 .7027499 // b r a n c h m e t r i c f o r no c o r r e c t r e c e p t i o n // − 8. ’ b r a n c h m e t r i c f o r no c o r r e c t r e c e p t i o n ’) // b r a n c h m e t r i c f o r c o r r e c t r e c e p t i o n // 0.r ) . // c o d e r a t e n =2. r = 1/2.2877124 93 .Scilab code Exa 8. 1 1 : C o n v o l u t i o n a l c o d e f o r b i n a r y symmetric channel clc .11 Fano metric for binary symmetric channel using convolutional code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // C a p t i o n : Fano m e t r i c f o r b i n a r y s y m m e t r i c c h a n n e l using c o n v o l u t i o n a l code // Example8 .8822126 // b r a n c h m e t r i c f o r any one c o r r e c t r e c p t i o n // − 3. ’ b r a n c h m e t r i c f o r any one c o r r e c t recption ’) disp ( gamma_3 . // number o f b i t s pe = 0.

9 .19].8 . x3 ) .11 . x2 =0. N = input ( ’ E n t e r t h e p e r i o d o f t h e s i g n a l ’ ) for i =1: N x3 = x2 . x2 = x1 . x3 =0.17 .12 . disp (i . 1 : Maximum−l e n g t h s e q u e n c e generator // Program t o g e n e r a t e Maximum Length Pseudo N o i s e Sequence // P e r i o d o f PN S e q u e n c e N = 7 clc .1 PN sequence generation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // C a p t i o n : PN s e q u e n c e g e n e r a t i o n // Example9 . disp (x . 1 and F i g u r e 9 . // A s s i g n I n i t i a l v a l u e f o r PN g e n e r a t o r x0 = 1.Chapter 9 Spread-Spectrum Modulation Scilab code Exa 9. x1 = x0 . ’ The PN s e q u e n c e a t s t e p ’ ) x = [ x1 x2 x3 ].10 . x1 = 0. ’ x= ’ ) end m = [7 .13 . 94 . x0 = xor ( x1 .

// The PN s e q u e n c e a t s t e p 6. // x= 1. 0. // x= 0. // The PN s e q u e n c e a t s t e p 5. // The PN s e q u e n c e a t s t e p 7. 1 Range o f PN S e q u e n c e l e n g t h s ’ ) 24 disp ( ’ 25 26 27 28 29 ’) disp ( ’ Length o f s h i f t r e g i s t e r (m) ’ ) disp ( m ) disp ( ’PN s e q u e n c e Length (N) ’ ) disp ( N ) disp ( ’ ’) // RESULTEnter t h e p e r i o d o f t h e s i g n a l 7 // The PN s e q u e n c e a t s t e p 1. 0. // x= 0. 1. 6 // A s s i g n I n i t i a l v a l u e f o r PN g e n e r a t o r 7 x0 = 1. 0. // The PN s e q u e n c e a t s t e p 3. 1. // x= 1. 2 and F i g u r e 9 . // The PN s e q u e n c e a t s t e p 2. 1. 2 : Maximum−l e n g t h s e q u e n c e 3 // P e r i o d o f PN S e q u e n c e N = 7 4 // P r o p e r i t e s o f maximum−l e n g t h s e q u e n c e 5 clc . 23 disp ( ’ T a b l e 9 . 1. 95 . 8 x1 = 0. // x= 1. 1. 0. 1. 1. // x= 1. // x= 0. 0. 0. 1.2 Maximum length sequence property 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 1 // C a p t i o n : Maximum l e n g t h s e q u e n c e p r o p e r t y 2 // Example9 . Scilab code Exa 9. // The PN s e q u e n c e a t s t e p 4.22 N = 2^ m -1.

5 if ( zero_count < one_count ) disp ( one_count . N = input ( ’ E n t e r t h e p e r i o d o f t h e s i g n a l ’ ) one_count = 0.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 x2 =0. // figure a = gca () . x2 = x1 . x1 = x0 . disp (x . ’ Number o f 0 s i n t h e g i v e n PN sequence ’) disp ( ’ P r o p e r t y 1 ( B a l a n c e p r o p e r t y ) i s s a t i s i f i e d ’ ) end Rc_tuo = corr ( C_level . ’ Output S e q u e n c e l e v e l s ’ ) // r e f e r equation 9. t = 1:2* length ( C_level ) . N ) . ’ Output S e q u e n c e ’ ) // r e f e r e q u a t i o n 9 . 96 . x0 = xor ( x1 . ’ Number o f 1 s i n t h e g i v e n PN sequence ’) disp ( zero_count . end end disp (C . if ( C ( i ) ==1) C_level ( i ) =1. one_count = one_count +1. elseif ( C ( i ) ==0) C_level ( i ) = -1. ’ x= ’ ) C ( i ) = x3 . ’ The PN s e q u e n c e a t s t e p ’ ) x = [ x1 x2 x3 ]. disp (i . for i =1: N x3 = x2 . x3 =0. zero_count = zero_count +1. 4 disp ( C_level . x3 ) . zero_count = 0.

//PN c h i p d u r a t i o n PG = Tb / Tc .[ C_level .3 Processing gain. //PN s e q u e n c e l e n g t h m = log2 ( N +1) . Jamming m a r g i n i n dB // Example9 . 51 a .43 a . ’ The f e e d b a c k s h i f t r e g i s t e r l e n g t h : ’ ) 97 . x_location = ” o r i g i n ” . ’ The r e q u i r e d PN s e q u e n c e i s : ’ ) disp (m . Jamming margin in dB 1 2 3 4 5 6 7 8 9 10 11 12 13 // C a p t i o n : P r o c e s s i n g g a i n . Tb = 4. x_location = ” o r i g i n ” . ’ The p r o c e s s i n g g a i n i s : ’ ) N = PG . // I n f o r m a t i o n b i t d u r a t i o n Tc = 1*10^ -6.[ 53 Rc_tuo ( $ : -1:2) . 50 a . Rc_tuo ] . clc . PN s e q u e n c e l e n g t h . y_location = ” o r i g i n ” . // f e e d b a c k s h i f t r e g i s t e r l e n g t h disp (N . C_level ]) 45 xlabel ( ’ t ’) 46 title ( ’ Waveform o f maximum−l e n g t h s e q u e n c e [ 0 0 1 1 1 0 1 0 0 1 1 1 0 1] ’) 47 // 48 figure 49 a = gca () .0: length ( Rc_tuo ) -1] . // P r o c e s s i n g g a i n disp ( PG .095*10^ -3. 44 plot2d (t .length ( Rc_tuo ) +1: -1 .5) xlabel ( ’ tuo ’ ) 54 ylabel ( ’ Rc ( t u o ) ’ ) 55 title ( ’ A u t o c o r r e l a t i o n o f maximum−l e n g t h s e q u e n c e ’ ) Scilab code Exa 9. 3 : P r o c e s s i n g g a i n and Jamming Margin clear . 52 plot2d ([ . PN sequence length. close .

Figure 9.1: Example9.2a 98 .

2: Example9.Figure 9.2b 99 .

// number o f b i t s p e r symbol M = 2^ K . // P e r i o d o f t h e PN s e q u e n c e N = 1 5 . ’ l e n g t h o f PN s e q u e n c e p e r hop k = ’ ) disp (2^ k . close . ’ T o t a l number o f f r e q u e n c y h o p s = ’ ) // R e s u l t // number o f b i t s p e r symbol K = 2 . 1 2 2 5 3 9 Scilab code Exa 9. ’ Number o f MFSK t o n e s M ’ ) = disp (N . K =2. 19 // The r e q u i r e d PN s e q u e n c e i s : 4 0 9 5 . ’ P e r i o d o f t h e PN s e q u e n c e N = ’ ) disp (k . 5 : P a r a m e t e r s o f FH/MFSK signal // Slow and F a s t F r e q u e n c y Hopping clear . ’ Jamming Margin i n dB : ’ ) 17 // R e s u l t 18 // The p r o c e s s i n g g a i n i s : 4095. 20 // The f e e d b a c k s h i f t r e g i s t e r l e n g t h : 1 2 .5 Slow and Fast Frequency hopping: FH/MFSK 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // C a p t i o n : Slow and F a s t F r e q u e n c y h o p p i n g : FH/MFSK // Example9 . clc . 4 and Example9 . // Energy t o n o i s e d e n s i t y r a t i o 15 J_P = PG / Eb_No .14 Eb_No = 10. ’ number o f b i t s p e r symbol K = ’ ) disp (M . // l e n g t h o f PN s e q u e n c e p e r hop k = 3 . // Jamming Margin 16 disp (10* log10 ( J_P ) .6 Direct Sequence Spread Coherent BPSK 1 // C a p t i o n : D i r e c t S e q u e n c e S p r e a d C o h e r e n t BPSK 100 . // T o t a l number o f f r e q u e n c y h o p s = 8 .4Example9. // Number o f MFSK t o n e s M = 4 . Scilab code Fig 9. // Number o f MFSK t o n e s N = 2^ M -1. 21 // Jamming Margin i n dB : 2 6 .4Figure9. // l e n g t h o f PN s e q u e n c e p e r hop disp (K . // P e r i o d o f t h e PN s e q u e n c e k = 3.

20 .2) a = gca () . Carrier = 2* sin ( wt *2* %pi ) .1 . 4 : G e n e r a t i o n o f w a v e f o r m s i n DS/BPSK spread spectrum t r a n s m i t t e r clear . y_location = ” o r i g i n ” . ct_polar = [ -1 .1 . -1 .1 .1 . plot2d2 (t . ct = [0 .2].1].1 .0 . -2.0 . y_location = ” o r i g i n ” . N ) -1* ones (1 .1 . data_bounds = [0 . a .1 . a . x_location = ” o r i g i n ” .01:1.1 . -1 . bt = [1* ones (1 .0 .1 . a . plot2d2 (t . mt = bt .5) xlabel ( ’ t ’) 101 27 28 29 30 31 32 33 34 .1 . for i = 1: length ( mt ) st = [ st mt ( i ) * Carrier ]. clc .1 .1 . bt .* ct_polar .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 // F i g u r e 9 .2]. a .1) a = gca () . a . st = []. -2.5) xlabel ( ’ t ’) title ( ’ Data b ( t ) ’ ) subplot (3 . -1 .0 .0 .1 . ct_polar . N ) ]. -1 . x_location = ” o r i g i n ” . N = 7.1 . end // figure subplot (3 . data_bounds = [0 . -1 . wt = 0:0. close .1 . a .20 .1]. t = 0:13.1 .

plot2d2 (t .1) a = gca () . a .2].5) xlabel ( ’ t ’) title ( ’ P r o d u c t S i g n a l m( t ) ’ ) subplot (3 . mt .2]. x_location = ” o r i g i n ” . a . a . a . y_location = ” o r i g i n ” . -2. a . data_bounds = [0 . -2.1 .3) a = gca () . y_location = ” o r i g i n ” .1 . data_bounds = [0 . data_bounds = [0 . a . -2. y_location = ” o r i g i n ” .20 . data_bounds = [0 . a .2]. a . x_location = ” o r i g i n ” . x_location = ” o r i g i n ” .5) xlabel ( ’ t ’) title ( ’ P r o d u c t S i g n a l m( t ) ’ ) // figure subplot (3 .20 .2]. x_location = ” o r i g i n ” . a .20 .1 .20 . -2. a . plot2d2 (t .3) a = gca () .35 36 37 38 39 40 41 42 title ( ’ S p r e a d i n g c o d e c ( t ) ’ ) subplot (3 . a .1 .2) a = gca () . plot ( Carrier ) xlabel ( ’ t ’) title ( ’ C a r r i e r S i g n a l ’ ) subplot (3 . a . y_location = ” o r i g i n ” . 102 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 . mt .

6a 67 68 plot ( st ) xlabel ( ’ t ’) 69 title ( ’DS/BPSK s i g n a l s ( t ) ’ ) 70 // Scilab code ARC 1 Alaw 1 2 3 function [ Cx .3: Figure9.Figure 9. Xmax ] = Alaw (x . A ) // Non− l i n e a r Q u a n t i z a t i o n //A−law : A−law n o n l i n e a r q u a n t i z a t i o n 103 .

Figure 9.6b 104 .6b Figure9.4: Figure9.

Figure 9.5: Figure10.12 105 .

for i = L +1: N h ( i ) = 0. endfunction Scilab code ARC 2 auto correlation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 function [ Rxx ] = auto_correlation ( x ) // A u t o c o r r e l a t i o n o f a g i v e n I n p u t S e q u e n c e // F i n d i n g o u t t h e p e r i o d o f t h e s i g n a l u s i n g autocorrelation technique L = length ( x ) . end N = 2* L -1. N ) . for i = 1: length ( x ) if ( x ( i ) / Xmax < = 1/ A ) Cx ( i ) = A * abs ( x ( i ) / Xmax ) . // n o r m a l i z a t i o n o f o u t p u t v e c t o r Cx = Cx ’.4 5 6 7 8 9 10 11 12 13 14 15 16 17 // x = i n p u t v e c t o r //Cx = A−law c o m p r e s s o r o u t p u t //Xmax = maximum o f i n p u t v e c t o r x Xmax = max ( abs ( x ) ) . end end Cx = Cx / Xmax . elseif ( x ( i ) / Xmax > 1/ A ) Cx ( i ) = (1+ log ( A * abs ( x ( i ) / Xmax ) ) ) . for i = 1: L h (L .i +1) = x ( i ) ./(1+ log ( A ) ) . end for n = 1: N for k = 1: N if ( n >= k ) 106 . end for i = L +1: N x ( i ) = 0./(1+ log ( A ) ) . L ) . Rxx = zeros (1 . h = zeros (1 .

k +1) * h ( k ) .:) =[ x1 (N . 0 . x2 = round ( convol ( g2 . 1 ] // x = 107 . n ] = max ( Rxx ) disp ( ’ P e r i o d o f t h e g i v e n s i g n a l u s i n g Auto C o r r e l a t i o n Sequence ’ ) n endfunction Scilab code ARC 3 Convolutional Coding 1 // C a p t i o n : C o n v o l u t i o n a l Code G e n e r a t i o n 2 // Time Domain Approach 3 close . m ) ) . m ) ) .i +1) ]. N = length ( x1 ) .i +1) . 4 clc . 22 end 23 end 24 end 25 disp ( ’ Auto C o r r e l a t i o n R e s u l t i s ’ ) 26 Rxx 27 disp ( ’ C e n t e r V a l u e i s t h e Maximum o f a u t o c o r r e l a t i o n 28 29 30 31 result ’) [m .2) . 1 . x2 (N .2) .21 Rxx ( n ) = Rxx ( n ) + x (n . 1 . 0 . end x = string ( x ) // R e s u l t // E n t e r t h e i n p u t Top Adder S e q u e n c e : = [ 1 . x1 = modulo ( x1 . 1 ] // E n t e r t h e i n p u t Bottom Adder S e q u e n c e : = [ 1 . for i =1: length ( x1 ) x (i . 1 ] // E n t e r t h e m e s s a g e s e q u e n c e : = [ 1 . 5 g1 = input ( ’ E n t e r t h e i n p u t Top Adder S e q u e n c e := ’ ) 6 g2 = input ( ’ E n t e r t h e i n p u t Bottom Adder S e q u e n c e := ’ 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ) m = input ( ’ E n t e r t h e m e s s a g e s e q u e n c e := ’ ) x1 = round ( convol ( g1 . 0 . x2 = modulo ( x2 .

0 . 1 . Scilab code ARC 5 Hamming Encode 108 . Hamming_Distance = 0.22 23 24 25 26 27 28 29 30 31 32 33 34 // ! 1 // ! // ! 1 // ! // ! 1 // ! // ! 1 // ! // ! 0 // ! // ! 0 // ! // ! 1 1 0 1 1 1 1 1 ! ! ! ! ! ! ! ! ! ! ! ! ! Scilab code ARC 4 Hamming Distance 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // C a p t i o n : Hamming Weight and Hamming D i s t a n c e //H( 7 . 0 . end disp ( Hamming_Distance . 1 . P a r i t y b i t s =3 // c l e a r . 0 . for i = 1: length ( code1 ) Hamming_Distance = Hamming_Distance + xor ( code1 ( i ) . 1 . 0 . Me ss ag e Word l e n g t h = 4 . // G e t t i n g Code Words code1 = input ( ’ E n t e r t h e f i r s t c o d e word ’ ) . 1 ] // E n t e r t h e s e c o n d c o d e word [ 1 . close . 1 . 0 . clc . 1 ] // Hamming D i s t a n c e 4. code2 ( i ) ) . 4 ) // Code Word Length = 7 . code2 = input ( ’ E n t e r t h e s e c o n d c o d e word ’ ) . ’ Hamming D i s t a n c e ’ ) // R e s u l t // E n t e r t h e f i r s t c o d e word [ 0 . 1 .

:) . m1 ( i ) ) ) . end C = [ b m ]. end disp ( ’ ’) // d i s p (m b C) // R e s u l t // E n t e r t h e 1 b i t (MSb) o f m e s s a g e word 109 22 23 24 25 26 27 28 29 30 31 32 33 .:) . xor ( m1 ( i ) . xor ( m3 ( i ) . m2 ( i ) ) ) . 4 ) // Code Word Length = 7 . Me ss ag e Word l e n g t h = 4 . m1 = input ( ’ E n t e r t h e 3 b i t o f m e s s a g e word ’ ) . m (i . ’ Mes sa ge Word ’ ) disp ( b (i . m0 = input ( ’ E n t e r t h e 4 b i t ( LSb ) o f m e s s a g e word ’ ) . clc . disp ( ” ”). b0 ( i ) = xor ( m0 ( i ) . ’ CodeWord ’ ) disp ( ” ”). ’ P a r i t y B i t s ’ ) disp ( C (i . xor ( m2 ( i ) . P a r i t y b i t s =3 // c l e a r . m3 ( i ) ) ) . close .:) = [ m3 ( i ) m2 ( i ) m1 ( i ) m0 ( i ) ]. disp ( ’ ’) for i = 1:2^4 disp ( i ) disp ( m (i . // G e n e r a t i n g P a r i t y b i t s for i = 1:(2^4) b2 ( i ) = xor ( m0 ( i ) . b1 ( i ) = xor ( m1 ( i ) . b (i . m2 = input ( ’ E n t e r t h e 2 b i t o f m e s s a g e word ’ ) .:) .:) = [ b2 ( i ) b1 ( i ) b0 ( i ) ].1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // C a p t i o n : Hamming E n c o d i n g //H( 7 . // G e t t i n g M es sag e Word m3 = input ( ’ E n t e r t h e 1 b i t (MSb) o f m e s s a g e word ’ ) .

0 .1 .0 .0 .0 . .0 .1 .0 Scilab code ARC 5 invmulaw 1 2 3 4 5 .1 . en_code ( i ) = en_code ( i ) -2^ j .0 .1 .1 . en_code ) // E n c o d i n g : C o n v e r t i n g Q u a n t i z e d d e c i m a l s a m p l e values in to binary // x = i n p u t s e q u e n c e //L = number o f q u n a t i z a t i o n l e v e l s // e n c o d e = n o r m a l i z e d i n p u t s e q u e n c e n = log2 ( L ) .1 .0 .1 .0 .1 .1].1 .1 35 // E n t e r t h e 3 b i t o f m e s s a g e word [0 .0 .1 .0 .L .0 . mu ) // Non− l i n e a r Q u a n t i z a t i o n // invmulaw : i n v e r s e mulaw n o n l i n e a r q u a n t i z a t i o n // x = o u t p u t v e c t o r // y = i n p u t v e c t o r ( u s i n g mulaw n o n l i n e a r comression ) 6 x = (((1+ mu ) . .1 .0 .1 .1].0 .1 .1 .( n .0 .1 .1 .1 .0 .0 ./ mu ) 7 endfunction Scilab code ARC 6 PCM Encoding 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 function [ c ] = PCM_Encoding (x .[0 .0 .1 .^( abs ( y ) ) -1) .1 34 // E n t e r t h e 2 b i t o f m e s s a g e word [0 . c = zeros ( length ( x ) .1 .n ) .0 .0 . end end end disp ( c ) 110 . for i = 1: length ( x ) for j = n : -1:0 if ( fix ( en_code ( i ) /(2^ j ) ) ==1) c (i .1 .0 .0 .0 .1 36 // E n t e r t h e 4 b i t ( LSb ) o f m e s s a g e [0 .0 .0 .1 .1 .1].1 .1 .0 .0 .1].j ) ) =1. word .0 .1 . function x = invmulaw (y .

a . 5 y ( i ) = 1. PCM encoding . // S t e p 1 [ SQNR . xq . t = 0:0.5) ./( %pi * x ) .Scilab code ARC 7 PCM Transmission 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // C a p t i o n :PCM T r a n s m i s s i o n ( i n c l u d e s f u n c t i o n s : u n i f o r m p c m .001:1. plot2d2 ( t *2* %pi . s c e ) // T h i s program i s a s a m p l e program f o r P u l s e Code Modulation t r a n s m i s s i o n // s t e p 1 : The g i v e n a n a l o g s i g n a l c o n v e r t e d i n t o quantized sample value // s t e p 2 : Then t h e q u a n t i z e d s a m p l e v a l u e c o n v e r t e d into binary value clc .L . close . // S t e p 2 c = PCM_Encoding (x . a = gca () . L ) . xq . x = sin (2* %pi * t ) . L = 16. 3 x ( i ) = 1. ’ Q u a n t i z e d S i g n a l ’ ]) Scilab code ARC 8 sinc new 1 function [ y ]= sinc_new ( x ) 2 i = find ( x ==0) . en_code ) . y_location = ” o r i g i n ” . 6 endfunction 111 . s c e . en_code ] = uniform_pcm (x . x_location = ” o r i g i n ” . title ( ’ Q u a n t i z a t i o n o f Sampled a n a l o g s i g n a l ’ ) legend ([ ’ Analog s i g n a l ’ . plot2d2 ( t *2* %pi . x ) . // From LS : don ’ t n e e d t h i s i s /0 warning i s o f f 4 y = sin ( %pi * x ) . a .

q = q -(( L -1) /2) * d . en_code = xq . end endfunction 112 .Scilab code ARC 9 uniform pcm 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 function [ SQNR .xq ) ) . xq = x / xmax . xq . else value = 1. for i = 1: L xq ( find ((( q ( i ) -d /2) <= xq ) &( xq <=( q ( i ) + d /2) ) ) ) =. B ) if ( A == B ) value = 0. endfunction Scilab code ARC 10 xor 1 2 3 4 5 6 7 function [ value ] = xor (A . en_code ] = uniform_pcm (x . end xq = xq * xmax . length ( find ( xq == q ( i ) ) ) ) . d = 2/ L .. L ) // x = i n p u t s e q u e n c e //L = number o f q u n a t i z a t i o n l e v e l s xmax = max ( abs ( x ) ) . q = d *[0: L -1]. length ( find ((( q ( i ) -d /2) <= xq ) &( xq <=( q ( i ) + d /2) ) ) ) ) . q ( i ) ..* ones (1 . SQNR = 20* log10 ( norm ( x ) / norm (x . en_code ( find ( xq == q ( i ) ) ) = (i -1) .* ones (1 .

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times