Digital Communication by simon haykins

Embed Size (px)

Citation preview

  • 7/22/2019 Digital Communication by simon haykins

    1/120

    Scilab Code for

    Digital Communication,

    by Simon Haykin 1

    Created byProf. R. Senthilkumar

    Institute of Road and Transport Technologyrsenthil [email protected]

    Cross-Checked byProf. Saravanan Vijayakumaran, IIT Bombay

    [email protected]

    23 August 2010

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

  • 7/22/2019 Digital Communication by simon haykins

    2/120

    Book Details

    Authors: Simon Haykins

    Title: Digital Communication

    Publisher: Willey India

    Edition: Wiley India Edition

    Year: Reprint 2010

    Place: Delhi

    ISBN: 9788126508242

    1

  • 7/22/2019 Digital Communication by simon haykins

    3/120

    Scilab numbering policy used in this document and the relation to theabove book.

    Prb Problem (Unsolved problem)

    Exa Example (Solved example)

    Tab Table

    ARC Additionally Required Code (Scilab Code that is not part of the abovebook but required to solve a particular Example)

    AE Appendix to Example(Scilab Code that is an Appednix to a particularExample of the above book)

    CF Code for Figure(Scilab code that is used for plotting the respective figureof the above book )

    For example, Prb 4.56 means Problem 4.56 of the above book. Exa 3.51means solved example 3.51 of this book. Sec 2.3 means a scilab code whosetheory is explained in Section 2.3 of the book.

    2

  • 7/22/2019 Digital Communication by simon haykins

    4/120

    Contents

    List of Scilab Codes 4

    1 Introduction 2

    2 Fundamental Limit on Performance 5

    3 Detection and Estimation 14

    4 Sampling Process 27

    5 Waveform Coding Techniques 31

    6 Baseband Shaping for Data Transmission 39

    7 Digital Modulation Techniques 59

    8 Error-Control Coding 87

    9 Spread-Spectrum Modulation 94

    3

  • 7/22/2019 Digital Communication by simon haykins

    5/120

    List of Scilab Codes

    CF 1.2 Digital Representation of Analog signal . . . . . . . . 2Exa 2.1 Entropy of Binary Memoryless source . . . . . . . . . 5Exa 2.2 Second order Extension of Discrete Memoryless Source 5Exa 2.3 Entropy, Average length, Variance of Huffman Encoding 7Exa 2.4 Entropy, Average length, Variance of Huffman Encoding 8Exa 2.5 Binary Symmetric Channel . . . . . . . . . . . . . . . 9Exa 2.6 Channel Capacity of a Binary Symmetric Channel . . 10Exa 2.7 Significance of the Channel Coding theorem . . . . . . 10Exa 3.1 Orthonormal basis for given set of signals . . . . . . . 14Exa 3.2 M ARY Signaling . . . . . . . . . . . . . . . . . . . . 16Exa 3.3 Matched Filter output for RF pulse . . . . . . . . . . 19Exa 3.4 Matched Filter output for Noise-like signal . . . . . . . 20Exa 3.6 Linear Predictor of Order one . . . . . . . . . . . . . . 22

    CF 3.29 Implementation of LMS Adaptive Filter algorithm . . 24Exa 4.1 Bound on Aliasing error for Time-shifted sinc pulse . . 27Exa 4.3 Equalizier to compensate Aperture effect . . . . . . . . 28Exa 5.1 Average Transmitted Power for PCM . . . . . . . . . 31Exa 5.2 Comparision of M-ary PCM with ideal system (Channel

    Capacity Theorem) . . . . . . . . . . . . . . . . . . . 31Exa 5.3 Signal-to-Quantization Noise Ratio of PCM . . . . . . 32Exa 5.5 Output Signal-to-Noise ratio for Sinusoidal Modulation 34CF 5.13a (a) u-Law companding . . . . . . . . . . . . . . . . . . 36CF 5.13b (b) A-law companding . . . . . . . . . . . . . . . . . . 36Exa 6.1 Bandwidth Requirements of the T1 carrier . . . . . . . 39

    CF 6.1a (a) Nonreturn-to-zero unipolar format . . . . . . . . . 40CF 6.1b (b) Nonreturn-to-zero polar format . . . . . . . . . . . 40CF 6.1c (c) Nonreturn-to-zero bipolar format . . . . . . . . . . 42Exa 6.2 Duobinary Encoding . . . . . . . . . . . . . . . . . . . 44

    4

  • 7/22/2019 Digital Communication by simon haykins

    6/120

    Exa 6.3 Generation of bipolar output for duobinary coder . . . 47

    CF 6.4 Power Spectra of different binary data formats . . . . 48CF 6.6b (b) Ideal solution for zero ISI . . . . . . . . . . . . . . 49CF 6.7b (b) Practical solution: Raised Cosine . . . . . . . . . 51CF 6.9 Frequency response of duobinary conversion filter . . . 53CF 6.15 Frequency response of modified duobinary conversion

    filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Exa 7.1 QPSK Waveform . . . . . . . . . . . . . . . . . . . . . 59CF 7.1 Waveform of Different Digital Modulation techniques . 61Exa 7.2 MSK waveforms . . . . . . . . . . . . . . . . . . . . . 63CF 7.2 Signal Space diagram for coherent BPSK . . . . . . . 68Tab 7.3 Illustration the generation of DPSK signal . . . . . . . 70

    CF 7.4 Signal Space diagram for coherent BFSK . . . . . . . 72CF 7.6 Signal space diagram for coherent QPSK waveform . . 74Tab 7.6 Bandwidth efficiency of M ary PSK signals . . . . . . 74Tab 7.7 Bandwidth efficiency of M ary FSK signals . . . . . . 76CF 7.29 Power Spectra of BPSK and BFSK signals . . . . . . . 77CF 7.30 Power Spectra of QPSK and MSK signals . . . . . . . 78CF 7.31 Power spectra of M-ary PSK signals . . . . . . . . . . 80CF 7.41 Matched Filter output of rectangular pulse . . . . . . 82Exa 8.1 Repetition Codes . . . . . . . . . . . . . . . . . . . . . 87Exa 8.2 Hamming Codes . . . . . . . . . . . . . . . . . . . . . 87

    Exa 8.3 Hamming Codes Revisited . . . . . . . . . . . . . . . . 88Exa 8.4 Encoder for the (7,4) Cyclic Hamming Code . . . . . . 89Exa 8.5 Syndrome calculator for the(7,4) Cyclic Hamming Code 90Exa 8.6 Reed-Solomon Codes . . . . . . . . . . . . . . . . . . . 90Exa 8.7 Convolutional Encoding - Time domain approach . . . 91Exa 8.8 Convolutional Encoding Transform domain approach 92Exa 8.11 Fano metric for binary symmetric channel using convo-

    lutional code . . . . . . . . . . . . . . . . . . . . . . . 93Exa 9.1 PN sequence generation . . . . . . . . . . . . . . . . . 94Exa 9.2 Maximum length sequence property . . . . . . . . . . 95Exa 9.3 Processing gain, PN sequence length, Jamming margin

    in dB . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Exa 9.4Example9.5Slow and Fast Frequency hopping: FH/MFSK . . . . 100Fig 9.4Figure9.6Direct Sequence Spread Coherent BPSK . . . . . . . . 100ARC 1 Alaw . . . . . . . . . . . . . . . . . . . . . . . . . . . 103ARC 2 auto correlation . . . . . . . . . . . . . . . . . . . . . 106

    5

  • 7/22/2019 Digital Communication by simon haykins

    7/120

    ARC 3 Convolutional Coding . . . . . . . . . . . . . . . . . . 107

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

    6

  • 7/22/2019 Digital Communication by simon haykins

    8/120

    List of Figures

    1.1 Figure1.2a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Figure1.2b . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    2.1 Example2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Example2.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.3 Example2.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    3.1 Example3.1a . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.2 Example3.1b . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.3 Example3.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.4 Example3.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.5 Example3.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.6 Figure3.29 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    4.1 Example4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.2 Example4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    5.1 Example5.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.2 Figure5.13a . . . . . . . . . . . . . . . . . . . . . . . . . . . 375.3 Figure5.13b . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

    6.1 Figure6.1a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416.2 Figure6.1b . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436.3 Figure6.1c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456.4 Figure6.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    6.5 Figure6.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526.6 Figure6.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546.7 Figure6.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566.8 Figure6.15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

    7

  • 7/22/2019 Digital Communication by simon haykins

    9/120

    7.1 Example7.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    7.2 Figure7.1a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647.3 Figure7.1b . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657.4 Figure7.1c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667.5 Example7.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 697.6 Figure7.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707.7 Figure 7.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737.8 Figure7.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757.9 Figure7.12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777.10 Figure7.29 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797.11 Figure7.30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817.12 Figure7.31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    7.13 Figure7.41a . . . . . . . . . . . . . . . . . . . . . . . . . . . 857.14 Figure7.41b . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

    9.1 Example9.2a . . . . . . . . . . . . . . . . . . . . . . . . . . . 989.2 Example9.2b . . . . . . . . . . . . . . . . . . . . . . . . . . . 999.3 Figure9.6a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039.4 Figure9.6b . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049.5 Figure10.12 . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

    1

  • 7/22/2019 Digital Communication by simon haykins

    10/120

    Chapter 1

    Introduction

    Scilab code CF 1.2 Digital Representation of Analog signal

    1 // C ap ti on : D i g i t a l R e p re s e nt a t i on o f Ana lo g s i g n a l2 // F i gu r e 1 . 2 : An al og t o D i g i t a l C on ve rs i on3 clear ;

    4 close ;

    5 clc ;

    6 t = - 1: 0. 01 :1 ;

    7 x = 2* sin ( ( % p i / 2 ) * t ) ;

    8 d i g _d a t a = [ 0 , 1 ,0 , 0 , 0 , 0 , 1 , 0 ,0 , 0 , 0 , 0 , 0 , 0 ,1 , 1 , 0 , 1 , 0 ,1 ]

    9 //10 figure

    11 a = gca () ;

    12 a . x _ l o c at i o n = o r i g i n ;13 a . y _ l o c at i o n = o r i g i n ;14 a . d a t a _ bo u n d s = [ - 2 , - 3 ;2 , 3 ]

    15 plot ( t , x )

    16 plot2d3 ( gnn ,0.5, sqrt ( 2 ) , - 9 )17 plot2d3 ( gnn ,-0.5,- sqrt ( 2 ) , - 9 )18 plot2d3 ( gnn ,1,2,-9)

    19 plot2d3 ( gnn , - 1 , - 2 , - 9 )20 x l a b e l (

    Time )21 y l a b e l (

    2

  • 7/22/2019 Digital Communication by simon haykins

    11/120

    Figure 1.1: Figure1.2a

    V o l t a g e )22 t i t l e ( Anal og Waveform )23 //24 figure

    25 a = gca () ;

    26 a . d a t a _ bo u n d s = [ 0 , 0 ;2 1 , 5 ] ;

    27 plot2d2 ([1: length (dig_data)],dig_data ,5)

    28 t i t l e ( D i g i t a l R e p r es e n t at i o n )

    3

  • 7/22/2019 Digital Communication by simon haykins

    12/120

    Figure 1.2: Figure1.2b

    4

  • 7/22/2019 Digital Communication by simon haykins

    13/120

    Chapter 2

    Fundamental Limit on

    Performance

    Scilab code Exa 2.1 Entropy of Binary Memoryless source

    1 / / C a pt i on : E nt ro py o f B i n ar y M em o ry le ss s o u r c e2 / / Exam ple 2 . 1 : E nt ro py o f B i n ar y M em o ry le ss S o u r ce3 / / p ag e 1 84 clear ;

    5 close ;

    6 clc ;

    7 P o = 0 : 0. 0 1: 1 ;

    8 H _P o = zeros (1 , length ( P o ) ) ;

    9 for i = 2: length ( P o ) - 1

    10 H _P o ( i) = - Po ( i ) *log2 ( P o ( i ) ) - ( 1 - P o ( i ) ) * log2 ( 1 - P o ( i

    ) ) ;

    11 end

    12 / / p l o t13 plot2d ( P o , H _ P o )

    14 x l a b e l ( S ymb ol P r o b a b i l i t y , Po )15 y l a b e l ( H(Po) )

    16 t i t l e ( E n tr o py f u n c t i o n H( Po ) )17 plot2d3 ( gnn ,0.5,1)

    Scilab code Exa 2.2 Second order Extension of Discrete Memoryless Source

    5

  • 7/22/2019 Digital Communication by simon haykins

    14/120

    Figure 2.1: Example2.1

    6

  • 7/22/2019 Digital Communication by simon haykins

    15/120

    1 / / c a p t i o n : S ec on d o r d e r E x t en s i o n o f D i s c r e t e

    M e mo r yl e ss S o u r c e2 / / Example 2 . 2 : E nt ro py o f D i s c r e t e M em or yl es s s o u r c e3 / / p ag e 1 94 clear ;

    5 clc ;

    6 P0 = 1/ 4; // p r o b a b i l i t y o f s o ur c e a l ph ab e t S07 P1 = 1/ 4; // p r o b a b i l i t y o f s o ur c e a l ph ab e t S18 P2 = 1/ 2; // p r o b a b i l i t y o f s o ur c e a l ph ab e t S29 H _R uo = P0 * log2 ( 1 / P 0 ) + P 1 * log2 ( 1 / P 1 ) + P 2 * log2 ( 1 / P 2 ) ;

    10 disp ( E nt ro py o f D i s c r e t e M em o ry le ss S o u r ce )11 disp ( b i t s , H _ R u o )

    12 // S ec on d o r d er E x te ns i on o f d i s c r e t e Me mo ry le sss o u r c e

    13 P _ s ig m a = [ P 0 * P0 , P 0 * P 1 , P 0 * P2 , P 1 * P 0 , P 1 * P1 , P 1 * P 2 , P 2 * P0

    , P 2 * P 1 , P 2 * P 2 ] ;

    14 disp ( T ab le 2 . 1 A lp ha be t P a r t i c u l a r s o f Secondo r d e rE x te n si o n o f a D i s c r e t e Me mo ry le ss S ou rc e )

    15 disp (

    )16 disp ( S e qu e nc e o f S ym bo ls o f r u o2 : )17 disp (

    S0 S0 S0 S1 S0 S2 S1 S0 S1 S1 S1 S2 S2 S0 S2 S1 S2 S2 )18 disp (P_s igma , P r o b a b i l i t y p ( s ig ma ) , i = 0 , 1 . . . . . 8 )19 disp (

    )20 disp ( )21 H _ R u o_ S q u ar e = 0 ;

    22 for i = 1: length ( P _ s i g m a )

    23 H _ R uo _ S q ua r e = H _ R uo _ S q ua r e + P _ s i g ma ( i ) * log2 (1/

    P _ s i g m a ( i ) ) ;

    24 end25 disp ( b i t s , H _ R u o _ Sq u a r e , H( Ruo Square )= )26 disp ( H( R uo Sq uar e ) = 2H(Ruo ) )

    7

  • 7/22/2019 Digital Communication by simon haykins

    16/120

    Scilab code Exa 2.3 Entropy,Average length, Variance of Huffman Encod-

    ing

    1 / / C a pt i on : E nt ro py , A ve ra ge l e n g t h , V a r i a n ce o f H uff man E nc odi ng

    2 / / Example 2 . 3 : Huffman E nc od in g : C a l c u l a t i o n o f 3 / / ( a ) A ve ra g e c od eword l e n g th L 4 / / ( b ) E n tr o py H5 clear ;

    6 clc ;

    7 P0 = 0. 4; // p r o b a b i l i t y o f c ode wo rd 0 0 8 L0 = 2; / / l e n g t h o f c od ew or d S0

    9 P1 = 0. 2; // p r o b a b i l i t y o f c ode wo rd 1 0 10 L1 = 2; / / l e n g t h o f c od ew or d S111 P2 = 0. 2; // p r o b i l i t y o f c od ewo rd 1 1 12 L2 = 2; / / l e n g t h o f c od ew or d S213 P3 = 0. 1; // p r o b i l i t y o f c od ewo rd 0 10 14 L3 = 3; / / l e n g t h o f c od ew or d S315 P 4 = 0. 1; // p r o b i l i t y o f co de wo rd 0 11 16 L4 = 3; / / l e n g t h o f c od ew or d S417 L = P 0 * L 0 + P1 * L 1 + P 2 * L2 + P 3 * L 3 + P 4 * L4 ;

    18 H _R uo = P0 * log2 ( 1 / P 0 ) + P 1 * log2 ( 1 / P 1 ) + P 2 * log2 ( 1 / P 2 ) + P 3

    * log2 ( 1 / P 3 ) + P 4 * log2 ( 1 / P 4 ) ;

    19 disp ( b i t s ,L , A v e r ag e c o de w or d L e n g th L )20 disp ( b i t s , H _ R u o , E nt ro py o f Huffman c o d i ng r e s u l t

    H )21 disp ( p e r c e n t , ( ( L - H _ R u o ) / H _ R u o ) * 1 0 0 , A v e r a ge c o d e

    word l e n g t h L e x c e e ds t h e e n tr o p y H( Ruo ) by o n l y )

    22 s i g ma _ 1 = P 0 * ( L0 - L ) ^ 2 + P 1 * ( L1 - L ) ^ 2 + P 2 * ( L2 - L ) ^ 2 + P 3 * ( L3

    - L ) ^ 2 + P 4 * ( L 4 - L ) ^ 2 ;

    23 disp (sig ma_1 , V a r i n a c e o f H uf fm an c o d e )

    Scilab code Exa 2.4 Entropy, Average length, Variance of Huffman En-coding

    1 / / C a pt i on : E nt ro py , A ve ra ge l e n g t h , V a r i a n ce o f H uff man E nc odi ng

    8

  • 7/22/2019 Digital Communication by simon haykins

    17/120

    2 // Example2 . 4 : I l l u s t r a t i n g n on un i q ue ss o f t he

    H uff man E nc odi ng3 // C a l c u l a t i o n o f ( a ) A ver ag e co de word l e ng t h L ( b) E n t ro p y H

    4 clear ;

    5 clc ;

    6 P0 = 0. 4; // p r o b a b i l i t y o f c ode wo rd 1 7 L0 = 1; / / l e n g t h o f c od ew or d S08 P1 = 0. 2; // p r o b a b i l i t y o f c ode wo rd 0 1 9 L1 = 2; / / l e n g t h o f c od ew or d S1

    10 P2 = 0. 2; // p r o b i l i t y o f c od ewo rd 0 00 11 L2 = 3; / / l e n g t h o f c od ew or d S2

    12 P3 = 0. 1; // p r o b i l i t y o f c od ewo rd 0 01 0 13 L3 = 4; / / l e n g t h o f c od ew or d S314 P 4 = 0. 1; // p r o b i l i t y o f co de wo rd 0 01 1 15 L4 = 4; / / l e n g t h o f c od ew or d S416 L = P 0 * L 0 + P1 * L 1 + P 2 * L2 + P 3 * L 3 + P 4 * L4 ;

    17 H _R uo = P0 * log2 ( 1 / P 0 ) + P 1 * log2 ( 1 / P 1 ) + P 2 * log2 ( 1 / P 2 ) + P 3

    * log2 ( 1 / P 3 ) + P 4 * log2 ( 1 / P 4 ) ;

    18 disp ( b i t s ,L , A v e r ag e c o de w or d L e n g th L )19 disp ( b i t s , H _ R u o , E nt ro py o f Huffman c o d i ng r e s u l t

    H )20 s i g ma _ 2 = P 0 * ( L0 - L ) ^ 2 + P 1 * ( L1 - L ) ^ 2 + P 2 * ( L2 - L ) ^ 2 + P 3 * ( L3

    - L ) ^ 2 + P 4 * ( L 4 - L ) ^ 2 ;

    21 disp (sig ma_2 , V a r i n a c e o f H uf fm an c o d e )

    Scilab code Exa 2.5 Binary Symmetric Channel

    1 / / C a p t i o n : B i n a r y S y m me t ri c C h a nn e l2 / / E xa mp le 2 . 5 : B i n a r y S y mm et ri c C ha n ne l3 clear ;

    4 clc ;

    5 close ;

    6 p = 0 . 4 ; // 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 n7 pe = 1 -p ;// 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 . e )

    t r a n s i t i o n p r o b i l i t y8 disp (p , 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 en t= )

    9

  • 7/22/2019 Digital Communication by simon haykins

    18/120

    9 disp ( T r a ns i t i o n p r o b i l i t y )

    10 disp ( p e , 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 en 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 en t= )

    Scilab code Exa 2.6 Channel Capacity of a Binary Symmetric Channel

    1 / / C a pt i on : C ha nn el C a p a ci t y o f a B i n ar y S ym me tr icChannel

    2 / / E xa mp le 2 . 6 : C h an n el C a p a c i t y o f B i n a r y S ym me tr iChannel

    3 clear ;

    4 close ;

    5 clc ;6 p = 0 : 0. 0 1: 0 .5 ;

    7 for i =1: length ( p )

    8 if ( i ~ = 1 )

    9 C (i ) = 1+ p (i ) *log2 ( p ( i ) ) + ( 1 - p ( i ) ) * log2 ( ( 1 - p ( i ) ) )

    ;

    10 elseif ( i = = 1 )

    11 C ( i ) = 1;

    12 elseif ( i = = length ( p ) )

    13 C ( i ) = 0 ;

    14 end15 end

    16 plot2d ( p , C , 5 )

    17 x l a b e l ( T r a n s i t i o n P r o b i l i t y , p )18 y l a b e l ( C h an n el C a p ac i t y , C )19 t i t l e ( F ig ur e 2 . 10 V a r i a t io n o f c ha nn el c a p ac i t y o f

    a b i n ar y s ym me tr ic c ha nn el w i th t r a n s i t i o np r o b i l i t y p )

    Scilab code Exa 2.7 Significance of the Channel Coding theorem

    1 / / C ap ti on : S i g n i f i c a n c e o f t h e C ha nn el C od in g t he or em2 // Example2 . 7 : S i g n i f i c a n c e o f t he c ha n ne l c o di n g

    t he or e m3 // A ve r age P r o b i l i t y o f E rr or o f R e p et i t i o n Code

    10

  • 7/22/2019 Digital Communication by simon haykins

    19/120

    Figure 2.2: Example2.6

    11

  • 7/22/2019 Digital Communication by simon haykins

    20/120

    4 clear ;

    5 clc ;6 close ;

    7 p = 10 ^ - 2;

    8 p e_ 1 = p ; // A v er a ge 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 er = 1

    9 p e_ 3 = 3 * p ^2 *( 1 - p ) + p ^3 ; // p r o b i l i t y o f e r r o r f o r c o d er a t e r =1/3

    10 p e _5 = 1 0* p ^ 3 * (1 - p ) ^ 2 + 5* p ^ 4 * (1 - p ) + p ^ 5 ; // e r r o r f o rc od e r a t e r =1/5

    11 p e _7 = ( ( 7 *6 * 5 ) / ( 1 * 2* 3 ) ) * p ^ 4 *( 1 - p ) ^ 3 + ( 4 2 / 2) * p ^ 5 * (1 - p

    ) ^ 2 + 7 * p ^ 6 * ( 1 - p ) + p ^ 7 ; // e r r o r f o r c o de r a t e r =1/7

    12 r = [ 1 , 1/ 3 , 1/ 5 , 1/ 7] ;13 p e = [ p e_ 1 , p e_ 3 , p e_ 5 , p e _7 ] ;

    14 a = gca () ;

    15 a . d a t a _ b o u n d s = [ 0 , 0 ; 1 , 0 . 0 1 ] ;

    16 plot2d ( r , p e , 5 )

    17 x l a b e l ( Code r a t e , r )18 y l a b e l ( A ver ag e P r o b a b i l i t y o f e r r or , Pe )19 t i t l e ( F i gu re 2 . 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

    c h a n n e l c o d i n g t he or em )20 l e g e n d ( R e p e t i t i o n c o d es )21 xgrid (1)

    22 disp ( T ab le 2 . 3 A v er a ge P r o b i l i t y o f E rr or f o rR e p e t i t i o n Code )

    23 disp (

    )24 disp (r , C o de R at e , r =1/ n , p e , A ve ra ge P r o b i l i t y o f

    E r r o r , Pe )25 disp (

    )

    12

  • 7/22/2019 Digital Communication by simon haykins

    21/120

    Figure 2.3: Example2.7

    13

  • 7/22/2019 Digital Communication by simon haykins

    22/120

    Chapter 3

    Detection and Estimation

    Scilab code Exa 3.1 Orthonormal basis for given set of signals

    1 // C ap ti on : Ort ho no rm al b a s i s f o r g i v en s e t o f s i g n a l s2 / / Example3 . 1 : F i nd i ng o r th o no r ma l b a s i s f o r t h e g i v e n

    s i g n a l s3 // us in g GramS ch mi dt o r t h o g o n a l i z a t i o n p r oc e du r e4 clear ;

    5 close ;

    6 clc ;

    7 T = 1;

    8 t 1 = 0 : 0. 0 1: T / 3 ;9 t 2 = 0 : 0. 0 1: 2 * T /3 ;

    10 t 3 = T / 3: 0. 01 : T ;

    11 t 4 = 0 :0 .0 1: T ;

    12 s1t = [0 , ones (1 , length ( t 1 ) - 2 ) , 0 ] ;

    13 s2t = [0 , ones (1 , length ( t 2 ) - 2 ) , 0 ] ;

    14 s3t = [0 , ones (1 , length ( t 3 ) - 2 ) , 0 ] ;

    15 s4t = [0 , ones (1 , length ( t 4 ) - 2 ) , 0 ] ;

    16 t 5 = 0 : 0. 0 1: T / 3 ;

    17 p hi 1t = sqrt ( 3 / T ) * [ 0 , ones (1 , length ( t 5 ) - 2 ) , 0 ] ;

    18 t 6 = T / 3 : 0 . 01 : 2 * T / 3 ;19 p hi 2t = sqrt ( 3 / T ) * [ 0 , ones (1 , length ( t 6 ) - 2 ) , 0 ] ;

    20 t 7 = 2 * T /3 : 0. 0 1: T ;

    21 p hi 3t = sqrt ( 3 / T ) * [ 0 , ones (1 , length ( t 7 ) - 2 ) , 0 ] ;

    22 //

    14

  • 7/22/2019 Digital Communication by simon haykins

    23/120

    23 figure

    24 t i t l e ( F ig ur e3 . 4 ( a ) S et o f s i g n a l s t o beo r t h o n o r m a l i z e d )25 subplot ( 4 , 1 , 1 )

    26 a = gca () ;

    27 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 2 ] ;

    28 plot2d2 ( t 1 , s 1 t , 5 )

    29 x l a b e l ( t )30 y l a b e l ( s1 ( t ) )31 subplot ( 4 , 1 , 2 )

    32 a = gca () ;

    33 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 2 ] ;

    34 plot2d2 ( t 2 , s 2 t , 5 )35 x l a b e l ( t )36 y l a b e l ( s2 ( t ) )37 subplot ( 4 , 1 , 3 )

    38 a = gca () ;

    39 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 2 ] ;

    40 plot2d2 ( t 3 , s 3 t , 5 )

    41 x l a b e l ( t )42 y l a b e l ( s3 ( t ) )43 subplot ( 4 , 1 , 4 )

    44 a = gca () ;

    45 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 2 ] ;

    46 plot2d2 ( t 4 , s 4 t , 5 )

    47 x l a b e l ( t )48 y l a b e l ( s4 ( t ) )49 //50 figure

    51 t i t l e ( F i gu r e3 . 4 ( b ) The r e s u l t i n g s e t o f o rt ho no rm alf u n c t i o n s )

    52 subplot ( 3 , 1 , 1 )

    53 a = gca () ;

    54 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 4 ] ;55 plot2d2 (t5, phi1t ,5)

    56 x l a b e l ( t )57 y l a b e l ( phi 1 ( t ) )58 subplot ( 3 , 1 , 2 )

    15

  • 7/22/2019 Digital Communication by simon haykins

    24/120

    Figure 3.1: Example3.1a

    59 a = gca () ;

    60 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 4 ] ;

    61 plot2d2 (t6, phi2t ,5)

    62 x l a b e l ( t )63 y l a b e l ( phi 2 ( t ) )64 subplot ( 3 , 1 , 3 )

    65 a = gca () ;

    66 a . d a t a _ bo u n d s = [ 0 , 0 ;2 , 4 ] ;

    67 plot2d2 (t7, phi3t ,5)68 x l a b e l ( t )69 y l a b e l ( phi 3 ( t ) )

    16

  • 7/22/2019 Digital Communication by simon haykins

    25/120

    Figure 3.2: Example3.1b

    17

  • 7/22/2019 Digital Communication by simon haykins

    26/120

    Scilab code Exa 3.2 M ARY Signaling

    1 // C apt i on :MARY S i g n a l i n g2 //E x ampl e 3 . 2 : MARY SIGNALING3 // S i gn a l c o n s t e l l a t i o n and R e p r e s e nt a t i o n o f d i b i t s4 clear ;

    5 close ;

    6 clc ;

    7 a =1; / / a m p l i t u d e =18 T =1; / / Symbol d u r a t i o n i n s e c o n ds9 // Four m es sa ge p o i n t s

    10 S i1 = [ ( - 3/ 2) * a * sqrt ( T ) , ( - 1 / 2 ) * a * sqrt ( T ) , ( 3 / 2 ) * a *

    sqrt ( T ) , ( 1 / 2 ) * a * sqrt ( T ) ] ;11 a = gca () ;

    12 a . d a t a _ bo u n d s = [ - 2 , - 0. 5; 2 , 0 .5 ]

    13 plot2d ( S i 1 , [ 0 , 0 , 0 , 0 ] , - 1 0 )

    14 x l a b e l ( phi 1 ( t ) )15 t i t l e ( F ig ur e 3 . 8 ( a ) S i gn a l c o n s t e l l a t i o n )16 xgrid (1)

    17 disp ( F i gu r e 3 . 8 ( b ) . R e p re s e n ta t i o n o f t r a n s mi t t e dd i b i t s )

    18 disp ( L o c . o f meg . p o i n t | ( 3/2) as qr 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) )

    19 disp (

    )20 disp ( T r a ns m i tt e d d i b i t | 00 | 01

    | 11 | 10 )21 disp ( )22 disp ( )23 disp ( F ig ur e 3 . 8 ( c ) . D e ci s i on i n t e r v a l s f o r

    r e c e i v e d d i b i t s )24 disp ( R e ce i ve d d i b i t | 00 | 01

    | 11 | 10 )25 disp (

    )26 disp ( I n t e r v a l on p h i 1 ( t ) | x1 < a . s q rt (T) |a . s q r t (

    18

  • 7/22/2019 Digital Communication by simon haykins

    27/120

    Figure 3.3: Example3.2

    T)

  • 7/22/2019 Digital Communication by simon haykins

    28/120

    9 p hi t = sqrt ( 2 / T ) * cos ( 2 * % p i * f c * t 1 ) ;

    10 h op t = p hi t ;11 p hi ot = convol ( p h i t , h o p t ) ;

    12 p hi ot = p hi ot /max ( p h i o t ) ;

    13 t 2 = 0 : 0. 0 1: 2 * T ;

    14 subplot ( 2 , 1 , 1 )

    15 a = gca () ;

    16 a . x _ l o c at i o n = o r i g i n ;17 a . y _ l o c at i o n = o r i g i n ;18 a . d a t a _ bo u n d s = [ 0 , - 1 ; 1 , 1] ;

    19 plot2d ( t 1 , p h i t ) ;

    20 x l a b e l (

    t )21 y l a b e l (

    p h i ( t ) )22 t i t l e ( F i gu r e 3 . 1 3 ( a ) RF p u l s e i n pu t )23 subplot ( 2 , 1 , 2 )

    24 a = gca () ;

    25 a . x _ l o c at i o n = o r i g i n ;26 a . y _ l o c at i o n = o r i g i n ;27 a . d a t a _ bo u n d s = [ 0 , - 1 ; 1 , 1] ;

    28 plot2d ( t 2 , p h i o t ) ;

    29 x l a b e l (

    t )30 y l a b e l (

    ph i0 ( t ) )31 t i t l e ( F i gu r e 3 . 1 3 ( b ) Matched F i l t e r o ut pu t )

    Scilab code Exa 3.4 Matched Filter output for Noise-like signal

    1 / / C a pt i on : Match ed F i l t e r o u tp u t f o r N o is e l i k es i g n a l

    2 // Example3 . 4 : Matched F i l t e r o ut pu t f o r n o i s e l i k e

    20

  • 7/22/2019 Digital Communication by simon haykins

    29/120

    Figure 3.4: Example3.3

    21

  • 7/22/2019 Digital Communication by simon haykins

    30/120

    i n p u t

    3 clear ;4 close ;

    5 clc ;

    6 p h it = 0 .1 * rand ( 1 , 1 0 , uni f or m ) ;7 h op t = p hi t ;

    8 p hi 0t = convol ( p h i t , h o p t ) ;

    9 p hi 0t = p hi 0t /max ( p h i 0 t ) ;

    10 subplot ( 2 , 1 , 1 )

    11 a = gca () ;

    12 a . x _ l o c at i o n = o r i g i n ;13 a . y _ l o c at i o n = o r i g i n ;

    14 a . d a t a _ bo u n d s = [ 0 , - 1 ; 1 , 1] ;15 plot2d ([1: length ( p h i t ) ] , p h i t ) ;

    16 x l a b e l (

    t )17 y l a b e l (

    p h i ( t ) )18 t i t l e ( F ig ur e 3 . 16 ( a ) N oi se L ik e i np ut s i g n a l )19 subplot ( 2 , 1 , 2 )

    20 a = gca () ;

    21 a . x _ l o c at i o n = o r i g i n ;22 a . y _ l o c at i o n = o r i g i n ;23 a . d a t a _ bo u n d s = [ 0 , - 1 ; 1 , 1] ;

    24 plot2d ([1: length ( p h i 0 t ) ] , p h i 0 t ) ;

    25 x l a b e l (

    t )26 y l a b e l (

    ph i0 ( t ) )

    27 t i t l e ( F i gu r e 3 . 1 6 ( b ) Matched F i l t e r o ut pu t )

    Scilab code Exa 3.6 Linear Predictor of Order one

    22

  • 7/22/2019 Digital Communication by simon haykins

    31/120

    Figure 3.5: Example3.4

    23

  • 7/22/2019 Digital Communication by simon haykins

    32/120

    1 / / C ap ti on : L i n e a r P r e d i c t o r o f O rd er o ne

    2 // Example3 . 6 : LINEAR PREDICTION: Pr ed ic to r of OrderOne3 clear ;

    4 close ;

    5 clc ;

    6 Rxx = [ 0. 6 1 0 .6 ];

    7 h 01 = R xx ( 3 ) / Rx x ( 2) ; / / Rxx ( 2 ) = Rxx ( 0 ) , Rxx ( 3 ) =R x x ( 1)

    8 s i gm a _E = R xx ( 2 ) - h 01 * R xx ( 3 ) ;

    9 s i gm a _X = R xx ( 2 ) ;

    10 disp (sig ma_E , P r e d i c t o r e r r o r v a r ia n c e )

    11 disp (sig ma_X , P r e d i c t o r i n pu t v a r i a n c e )12 if ( s i gm a _X > s ig m a_ E )

    13 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 thant h e v a ri a nc e o f t he p r e d i c t o r i np ut )

    14 end

    Scilab code CF 3.29 Implementation of LMS Adaptive Filter algorithm

    1 // Im pl em en ta ti on o f LMS ADAPTIVE FILTER2 // 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 n3 clear ;

    4 clc ;

    5 close ;

    6 o rd er = 1 8;

    7 t = 0 : 0. 0 1 :1 ;

    8 x = sin ( 2 * % p i * 5 * t ) ;

    9 n oi se = rand (1 , length ( x ) ) ;

    10 x _n = x + no is e ;

    11 r e f_ n oi s e = n oi se * rand ( 1 0 ) ;

    12 w = zeros (order ,1);

    13 m u = 0 .0 1* ( sum ( x . ^ 2 ) / length ( x ) ) ;

    14 N = length ( x ) ;15 for k = 1: 1 01 0

    16 for i = 1 : N - o rd er - 1

    17 b u ff e r = r e f _n o i se ( i : i + o r de r - 1) ;

    18 d e s ir e d ( i ) = x _n ( i ) - b u f f er * w ;

    24

  • 7/22/2019 Digital Communication by simon haykins

    33/120

    19 w = w + ( b u f fe r * m u * d e s i re d ( i ) ) ;

    20 end21 end

    22 subplot ( 4 , 1 , 1 )

    23 plot2d ( t , x )

    24 t i t l e ( O r i g n a l I n pu t S i g n a l )25 subplot ( 4 , 1 , 2 )

    26 plot2d (t, noise ,2)

    27 t i t l e ( r and om n o i s e )28 subplot ( 4 , 1 , 3 )

    29 plot2d ( t , x _ n , 5 )

    30 t i t l e ( S i g n a l +n o i s e )

    31 subplot ( 4 , 1 , 4 )32 plot ( d e s i r e d )

    33 t i t l e ( n o i s e r em ov ed s i g n a l )

    25

  • 7/22/2019 Digital Communication by simon haykins

    34/120

    Figure 3.6: Figure3.29

    26

  • 7/22/2019 Digital Communication by simon haykins

    35/120

    Chapter 4

    Sampling Process

    Scilab code Exa 4.1 Bound on Aliasing error for Time-shifted sinc pulse

    1 / / C ap ti on : Bound on A l i a s i n g e r r o r f o r Times h i f t e ds i n c p u l s e

    2 / / Exa mp le4 . 1 : Maximum bou nd on a l i a s i n g e r r o r f o rs i n c p u l s e

    3 clc ;

    4 close ;

    5 t = - 1. 5 :0 . 01 : 2. 5;

    6 g = 2 * s in c _n e w ( 2* t - 1) ;

    7 disp (max ( g ) , A l i a s i n g e r r o r c an no t e xc ee d max | g ( t ) | )

    8 f = - 1: 0. 01 :1 ;

    9 G = [0 ,0 ,0 ,0 , ones (1 , length ( f ) ) , 0 , 0 , 0 , 0 ] ;

    10 f 1 = - 1 . 04 : 0 .0 1 : 1. 0 4 ;

    11 subplot ( 2 , 1 , 1 )

    12 a = gca () ;

    13 a . d a t a _ bo u n d s = [ - 3 , - 1 ;2 , 2 ];

    14 a . x _ l o c at i o n = o r i g i n 15 a . y _ l o c at i o n = o r i g i n

    16 plot2d ( t , g )17 x l a b e l ( t )18 y l a b e l ( g ( t ) )19 t i t l e ( F ig ur e 4 . 8 ( a ) S i n c p u l s e g ( t ) )20 subplot ( 2 , 1 , 2 )

    27

  • 7/22/2019 Digital Communication by simon haykins

    36/120

    Figure 4.1: Example4.1

    21 a = gca () ;

    22 a . d a t a _ bo u n d s = [ - 2 , 0 ;2 , 2 ] ;

    23 a . x _ l o c at i o n = o r i g i n 24 a . y _ l o c at i o n = o r i g i n 25 plot2d2 ( f 1 , G )

    26 x l a b e l ( f )27 y l a b e l ( G( f ) )28 t i t l e ( F i g u re 4 . 8 ( b ) A mp li tu de s pe ct ru m |G( f ) | )

    Scilab code Exa 4.3 Equalizier to compensate Aperture effect

    1 / / C ap ti on : E q u a l i z e r t o c om pe ns at e A p er t ur e e f f e c t

    28

  • 7/22/2019 Digital Communication by simon haykins

    37/120

    2 / / Exa mp le4 . 3 : E q u a l i z e r t o Co mp en sa te f o r a p e r t u r e

    e f f e c t3 clc ;4 close ;

    5 T _ Ts = 0 . 0 1 :0 . 0 1 :0 . 6 ;

    6 / /E = 1 / ( s i n c n e w ( 0 . 5 T Ts ) ) ;7 E ( 1) = 1;

    8 for i = 2: length ( T _ T s )

    9 E ( i ) = ( ( %p i / 2) * T _ Ts ( i ) ) /( sin ( ( % p i / 2 ) * T _ T s ( i ) ) ) ;

    10 end

    11 a = gca () ;

    12 a . d a t a _ bo u n d s = [ 0 , 0 . 8 ;0 . 8 , 1 . 2] ;

    13 plot2d ( T _ T s , E , 5 )14 x l a b e l ( D uty c y c l e T/ Ts )15 y l a b e l ( 1 / s i n c ( 0 . 5 ( T/ Ts ) ) )16 t i t l e ( F i gu r e 4 . 1 6 N or ma li ze d e q u a l i z a t i o n ( t o

    c o mpe n sa te f o r a p e rt u r e e f f e c t ) p l o t t ed v e rs u s T/Ts )

    29

  • 7/22/2019 Digital Communication by simon haykins

    38/120

    Figure 4.2: Example4.3

    30

  • 7/22/2019 Digital Communication by simon haykins

    39/120

    Chapter 5

    Waveform Coding Techniques

    Scilab code Exa 5.1 Average Transmitted Power for PCM

    1 / / C a p t i o n : A v e r ag e T r a n s m i t t e d P ow er f o r PCM2 / / E x am pl e5 . 1 : A v e r ag e T r a n s m i t t e d P ow er o f PCM3 / / P ag e 1 8 74 clear ;

    5 clc ;

    6 s i gm a _N = input ( E nt er t he n o i s e v a r i a n c e ) ;7 k = input ( E nt er t he s e p a r at i o n c o ns t an t f o r on o f f

    s i g n a l i n g ) ;8 M = input ( E nt er t he number o f d i s c r e t e a mp li tu de

    l e v e l s f o r NRZ p o l ar ) ;9 disp ( The a v e r ag e t r a n s m i t t e d p ower i s : )

    10 P = ( k ^ 2 ) *( s i g m a _N ) * ( ( M ^ 2 ) - 1 ) / 1 2;

    11 disp ( P )

    12 / / R e s u l t13 // E n te r t he n o i s e v a r i a n c e 10614 // E nt e r t he s e p a r at i o n c o ns t a n t f o r ono f f s i g n a l i n g

    715 // E nt e r t he number o f d i s c r e t e a mp li tu de l e v e l s f o r

    NRZ p o l a r 216 // The a v er a ge t r a n sm i t t ed power i s : 0 . 0 00 0 1 22

    Scilab code Exa 5.2 Comaprision of M-ary PCM with ideal system (Chan-nel Capacity Theorem)

    31

  • 7/22/2019 Digital Communication by simon haykins

    40/120

    1 / / C a p t i o n : C o m pa r i so n o f Ma r y PCM w i th i d e a l s y st em

    ( C h a nn e l C a p a c i t y T he or em )2 / / E x am pl e5 . 2 : C o m pa r i so n o f Mary PCM system3 / / C h an n el C a p a c i t y t h eo r em4 clear ;

    5 close ;

    6 clc ;

    7 P _ No B_ d B = [ - 2 0 :3 0] ; // I n pu t s i g n a l ton o i s e r a t i o P/NoB , d e c i b e l s

    8 P _N oB = 1 0^ ( P _ No B _d B / 1 0) ;

    9 k =7; // f o r Mar y PCM sys tem ;10 R b_ B = log2 ( 1 + ( 1 2 / k ^ 2 ) * P _ N o B ) ; // b an dwid th e f f i c i e n c y

    i n b i t s / s e c / Hz11 C_B = log2 ( 1 + P _ N o B ) ; // i d e a l s ys te m a c c o rd i n g t o

    Sha nnon s c h a n n e l c a p a c i t y t he or em12 / / p l o t13 a = gca () ;

    14 a . d a t a _ bo u n d s = [ - 3 0 , 0 ; 40 , 1 0 ];

    15 plot2d (P_NoB_dB ,C_B ,5)

    16 plot2d (P _NoB_dB ,Rb_B ,5)

    17 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    18 p o ly 1 . t h i c k ne s s = 2;

    19 p ol y1 . l i n e_ s ty l e = 4 ;

    20 x l a b e l ( I n pu t s i g n a l to n o i s e r a t i o P/NoB , d e c i b e l s )

    21 y l a b e l ( B andwidth e f f i c i e n c y , Rb/B , b i t s p er s ec on dp er h e r t z )

    22 t i t l e ( F i g u re 5 . 9 C om pa ri so n o f Ma r y PCM w i t h t h ei d e a l s sy te m )

    23 l e g e n d ( [ I d e a l S ys te m , PCM ])

    Scilab code Exa 5.3 Signal-to-Quantization Noise Ratio of PCM

    1 / / C a p t i o n : S i g n a l toQ u a n t i z a t i o n N o i s e R a t io o f PCM2 / / E x am pl e5 . 3 : S i g n a l toQ ua n ti z a t i on n o i s e r a t i o3 / / C h a n n el B a nd wi d th B4 clear ;

    32

  • 7/22/2019 Digital Communication by simon haykins

    41/120

    Figure 5.1: Example5.2

    33

  • 7/22/2019 Digital Communication by simon haykins

    42/120

    5 clc ;

    6 n = input ( E nt er no . o f b i t s u se d t o e nc od e : )7 W = input ( E nt er t h e m es sa ge s i g n a l b an wi dt h i n Hz : )

    8 B = n * W ;

    9 disp (B , C ha nn el w id t h i n Hz : )10 SNRo = 6* n - 7.2;

    11 disp ( S N R o , Output S i g n al t o n o i s e r a t i o i n dB : )12 // R es ul t 1 i f n = 8 b i t s13 // E nt e r no . o f b i t s u se d t o e nc od e : 814 // E n te r t he m es sa ge s i g n a l b an wi dt h i n Hz : 4 00 015 // C ha nnel w id th i n Hz : 3 2 0 0 0.

    16 // Output S i gn a l t o n o i se r a t i o i n dB : 4 0 . 817 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /18 // R es ul t 2 i f n = 9 b i t s19 // E n te r no . o f b i t s u se d t o e nc od e : 920 // E n te r t he m es sa ge s i g n a l b an wi dt h i n Hz : 4 0 0021 / / Ch an ne l w id th i n Hz : 3 6 0 0 0 .22 // Output S i gn a l t o n o i se r a t i o i n dB : 4 6 . 823 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /24 // C on c l us i o n : c o mp ar in g r e s u l t 1 w i th r e s u l t 2 i f

    number o f b i t s i n c r e as e d by 125

    // c o r r es p o n d i ng o ut pu t s i g n a l t o n o i s e i n PCMi n c r e as e d by 6 dB .

    Scilab code Exa 5.5 Output Signal-to-Noise ratio for Sinusoidal Modula-tion

    1 / / E xa mp le 5 : D e l t a M o d u la t i o n t o a vo id s l o p eo v e r l o a d d i s t o r t i o n

    2 / / maximum o u t p u t s i g n a l ton o i s e r a t i o f o rs i n u s o i d a l m od ul at io n

    3 / / p ag e 2 07

    4 clear ;5 clc ;

    6 a0 = input ( E nt e r t he a mp li tu de o f s i n u s o i d a l s i g n a l: ) ;

    34

  • 7/22/2019 Digital Communication by simon haykins

    43/120

    7 f0 = input ( E n t e r t he f re 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 : ) ;8 fs = input ( E nt er t he s a mp li ng f r eq u e nc y i n s am pl esp e r s e c o n d s : ) ;

    9 Ts = 1/ fs ; // S am pl in g i n t e r v a l10 d el ta = 2 * %p i * f0 * a 0 * Ts ; // S te p s i z e t o a vo id s l o pe

    o v e r l o a d11 P ma x = ( a 0 ^2 ) / 2; / /maximum p e r m i s s i b l e o u t p u t p ow er12 s i gm a _Q = ( d e lt a ^ 2) / 3 ; // Q u an t iz a ti o n e r r o r o r n o i s e

    v a r i a n c e13 W = f0 ;//Maximum mess age bandwidth14 N = W * Ts * s i gm a_ Q ; / / A ve ra ge o u tp ut n o i s e po wer

    15 S NR o = P ma x / N; / / Maximum o u t p u t s i g n a l ton o i s er a t i o

    16 S NR o_ dB = 1 0* log10 ( S N R o ) ;

    17 disp (SNR o_dB , Maximum out pu t s i gn al ton o s i e i n dBf o r D e l t a M o du a lt i on : )

    18 // R e s ul t 1 f o r f s = 8 000 H er tz19 // E nt e r t he a mp li tu de o f s i n u s o i d a l s i g n a l : 120 // E nt e r t h e f r e qu 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

    : 4 0 0 021 // E n te r t he s am pl in g f r eq u e nc y i n s am pl es p er

    s e c o n d s : 8 0 0 022 //Maximum out pu t s i gn al ton o s i e i n dB f o r D el taM odual t i on : 5 . 1 7 1 7 8 4 9

    23 /// / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

    24 // R e s ul t 2 f o r f s = 1 600 0 H er tz25 // E nt e r t he a mp li tu de o f s i n u s o i d a l s i g n a l : 126 // E nt e r t h e f r e qu 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

    : 4 0 0 027 // E n te r t he s am pl in g f r eq u e nc y i n s am pl es p er

    s e c o n d s : 1 6 0 0 028 //Maximum out pu t s i gn al ton o s i e i n dB f o r D el ta

    M o d u a lt i o n : 3 . 8 5 9 1 1 529 //

    / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

    35

  • 7/22/2019 Digital Communication by simon haykins

    44/120

    30 // C o nc l us i on : c om pa ri ng r e s u l t 1 w it h r e s u l t 2 , i f t h e s a mp l in g f r e q u e n c y31 // i s d o ub le d t he s i g n a l t o n o i se i n c r e a s e d by 9 dB

    Scilab code CF 5.13a (a) u-Law companding

    1 / / C a p t i o n : uLaw companding2 / / F i g u r e 5 . 1 3 ( a ) M ulaw c o mp a nd i ng N o n l i n e a r

    Q u a n t i z a t i o n3 // P l o tt 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 t4 / / V a lu e s o f mu5 clc ;

    6 x = 0 :0 .0 1: 1; / / N o r ma l i ze d i n p u t7 m u = [ 0 , 5 , 25 5] ; // d i f f e r e n t v a l u e s o f mu8 for i = 1: length ( m u )

    9 [ C x (i , :) , X m ax ( i ) ] = m ul aw ( x , mu ( i ) );

    10 end

    11 plot2d ( x / X m a x ( 1 ) , C x ( 1 , : ) , 2 )

    12 plot2d ( x / X m a x ( 2 ) , C x ( 2 , : ) , 4 )

    13 plot2d ( x / X m a x ( 3 ) , C x ( 3 , : ) , 6 )

    14 xtitle ( C o m p r e s s i o n Law : uLaw companding ,

    N o rm a l iz e d I n p u t | x | , N o r m a l i z e d O ut pu t | c ( x ) | );15 l e g e n d ( [ u =0 ] ,[ u=5 ] ,[ u=255 ])

    Scilab code CF 5.13b (b) A-law companding

    1 / / C a p t i o n : Al a w c o mp a n di n g2 / / F i g u r e 5 . 1 3 ( b ) Al a w c om pa nd in g , N o n l i n e a r

    Q u a n t i z a t i o n3 / / P l o t t i n g Al aw 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

    4 // V a lu es o f A5 clc ;

    6 x = 0 :0 .0 1: 1; / / N o r ma l i ze d i n p u t7 A = [ 1 , 2 , 87 .5 6] ; // d i f f e r e n t v a l u es o f A8 for i = 1: length ( A )

    36

  • 7/22/2019 Digital Communication by simon haykins

    45/120

    Figure 5.2: Figure5.13a

    37

  • 7/22/2019 Digital Communication by simon haykins

    46/120

    Figure 5.3: Figure5.13b

    9 [ C x (i , :) , X m ax ( i ) ] = A la w ( x ,A ( i )) ;

    10 end

    11 plot2d ( x / X m a x ( 1 ) , C x ( 1 , : ) , 2 )

    12 plot2d ( x / X m a x ( 2 ) , C x ( 2 , : ) , 4 )

    13 plot2d ( x / X m a x ( 3 ) , C x ( 3 , : ) , 6 )

    14 xtitle ( C o m p r e s s i o n Law : ALaw companding , N o rm a l iz e d I n p u t | x | , N o r m a l i z e d O ut pu t | c ( x ) | );

    15 l e g e n d ( [ A =1 ] ,[ A=2 ] ,[ A=87.56 ])

    38

  • 7/22/2019 Digital Communication by simon haykins

    47/120

    Chapter 6

    Baseband Shaping for Data

    Transmission

    Scilab code Exa 6.1 Bandwidth Requirements of the T1 carrier

    1 / / C a pt i on : B an dw id th R e qu i re m en t s o f t h e T1 c a r r i e r2 / / E xa mp le 6 . 1 : B an dw id th R e q u i r em e n t s o f t h e T1

    C a r r i e r3 / / P ag e 2 5 14 clear ;

    5 clc ;

    6 Tb = input ( E nt er t he b i t d u r at i o n o f t he TDM s i g n a l: )

    7 B o = 1 /( 2* T b ); / /minimum t r a n s m i s s i o n b an dw id th o f T1sy st e m

    8 / / T r a ns m i s si o n b an dw id th f o r r a i s e d c o s i n e s pe ct ru mB

    9 a lp ha = 1; // c o s i n e r o l l o f f f a c t o r10 f 1 = B o *( 1 - a lp ha ) ;

    11 B = 2* Bo - f 1;

    12 disp (B , T r an s mi s si o n ba ndwi dth f o r r a i s e d c o s i n e

    s p ec t ru m i n Hz : )13 / / R e s u l t14 // E n te r t he b i t d u r at i o n o f t he TDM s i g n a l

    : 0 . 6 4 7 1 0 615 / / T r a ns m i s si o n b an dw id th f o r r a i s e d c o s i n e s pe ct ru m

    39

  • 7/22/2019 Digital Communication by simon haykins

    48/120

    i n H z : 1 5 4 5 5 9 5 . 1

    Scilab code CF 6.1a (a) Nonreturn-to-zero unipolar format

    1 // C apt i on : N onr et ur n toz e r o u n i p ol a r f or ma t2 / / F i g u re 6 . 1 ( a ) : D i s c r e t e PAM S i g n a l s G e n er a t io n3 // [ 1 ] . Un ip ol ar NRZ4 / / p ag e 2 355 clear ;

    6 close ;

    7 clc ;

    8 x = [0 1 0 0 0 1 0 0 1 1];

    9 bi n ar y _z e ro = [0 0 0 0 0 0 0 0 0 0];

    10 bi na r y_ on e = [1 1 1 1 1 1 1 1 1 1];

    11 L = length ( x ) ;

    12 L1 = length ( b i n a r y _ z e r o ) ;

    13 t o ta l _d u ra t io n = L * L ;

    14 / / p l o t t i n g15 a = gca () ;

    16 a . d a ta _ bo u nd s = [0 -2 ;L * L1 2 ];

    17 for i =1: L

    18 if ( x ( i ) = = 0 )

    19 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ z e r o ) ;20 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    21 p o ly 1 . t h i c k n es s = 3 ;

    22 else

    23 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ o n e ) ;

    24 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    25 p o ly 1 . t h i c k n es s = 3 ;

    26 end

    27 end

    28 xgrid (1)

    29 t i t l e ( U n i po l a r NRZ )

    Scilab code CF 6.1b (b) Nonreturn-to-zero polar format

    1 // C apt i on : N onr et ur n toz e r o p o l ar f or ma t

    40

  • 7/22/2019 Digital Communication by simon haykins

    49/120

    Figure 6.1: Figure6.1a

    41

  • 7/22/2019 Digital Communication by simon haykins

    50/120

    2 / / F i g u re 6 . 1 ( b ) : D i s c r e t e PAM S i g n a l s G e n er a ti o n

    3 // [ 2 ] . P ol a r NRZ4 / / p ag e 2 355 clear ;

    6 close ;

    7 clc ;

    8 x = [0 1 0 0 0 1 0 0 1 1];

    9 b in ar y_ ne ga ti ve = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];

    10 b i na r y _ p os i t i v e = [1 1 1 1 1 1 1 1 1 1];

    11 L = length ( x ) ;

    12 L1 = length ( b i n a r y _ n e g a t i v e ) ;

    13 t o ta l _d u ra t io n = L * L1 ;

    14 / / p l o t t i n g15 a = gca () ;

    16 a . d a ta _ bo u nd s = [0 -2 ;L * L1 2 ];

    17 for i =1: L

    18 if ( x ( i ) = = 0 )

    19 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ n e g a t i v e ) ;

    20 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    21 p o ly 1 . t h i c k n es s = 3 ;

    22 else

    23 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ p o s i t i v e ) ;

    24 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    25 p o ly 1 . t h i c k n es s = 3 ;

    26 end

    27 end

    28 xgrid (1)

    29 t i t l e ( Po la r NRZ )

    Scilab code CF 6.1c (c) Nonreturn-to-zero bipolar format

    1 // C apt i on : N onr et ur n toz e r o b i p o l a r f or ma t

    2 / / F i g u r e 6 . 1 ( c ) : D i s c r e t e PAM S i g n a l s G e n e r a ti o n3 // [ 3 ] . Bi P ol ar NRZ4 / / p ag e 2 355 clear ;

    6 close ;

    42

  • 7/22/2019 Digital Communication by simon haykins

    51/120

    Figure 6.2: Figure6.1b

    43

  • 7/22/2019 Digital Communication by simon haykins

    52/120

    7 clc ;

    8 x = [0 1 1 0 0 1 0 0 1 1];9 b in ar y_ ne ga ti ve = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];

    10 bi n ar y _z e ro = [0 0 0 0 0 0 0 0 0 0];

    11 b i na r y _ p os i t i v e = [1 1 1 1 1 1 1 1 1 1];

    12 L = length ( x ) ;

    13 L1 = length ( b i n a r y _ n e g a t i v e ) ;

    14 t o ta l _d u ra t io n = L * L1 ;

    15 / / p l o t t i n g16 a = gca () ;

    17 a . d a ta _ bo u nd s = [0 -2 ;L * L1 2 ];

    18 for i =1: L

    19 if ( x ( i ) = = 0 )20 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ z e r o ) ;

    21 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    22 p o ly 1 . t h i c k n es s = 3 ;

    23 elseif ( ( x ( i ) = = 1 ) & ( x ( i - 1 ) ~ = 1 ) )

    24 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ p o s i t i v e ) ;

    25 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    26 p o ly 1 . t h i c k n es s = 3 ;

    27 else

    28 plot ( [ i * L - L + 1 : i * L ] , b i n a r y _ n e g a t i v e ) ;

    29 p o ly 1 = a . c h i l d re n ( 1 ) . c h i l d re n ( 1 ) ;

    30 p o ly 1 . t h i c k n es s = 3 ;

    31 end

    32 end

    33 xgrid (1)

    34 t i t l e ( Bi P ol a r NRZ )

    Scilab code Exa 6.2 Duobinary Encoding

    1 / / C a p t i o n : D u o b i n ar y E n c o d i ng

    2 / / Exa mp le6 . 2 : P r ec o de d D uo bi na ry c o d e r and d e c o d e r3 / / P ag e 2 5 64 clc ;

    5 b = [ 0 ,0 , 1 , 0 ,1 , 1 , 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 ri n p u t

    44

  • 7/22/2019 Digital Communication by simon haykins

    53/120

    Figure 6.3: Figure6.1c

    45

  • 7/22/2019 Digital Communication by simon haykins

    54/120

    6 a ( 1) = x or ( 1 , b (1 ) ) ;

    7 if ( a ( 1 ) = = 1 )8 a _ vo lt s ( 1) = 1 ;

    9 end

    10 for k =2: length ( b )

    11 a ( k ) = x or ( a (k - 1 ) ,b ( k )) ;

    12 if ( a ( k ) = = 1 )

    13 a _ v o l t s ( k ) = 1 ;

    14 else

    15 a _ v o l t s ( k ) = - 1 ;

    16 end

    17 end

    18 a = a ;19 a _ v ol t s = a _ vo lt s ;

    20 disp (a , P r ec o d er o ut p ut i n b i n a r y f or m : )21 disp (a_v olts , P r ec o de r o u tp ut i n v o l t s : )22 // D uo bi na ry c o de r o ut pu t i n v o l t s23 c ( 1) = 1 + a _v ol ts ( 1) ;

    24 for k =2: length ( a )

    25 c ( k ) = a _ vo l ts ( k - 1) + a _ vo l ts ( k ) ;

    26 end

    27 c = c ;

    28 disp (c , D uo bi na ry c o d er o u tp u t i n v o l t s :

    )

    29 // D uo bi na ry d ec o de r o ut pu t by a p p l y in g d e c i s i o nr u l e

    30 for k =1: length ( c )

    31 if ( abs ( c ( k ) ) > 1 )

    32 b_r (k ) = 0;

    33 else

    34 b _r ( k ) = 1;

    35 end

    36 end

    37 b _r = b_r ;

    38 disp ( b _ r , R e co ve re d o r i g i n a l s eq ue nc e a t d e t e c t o roupup t : )

    39 / / R e s u l t40 / / P r ec o d er o u tp ut i n b i n a r y f or m :41 //

    46

  • 7/22/2019 Digital Communication by simon haykins

    55/120

    42 // 1 . 1 . 0 . 0 . 1 . 0 . 0 .

    43 //44 // P re co de r o ut pu t i n v o l t s :45 //46 // 1 . 1 . 1 . 1 . 1 . 1 . 1 .47 //48 // D uo bi na ry c o de r o ut pu t i n v o l t s :49 //50 // 2 . 2 . 0 . 2 . 0 . 0 . 2 .51 //52 // R ec ov er ed o r i g i n a l s e qu e nc e a t d e t e c t o r ou pupt :53 //

    54 // 0 . 0 . 1 . 0 . 1 . 1 . 0 .

    Scilab code Exa 6.3 Generation of bipolar output for duobinary coder

    1 / / C ap ti on : G e ne r a ti o n o f b i p o l a r o ut p ut f o r d u ob i na r yc o d e r

    2 // Example6 . 3 : O pe ra ti on o f C i r c u i t i n f i g u r e 6 . 1 33 // f o r g e n er a t i n g b i p o l a r f or ma t4 / / pa ge 2 56 and p ag e 2 575 / / R e f er T ab le 6 . 46 clc ;

    7 x = [ 0 ,1 , 1 , 0 ,1 , 0 , 0 ,0 , 1 , 1] ; / / i n p u t b i n a r y s e q u e n c e :p r e co d e r i n pu t

    8 y (1) = 1;

    9 for k =2: length ( x ) + 1

    10 y ( k ) = x or ( x (k - 1 ) ,y ( k -1 ) ) ;

    11 end

    12 y _ de l ay = y ( 1: $ - 1) ;

    13 y = y ;

    14 y _ d el a y = y _ de la y ;

    15 disp (y , Modulo2 a d d er o u t pu t : )

    16 disp (y_d elay , D e la y e l e m e n t o u t p u t : )17 for k = 1: length ( y _ d e l a y )

    18 z ( k ) = y ( k +1 ) - y _d e la y ( k );

    19 end

    20 z = z ;

    47

  • 7/22/2019 Digital Communication by simon haykins

    56/120

    21 disp (z , 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

    : )22 / / R e s u l t23 //Modulo 2 a d d er o u tp u t :24 // 1 . 1 . 0 . 1 . 1 . 0 . 0 . 0 .

    0 . 1 . 0 .25 / / D el a y e l e m en t o u tp u t :26 // 1 . 1 . 0 . 1 . 1 . 0 . 0 . 0 .

    0 . 1 .27 / / 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 tp u t i n v o l t s :28 // 0 . 1 . 1 . 0 . 1 . 0 . 0 . 0 .

    1 . 1 .

    Scilab code CF 6.4 Power Spectra of different binary data formats

    1 // C ap ti on : Power S p ec t ra o f d i f f e r e n t b i na r y d at af o r m a t s

    2 // F ig ur e 6 . 4 : Power S p e ct a l D e n s i t i e s o f 3 / / D i f f e r e n t L i ne Co di ng T ec h ni q ue s4 / / [ 1 ] . NRZ P o l a r F or ma t [ 2 ] . NRZ B i p o l a r f o r m a t5 / / [ 3 ] . NRZ U n i p o l a r f o r m a t [ 4 ] . M a n ch e s t er f o r m a t6 / / P ag e 2 4 1

    7 close ;8 clc ;

    9 / / [ 1 ] . NRZ P o l a r f o r m a t10 a = input ( E n te r t h e A mp li tu de v a l u e : ) ;11 fb = input ( E nt er t he b i t r a t e : ) ;12 Tb = 1/ fb ; // b i t d u r a t i o n13 f = 0 : 1/ ( 10 0 * Tb ) : 2/ T b ;

    14 for i = 1: length ( f )

    15 S x x f _N R Z _ P ( i ) = ( a ^ 2 ) * T b *( s i n c _ n ew ( f ( i ) * T b ) ^ 2) ;

    16 S x x f_ N R Z _B P ( i ) = ( a ^ 2 ) * Tb * ( ( s i n c _ ne w ( f ( i ) * T b ) ) ^ 2)

    *(( sin ( % p i * f ( i ) * T b ) ) ^ 2 ) ;

    17 if ( i = = 1 )18 S x x f _N R Z _U P ( i ) = ( a ^ 2 ) * ( Tb / 4 ) * ( ( s i n c _n e w ( f ( i ) * Tb

    ) ) ^ 2 ) + ( a ^ 2 ) / 4 ;

    19 else

    48

  • 7/22/2019 Digital Communication by simon haykins

    57/120

    20 S x x f _N R Z _U P ( i ) = ( a ^ 2 ) * ( Tb / 4 ) * ( ( s i n c _n e w ( f ( i ) * Tb

    ) ) ^ 2 ) ;21 end

    22 S x x f _M a n c h ( i ) = ( a ^ 2 ) * T b *( s i n c _ n ew ( f ( i ) * T b / 2) ^ 2 ) * (

    sin ( % p i * f ( i ) * T b / 2 ) ^ 2 ) ;

    23 end

    24 / / P l o t t i n g25 a = gca () ;

    26 plot2d ( f , S x x f _ N R Z _ P )

    27 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    28 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .29 plot2d (f, Sxxf_NRZ_BP ,2)

    30 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;31 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .32 plot2d (f, Sxxf_NRZ_UP ,5)

    33 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    34 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .35 plot2d (f, Sxxf_Manch ,9)

    36 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    37 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .38 x l a b e l ( fTb> )39 y l a b e l ( Sxx( f )> )40 t i t l e (

    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 in eC o d i n ig T e c hn i q ue s )41 xgrid (1)

    42 l e g e n d ( [ NRZ Po la r Format , NRZ B i p o l a r f o r m a t , NRZU n i p o l a r f o r ma t , M a n c h e s t e r f o r m a t ]) ;

    43 / / R e s u l t44 / / E n te r t h e A mp li tu de v a l u e : 145 // E nt e r t he b i t r a t e : 1

    Scilab code CF 6.6b (b) Ideal solution for zero ISI

    1 // C ap ti on : I d e a l s o l u t i o n f o r z e r o I S I2 // F ig ur e 6 . 6 ( b ) : I d e a l S o l u t i o n f o r I n te rs y m b ol

    I n t e r f e r e n c e3 / / SINC p u l s e

    49

  • 7/22/2019 Digital Communication by simon haykins

    58/120

    Figure 6.4: Figure6.4

    50

  • 7/22/2019 Digital Communication by simon haykins

    59/120

    4 / / p ag e 2 49

    5 rb = input ( E nt er t he b i t r a t e : ) ;6 Bo = rb /2;7 t = - 3 :1 / 1 00 : 3;

    8 x = s i nc _ ne w ( 2* B o * t );

    9 plot ( t , x )

    10 x l a b e l ( t> ) ;11 y l a b e l ( p ( t )> ) ;12 t i t l e ( SINC P ul s e f o r z e r o I S I )13 xgrid (1)

    14 / / R e s u l t15 // E nt e r t he b i t r a t e : 1

    Scilab code CF 6.7b (b) Practical solution: Raised Cosine

    1 // C ap ti on : P r a c t i c a l s o l u t i o n : R ai se d C os in e2 / / F i g u re 6 . 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 sy m b o l

    I n t e r f e r e n c e3 / / R a i s e d C o s i n e S p ec tr u m4 / / p ag e 2 505 close ;

    6 clc ;

    7 rb = input ( E nt er t he b i t r a t e : ) ;8 T b = 1/ r b ;

    9 t = - 3 :1 / 1 00 : 3;

    10 Bo = rb /2;

    11 A l ph a = 0; // I n t i a l i z e d t o z er o12 x = t /T b;

    13 for j = 1: 3

    14 for i = 1: length ( t )

    15 if ( ( j = = 3 ) & ( ( t ( i ) = = 0 . 5 ) | ( t ( i ) = = - 0 . 5 ) ) )

    16 p ( j , i ) = s i n c_ n e w ( 2 * Bo * t ( i ) ) ;

    17 else18 n um = s in c_ ne w ( 2* B o* t (i ) )* cos ( 2 * % p i * A l p h a *

    B o * t ( i ) ) ;

    19 d en = 1 - 1 6* ( A lp ha ^ 2 ) *( B o ^ 2) * ( t ( i) ^ 2) + 0 . 01 ;

    20 p ( j , i ) = n um / d e n ;

    51

  • 7/22/2019 Digital Communication by simon haykins

    60/120

    Figure 6.5: Figure6.6

    52

  • 7/22/2019 Digital Communication by simon haykins

    61/120

    21 end

    22 end23 A lp ha = A lp ha + 0 . 5;

    24 end

    25 a = gca () ;

    26 plot2d ( t , p ( 1 , : ) )

    27 plot2d ( t , p ( 2 , : ) )

    28 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    29 p o l y 1 . f o r e g r o u n d = 2 ;

    30 plot2d ( t , p ( 3 , : ) )

    31 p o ly 2 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    32 p o 1 y 2 . f o r e g r o u n d = 4 ;

    33 p ol y2 . l i n e_ s ty l e = 3 ;34 x l a b e l ( t /Tb> ) ;35 y l a b e l ( p ( t )> ) ;36 t i t l e ( RAISED COSINE SPECTRUM P r a c t i c a l S o l u t i o n

    f o r I S I )37 l e g e n d ( [ R O l l o f f F a c t o r =0 , R O l l o f f F a c t or = 0. 5 ,

    R O l l o f f F a c t or =1 ])38 xgrid (1)

    39 / / R e s u l t40 // E nt e r t he b i t r a t e : 1

    Scilab code CF 6.9 Frequency response of duobinary conversion filter

    1 / / C ap ti on : F re qu en cy r e s p o n s e o f d u ob i na r y c o n v e r s i o nf i l t e r

    2 / / F i g u r e 6 . 9 : F r e qu e n cy R e s po n s e o f D u ob i na r yC on v e r s i on f i l t e r

    3 / / ( a ) A m pl i tu d e R e s po n s e4 / / ( b ) P ha s e R e s po n s e5 / / P ag e 2 5 4

    6 clear ;7 close ;

    8 clc ;

    9 rb = input ( E nt er t he b i t r a t e= ) ;10 T b = 1/ r b ; / / B i t d u r a t i o n

    53

  • 7/22/2019 Digital Communication by simon haykins

    62/120

    Figure 6.6: Figure6.7

    54

  • 7/22/2019 Digital Communication by simon haykins

    63/120

    11 f = - rb / 2 : 1/ 1 00 : r b / 2;

    12 A m p l i tu d e _ Re s p o n se = abs (2* cos ( % p i * f . * T b ) ) ;13 P h a s e_ R e s po n s e = - ( %p i * f . * Tb ) ;

    14 subplot ( 2 , 1 , 1 )

    15 a = gca () ;

    16 a . x _ l o c at i o n = o r i g i n ;17 a . y _ l o c at i o n = o r i g i n ;18 plot2d (f,Amplitude_Response ,2)

    19 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    20 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .21 x l a b e l ( F r e q u e n c y f > )22 y l a b e l ( | H( f ) | > )

    23 t i t l e ( A mp li tu de R ep s on s e o f D uo bi na ry S i n g a l i n g )24 subplot ( 2 , 1 , 2 )

    25 a = gca () ;

    26 a . x _ l o c at i o n = o r i g i n ;27 a . y _ l o c at i o n = o r i g i n ;28 plot2d (f,Phase_Response ,5)

    29 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    30 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .31 x l a b e l (

    F r e qu e n cy f > )32 y l a b e l (

    )33 t i t l e ( P ha se R e ps o ns e o f D uo bi na ry S i n g a l i n g )34 / / R e s u l t35 // E n te r t he b i t r a t e =8

    Scilab code CF 6.15 Frequency response of modified duobinary conver-sion filter

    1 / / C a pt i on : F r eq u en c y r e s p o n s e o f m o d i f i e d d u o b in a r y

    c o n v e r s i o n f i l t e r2 / / F i g u re 6 . 1 5 : F re qu en cy R es po ns e o f M o d if i e dd u o b in a r y c o n v e r s i o n f i l t e r

    3 / / ( a ) A m pl i tu d e R e s po n s e4 / / ( b ) P ha s e R e s po n s e

    55

  • 7/22/2019 Digital Communication by simon haykins

    64/120

    Figure 6.7: Figure6.9

    56

  • 7/22/2019 Digital Communication by simon haykins

    65/120

    5 / / p ag e 2 59

    6 clear ;7 close ;

    8 clc ;

    9 rb = input ( E nt er t he b i t r a t e= ) ;10 T b = 1/ r b ; / / B i t d u r a t i o n11 f = - rb / 2 : 1/ 1 00 : r b / 2;

    12 A m p l i tu d e _ Re s p o n se = abs (2* sin ( 2 * % p i * f . * T b ) ) ;

    13 P h a s e_ R e s po n s e = - (2 * % pi * f . * T b ) ;

    14 subplot ( 2 , 1 , 1 )

    15 a = gca () ;

    16 a . x _ l o c at i o n = o r i g i n ;

    17 a . y _ l o c at i o n = o r i g i n ;18 plot2d (f,Amplitude_Response ,2)

    19 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    20 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .21 x l a b e l ( F r e q u e n c y f > )22 y l a b e l ( | H( f ) | > )23 t i t l e ( A mp li tu de R ep s on s e o f M o d i f i e d D uo bi na ry

    S i n g a l i n g )24 xgrid (1)

    25 subplot ( 2 , 1 , 2 )

    26 a = gca () ;

    27 a . x _ l o c at i o n = o r i g i n ;28 a . y _ l o c at i o n = o r i g i n ;29 plot2d (f,Phase_Response ,5)

    30 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    31 p ol y1 . t h i ck n es s = 2 ; // t he t i c k n e s s o f a c ur ve .32 x l a b e l (

    F r e qu e n cy f > )33 y l a b e l (

    )34 t i t l e ( P ha se R e ps o ns e o f M o d i f i e d D uo bi na ry

    S i n g a l i n g )35 xgrid (1)

    36 / / R e s u l t37 // E n te r t he b i t r a t e =8

    57

  • 7/22/2019 Digital Communication by simon haykins

    66/120

    Figure 6.8: Figure6.15

    58

  • 7/22/2019 Digital Communication by simon haykins

    67/120

    Chapter 7

    Digital Modulation Techniques

    Scilab code Exa 7.1 QPSK Waveform

    1 / / C ap ti on : Waveforms o f D i f f e r e n t D i g i t a l M od ul at io nt e c h n i q u e s

    2 / / Exa mp le7 . 1 S i g n a l S pa c e D ia gr am f o r c o h e r e n t QPSKs y s t e m

    3 clear ;

    4 clc ;

    5 close ;

    6 M =4;

    7 i = 1 : M ;8 t = 0 :0 .0 01 :1 ;

    9 for i = 1: M

    10 s 1 (i , : ) = cos ( 2 * % p i * 2 * t ) * cos ( ( 2 * i - 1 ) * % p i / 4 ) ;

    11 s2 (i , :) = - sin ( 2 * % p i * 2 * t ) * sin ( ( 2 * i - 1 ) * % p i / 4 ) ;

    12 end

    13 S 1 = [] ;

    14 S 2 = [ ] ;

    15 S = [];

    16 I n p u t_ S e q ue n c e = [0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 ];

    17 m = [3 , 1 ,1 , 2] ;18 for i =1: length ( m )

    19 S 1 = [ S1 s1 ( m( i ) ,:) ];

    20 S 2 = [ S2 s2 ( m( i ) ,:) ];

    21 end

    59

  • 7/22/2019 Digital Communication by simon haykins

    68/120

    22 S = S 1 + S 2 ;

    23 figure24 subplot ( 3 , 1 , 1 )

    25 a = gca () ;

    26 a . x _ l o c at i o n = o r i g i n ;27 plot ( S 1 )

    28 t i t l e ( Bi nar y PSK w av e of Oddnumbered b i t s o f i n pu ts e q u e n c e )

    29 subplot ( 3 , 1 , 2 )

    30 a = gca () ;

    31 a . x _ l o c at i o n = o r i g i n ;32 plot ( S 2 )

    33 t i t l e ( B i n a r y PSK w av e o f E vennumbered b i t s o f i n p u t s e q ue n c e )

    34 subplot ( 3 , 1 , 3 )

    35 a = gca () ;

    36 a . x _ l o c at i o n = o r i g i n ;37 plot ( S )

    38 t i t l e ( QPSK wav efo rm )39 //s i n ( ( 2 i 1) % p i / 4 ) %i ;40 / / a n n o t = d e c 2 b i n ( [ 0 : l e n g t h ( y ) 1] , lo g 2 (M) ) ;41 / / d i s p ( y , c o o r d i n a t e s o f m es sa ge p o i n ts )42

    / / d i s p ( a nn o t , d i b i t s v a l u e )43 / / f i g u r e ;44 //a =gc a ( ) ;45 / / a . d a t a b o u n d s = [ 1 , 1 ; 1 , 1 ] ;46 // a . x l o c a t i o n = o r i g i n ;47 // a . y l o c a t i o n = o r i g i n ;48 / / p l o t 2 d ( r e a l ( y ( 1 ) ) , i ma g ( y ( 1 ) ) , 2)49 / / p l o t 2 d ( r e a l ( y ( 2 ) ) , i ma g ( y ( 2 ) ) , 4)50 / / p l o t 2 d ( r e a l ( y ( 3 ) ) , i ma g ( y ( 3 ) ) , 5)51 / / p l o t 2 d ( r e a l ( y ( 4 ) ) , i ma g ( y ( 4 ) ) , 9)52 / / x l a b e l (

    InPhase ) ;

    53 / / y l a b e l (

    Q uadr at ur e ) ;

    60

  • 7/22/2019 Digital Communication by simon haykins

    69/120

    Figure 7.1: Example7.1

    54 / / t i t l e ( C o n s t e l l a t i o n f o r QPSK )55 / / l e g e n d ( [ m es s ag e p o i n t 1 ( d i b i t 1 0 ) ; m e ss a ge

    p o in t 2 ( d i b i t 0 0) ; m es sa ge p o in t 3 ( d i b i t 0 1) ; m es sa ge p o i n t 4 ( d i b i t 1 1) ] , 5 )

    Scilab code CF 7.1 Waveform of Different Digital Modulation techniques

    1 / / C ap ti on : Waveforms o f D i f f e r e n t D i g i t a l M od ul at io nt e c h n i q u e s2 / / F i g u r e 7 . 13 / / D i g i t a l M o du l at i on T e ch n i q ue s4 / / To P l o t t h e ASK , FSK a nd PSk W av ef or ms

    61

  • 7/22/2019 Digital Communication by simon haykins

    70/120

    5 clear ;

    6 clc ;7 close ;

    8 f = input ( E nt er t h e A na lo g C a r r i e r F re qu en cy i n Hz ) ;

    9 t = 0 :1 /5 12 :1 ;

    10 x = sin ( 2 * % p i * f * t ) ;

    11 I = input ( E nt er t he d i g i t a l b i n ar y d at a ) ;12 // Ge n e r a t i o n of ASK Wav ef or m13 X as k = [ ];

    14 for n = 1: length ( I )

    15 if ( ( I ( n ) = = 1 ) & ( n = = 1 ) )

    16 X as k = [ x , X as k ] ;17 elseif ( ( I ( n ) = = 0 ) & ( n = = 1 ) )

    18 Xask = [ zeros (1 , length ( x ) ) , X a s k ] ;

    19 elseif ( ( I ( n ) = = 1 ) & ( n ~ = 1 ) )

    20 X as k = [ X as k , x ] ;

    21 elseif ( ( I ( n ) = = 0 ) & ( n ~ = 1 ) )

    22 X as k = [ Xask , zeros (1 , length ( x ) ) ] ;

    23 end

    24 end

    25 // Ge n e r a t i o n of FSK Wav ef or m26 X fs k = [ ];

    27 x1 = sin ( 2 * % p i * f * t ) ;

    28 x2 = sin ( 2 * % p i * ( 2 * f ) * t ) ;

    29 for n = 1: length ( I )

    30 if ( I ( n ) = = 1 )

    31 X fs k = [ X fs k , x 2 ];

    32 elseif ( I ( n ) ~ = 1 )

    33 X fs k = [ X fs k , x 1 ];

    34 end

    35 end

    36 // Ge n e r a t i o n of PSK Wav ef or m

    37 X ps k = [ ];38 x1 = sin ( 2 * % p i * f * t ) ;

    39 x2 = - sin ( 2 * % p i * f * t ) ;

    40 for n = 1: length ( I )

    41 if ( I ( n ) = = 1 )

    62

  • 7/22/2019 Digital Communication by simon haykins

    71/120

    42 X ps k = [ X ps k , x 1 ];

    43 elseif ( I ( n ) ~ = 1 )44 X ps k = [ X ps k , x 2 ];

    45 end

    46 end

    47 figure

    48 plot ( t , x )

    49 xtitle ( A na lo g C a r r i e r S i g n a l f o r D i g i t a l M od ul at io n )

    50 xgrid

    51 figure

    52 plot ( X a s k )

    53 xtitle ( A m pl i tu d e S h i f t K ey i ng )54 xgrid

    55 figure

    56 plot ( X f s k )

    57 xtitle ( F r eq u en c y S h i f t K ey in g )58 xgrid

    59 figure

    60 plot ( X p s k )

    61 xtitle ( P ha se S h i f t K ey in g )62 xgrid

    63//Example64 / / E nt er t h e A na lo g C a r r i e r F re qu en cy 2

    65 / / E nt er t h e d i g i t a l b i n a r y d at a [ 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 ]

    Scilab code Exa 7.2 MSK waveforms

    1 / / C a pt i on : S i g n a l S pa c e d ia g ra m f o r c o h e r e n t BPSK2 / / E xa mp le 7 . 2 : S e q u e nc e a nd W av ef or ms f o r MSK s i g n a l3 // T abl e 7 . 2 s i g n a l s pa ce c h a r a c t e r i z a t i o n o f MSK4 clear

    5 clc ;6 close ;

    7 M =2;

    8 T b = 1;

    9 t 1 = - Tb : 0 . 01 : T b ;

    63

  • 7/22/2019 Digital Communication by simon haykins

    72/120

    Figure 7.2: Figure7.1a

    64

  • 7/22/2019 Digital Communication by simon haykins

    73/120

    Figure 7.3: Figure7.1b

    65

  • 7/22/2019 Digital Communication by simon haykins

    74/120

    Figure 7.4: Figure7.1c

    66

  • 7/22/2019 Digital Communication by simon haykins

    75/120

    10 t 2 = 0 : 0. 0 1: 2 * Tb ;

    11 p hi 1 = cos ( 2 * % p i * t 1 ) . * cos ( ( % p i / ( 2 * T b ) ) * t 1 ) ;12 p hi 2 = sin ( 2 * % p i * t 2 ) . * sin ( ( % p i / ( 2 * T b ) ) * t 2 ) ;

    13 t et a _0 = [ 0 , %p i ];

    14 t e t a_ t b = [ % p i /2 , - % p i / 2 ] ;

    15 S 1 = [ ] ;

    16 S 2 = [ ] ;

    17 for i = 1: M

    18 s 1( i) = cos ( t e t a _ 0 ( i ) ) ;

    19 s2 (i ) = - sin ( t e t a _ t b ( i ) ) ;

    20 S 1 = [ S1 s1 ( i) * ph i1 ] ;

    21 S 2 = [ S2 s2 ( 1) * p hi 2 ];

    22 end23 for i = M : -1:1

    24 S 1 = [ S1 s1 ( i) * ph i1 ] ;

    25 S 2 = [ S2 s2 ( 2) * p hi 2 ];

    26 end

    27 I n p u t_ S e q ue n c e = [1 , 1 , 0 , 1 , 0 , 0 , 0 ];

    28 S = [];

    29 t = 0 :0 .0 1: 1;

    30 S = [ S cos ( 0 ) * cos ( 2 * % p i * t ) - sin ( % p i / 2 ) * sin ( 2 * % p i * t ) ] ;

    31 S = [ S cos ( 0 ) * cos ( 2 * % p i * t ) - sin ( % p i / 2 ) * sin ( 2 * % p i * t ) ] ;

    32 S = [ S cos ( % p i ) * cos ( 2 * % p i * t ) - sin ( % p i / 2 ) * sin ( 2 * % p i * t )

    ];

    33 S = [ S cos ( % p i ) * cos ( 2 * % p i * t ) - sin ( - % p i / 2 ) * sin ( 2 * % p i * t

    ) ];

    34 S = [ S cos ( 0 ) * cos ( 2 * % p i * t ) - sin ( - % p i / 2 ) * sin ( 2 * % p i * t )

    ];

    35 S = [ S cos ( 0 ) * cos ( 2 * % p i * t ) - sin ( - % p i / 2 ) * sin ( 2 * % p i * t )

    ];

    36 S = [ S cos ( 0 ) * cos ( 2 * % p i * t ) - sin ( - % p i / 2 ) * sin ( 2 * % p i * t )

    ];

    37 y = [ s 1 ( 1) , s 2 ( 1 ) ; s 1 ( 2) , s 2 ( 1 ) ; s 1 ( 2) , s 2 ( 2 ) ; s 1 ( 1) , s 2 ( 2 )

    ];38 disp (y , c o o r d i n a t e s o f m es sa ge p o i n t s )39 figure

    40 subplot ( 3 , 1 , 1 )

    41 a = gca () ;

    67

  • 7/22/2019 Digital Communication by simon haykins

    76/120

    42 a . x _ l o c at i o n = o r i g i n ;

    43 plot ( S 1 )44 t i t l e ( S c a l ed t im e f u n c ti o n s 1 ph i1 ( t ) )45 subplot ( 3 , 1 , 2 )

    46 a = gca () ;

    47 a . x _ l o c at i o n = o r i g i n ;48 plot ( S 2 )

    49 t i t l e ( S c a l ed t im e f u n c ti o n s 2 ph i2 ( t ) )50 subplot ( 3 , 1 , 3 )

    51 a = gca () ;

    52 a . x _ l o c at i o n = o r i g i n ;53 plot ( S )

    54 t i t l e ( O bt ai n ed by a d d in g s 1 ph i1 ( t )+s2 p h i 2 ( t ) o n ab i t byb i t b a s i s )

    Scilab code CF 7.2 Signal Space diagram for coherent BPSK

    1 / / C a pt i on : S i g n a l S pa c e d ia g ra m f o r c o h e r e n t BPSK2 / / F i g u r e 7 . 2 S i g n a l S p ac e Di ag ra m f o r c o h e r e n t BPSK

    s y s t e m3 clear

    4 clc ;

    5 close ;6 M =2;

    7 i = 1 : M ;

    8 y = cos ( 2 * % p i + ( i - 1 ) * % p i ) ;

    9 a nn ot = d ec 2 bi n ( [ length ( y ) - 1 : - 1 : 0 ] , log2 ( M ) ) ;

    10 disp (y , c o o r d i n a t e s o f m es sa ge p o i n t s )11 disp ( a n n o t , M es s ag e p o i n t s )12 figure ;

    13 a = gca () ;

    14 a . d a t a _ bo u n d s = [ - 2 , - 2; 2 , 2] ;

    15 a . x _ l o c at i o n = o r i g i n ;16 a . y _ l o c at i o n = o r i g i n ;17 plot2d ( real ( y ( 1 ) ) , imag ( y ( 1 ) ) , - 9 )

    18 plot2d ( real ( y ( 2 ) ) , imag ( y ( 2 ) ) , - 5 )

    19 x l a b e l (

    68

  • 7/22/2019 Digital Communication by simon haykins

    77/120

    Figure 7.5: Example7.2

    69

  • 7/22/2019 Digital Communication by simon haykins

    78/120

    Figure 7.6: Figure7.2

    InPhase ) ;20 y l a b e l (

    Q uadr at ur e ) ;21 t i t l e ( C o n s t e l l a t i o n f o r BPSK )22 l e g e n d ( [ m es sa ge p o i n t 1 ( b i n a r y 1 ) ; m e ss a ge p o i n t

    2 ( b i n a ry 0 ) ],5)

    Scilab code Tab 7.3 Illustration the generation of DPSK signal

    1 // C ap ti on : I l l u s t r a t i n g t he g e n e r a t i o n o f DPSK s i g n a l

    70

  • 7/22/2019 Digital Communication by simon haykins

    79/120

    2 // T abl e7 . 3 G en er at io n o f D i f f e r e n t i a l Phase s h i f t

    k ey in g s i g n a l3 clc ;4 b k = [ 1 ,0 , 0 , 1 ,0 , 0 , 1 ,1 ]; // i np ut d i g i t a l s eq ue nc e5 for i = 1: length ( b k )

    6 if ( b k ( i ) = = 1 )

    7 b k _n o t ( i ) = ~ 1;

    8 else

    9 b k _n o t ( i ) = 1 ;

    10 end

    11 end

    12 d k_ 1 ( 1) = 1 & bk ( 1) ; // i n i t i a l va lu e o f d i f f e r e n t i a l

    e n co d ed s e q u e n c e13 d k _ 1 _ n o t ( 1 ) = 0 & b k _ n o t ( 1 ) ;

    14 d k ( 1) = x o r ( d k_ 1 ( 1 ) , d k _ 1_ n o t ( 1 ) ) / / f i r s t b i t o f d ps ke n c o d e r

    15 for i=2: length ( b k )

    16 d k_ 1 ( i) = d k (i - 1 ) ;

    17 d k _1 _ no t ( i ) = ~ d k (i - 1 ) ;

    18 d k ( i ) = x or ( ( d k _ 1 ( i ) & bk ( i ) ) , ( d k _ 1 _n o t ( i ) & b k _ no t ( i )

    ) ) ;

    19 end

    20 for i =1: length ( d k )

    21 if ( d k ( i ) = = 1 )

    22 d k _ r a d i a n s ( i ) = 0 ;

    23 elseif ( d k ( i ) = = 0 )

    24 d k _ r a d i a n s ( i ) = % p i ;

    25 end

    26 end

    27 disp ( T ab le 7 . 3 I l l u s t r a t i n g t he G en er a ti o n o f DPSKS i g n a l )

    28 disp (

    )29 disp ( b k , ( bk) )30 b k _ no t = b k_ no t ;

    31 disp ( b k _ n o t , ( bk no t ) )32 dk = dk ;

    71

  • 7/22/2019 Digital Communication by simon haykins

    80/120

    33 disp ( d k , D i f f e r e n t i a l l y e n co de d s eq ue nc e ( dk ) )

    34 d k _ ra d i an s = d k _r a di a ns ;35 disp (dk_radians , T ra n sm i tt ed p ha s e i n r a d i a n s )36 disp (

    )

    Scilab code CF 7.4 Signal Space diagram for coherent BFSK

    1 / / C a pt i on : S i g n a l S pa c e d ia g ra m f o r c o h e r e n t BFSK2 / / F i g u r e 7 . 4 S i g n a l S p ac e Di ag ra m f o r c o h e r e n t BFSK

    s y s t e m3 clear4 clc ;

    5 close ;

    6 M =2;

    7 y = [ 1 ,0 ;0 , 1] ;

    8 a n no t = d e c2 b i n ( [ M - 1: - 1 : 0] , log2 ( M ) ) ;

    9 disp (y , c o o r d i n a t e s o f m es sa ge p o i n t s )10 disp ( a n n o t , M es s ag e p o i n t s )11 figure ;

    12 a = gca () ;

    13 a . d a t a _ bo u n d s = [ - 2 , - 2; 2 , 2] ;14 a . x _ l o c at i o n = o r i g i n ;15 a . y _ l o c at i o n = o r i g i n ;16 plot2d ( y ( 1 , 1 ) , y ( 1 , 2 ) , - 9 )

    17 plot2d ( y ( 2 , 1 ) , y ( 2 , 2 ) , - 5 )

    18 x l a b e l (

    InPhase ) ;19 y l a b e l (

    Q uadr at ur e ) ;

    20 t i t l e ( C o n s t e l l a t i o n f o r BFSK )21 l e g e n d ( [ m es sa ge p o i n t 1 ( b i n a r y 1 ) ; m e ss a ge p o i n t

    2 ( b i n a ry 0 ) ],5)

    72

  • 7/22/2019 Digital Communication by simon haykins

    81/120

    Figure 7.7: Figure 7.4

    73

  • 7/22/2019 Digital Communication by simon haykins

    82/120

    Scilab code CF 7.6 Signal space diagram for coherent QPSK waveform

    1 / / C a pt i on : S i g n a l s p a c e d ia g ra m f o r c o h e r e n t QPSKwaveform

    2 / / F i g u r e 7 . 6 S i g n a l S p ac e Di ag ra m f o r c o h e r e n t QPSKs y s t e m

    3 clear

    4 clc ;

    5 close ;

    6 M =4;

    7 i = 1 : M ;

    8 y = cos ( ( 2 * i - 1 ) * % p i / 4 ) - sin ( ( 2 * i - 1 ) * % p i / 4 ) * % i ;

    9 a n no t = d e c2 b i n ( [ 0: M - 1 ] , log2 ( M ) ) ;10 disp (y , c o o r d i n a t e s o f m es sa ge p o i n t s )11 disp ( a n n o t , d i b i t s v al u e )12 figure ;

    13 a = gca () ;

    14 a . d a t a _ bo u n d s = [ - 1 , - 1; 1 , 1] ;

    15 a . x _ l o c at i o n = o r i g i n ;16 a . y _ l o c at i o n = o r i g i n ;17 plot2d ( real ( y ( 1 ) ) , imag ( y ( 1 ) ) , - 2 )

    18 plot2d ( real ( y ( 2 ) ) , imag ( y ( 2 ) ) , - 4 )

    19 plot2d ( real ( y ( 3 ) ) , imag ( y ( 3 ) ) , - 5 )

    20 plot2d ( real ( y ( 4 ) ) , imag ( y ( 4 ) ) , - 9 )

    21 x l a b e l ( In

    Phase ) ;22 y l a b e l (

    Q uadr at ur e ) ;23 t i t l e ( C o n s t e l l a t i o n f o r QPSK )24 l e g e n d ( [ m es sa ge p o i nt 1 ( d i b i t 1 0) ; m e ss a ge p o i n t

    2 ( d i b i t 0 0) ; m es sa ge p o i nt 3 ( d i b i t 0 1) ;

    m es sa ge p o i nt 4 ( d i b i t 1 1) ],5)

    Scilab code Tab 7.6 Bndwidth efficiency of M ary PSK signals

    74

  • 7/22/2019 Digital Communication by simon haykins

    83/120

    Figure 7.8: Figure7.6

    75

  • 7/22/2019 Digital Communication by simon haykins

    84/120

    1 / / C ap ti on : Ba ndwid th e f f i c i e n c y o f Ma ry PSK s i g n a l s

    2 // T ab le 7 . 6 : Bandwidth E f f i c i e n c y o f Mar y PSKs i g n a l s3 clear ;

    4 clc ;

    5 close ;

    6 M = [ 2 , 4 ,8 , 1 6 ,3 2 , 64 ]; //Ma r y7 Ruo = log2 ( M ) . / 2 ; // Bandwidth e f f i c i e n c y i n b i t s / s /

    Hz8 disp ( T ab le 7 . 7 Bandwidth E f f i c i e n c y o f Mar y PSK

    s i g n a l s )9 disp (

    )10 disp (M , M )11 disp (

    )12 disp ( R u o , r i n b i t s / s /Hz )13 disp (

    )

    Scilab code Tab 7.7 Bandwidth efficiency of M ary FSK signals

    1 / / C ap ti on : Ba ndwid th e f f i c i e n c y o f Ma ry FSK s i g n a l s2 // T ab le 7 . 7 : Bandwidth E f f i c i e n c y o f Mary FSK3 clear ;

    4 clc ;

    5 close ;

    6 M = [ 2 , 4 ,8 , 1 6 ,3 2 , 64 ]; //Ma r y7 Ruo = 2* log2 ( M ) . / M ; // Bandwidth e f f i c i e n c y i n b i t s / s

    /Hz

    8 //M = M ;9 //Ruo = Ruo ;

    10 disp ( T ab le 7 . 7 Bandwidth E f f i c i e n c y o f Mar y FSKs i g n a l s )

    11 disp (

    76

  • 7/22/2019 Digital Communication by simon haykins

    85/120

    Figure 7.9: Figure7.12

    )12 disp (M , M )13 disp (

    )14 disp ( R u o , r i n b i t s / s /Hz )15 disp (

    )

    Scilab code CF 7.29 Power Spectra of BPSK and BFSK signals

    77

  • 7/22/2019 Digital Communication by simon haykins

    86/120

    1 / / C a p t i o n : P ow er S p e c t r a o f BPSK a nd BFSK s i g n a l s

    2 / / F i g u re 7 . 2 9 : C om pa ri so n o f Power S p e c t r a l D e n s i t i e so f BPSK3 // and BFSK4 clc ;

    5 rb = input ( E nt er t he b i t r a t e= ) ;6 Eb = input ( E nt e r t he e ne rg y o f t he b i t= ) ;7 f = 0 : 1/ 1 00 : 8/ r b ;

    8 Tb = 1/ rb ; / / B i t d u r a t i o n9 for i = 1: length ( f )

    10 if ( f ( i ) = = ( 1 / ( 2 * T b ) ) )

    11 S B _ F S K ( i ) = E b / ( 2 * T b ) ;

    12 else13 S B_ F SK ( i ) = ( 8* E b * (cos ( % p i * f ( i ) * T b ) ^ 2 ) ) / ( ( % p i

    ^ 2 ) * ( ( ( 4 * ( T b ^ 2 ) * ( f ( i ) ^ 2 ) ) - 1 ) ^ 2 ) ) ;

    14 end

    15 S B _ P S K ( i ) = 2 * E b * ( s i n c _ n e w ( f ( i ) * T b ) ^ 2 ) ;

    16 end

    17 a = gca () ;

    18 plot ( f * T b , S B _ F S K / ( 2 * E b ) )

    19 plot ( f * T b , S B _ P S K / ( 2 * E b ) )

    20 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    21 p ol y1 . f o r eg r ou n d = 6 ;

    22 x l a b e l ( N o r m a l i z e d F r e q u e n cy > )23 y l a b e l ( N o r ma l i ze d Power S p e c t r a l D e ns i ty > )24 t i t l e ( PSK Vs FSK P ow er Sp e c t r a C ompar i son )25 l e g e n d ( [ F re q ue n cy S h i f t K ey in g , P ha se S h i f t K ey in g

    ])26 xgrid (1)

    27 / / R e s u l t28 // E nt e r t h e b i t r a te i n b i t s p er s ec o nd : 229 // E n te r t he Energ y o f b i t : 1

    Scilab code CF 7.30 Power Spectra of QPSK and MSK signals.

    1 / / C a p t i o n : P ow er S p e c t r a o f QPSK a nd MSK s i g n a l s2 // F i g ur e 7 . 3 0 : C ompar i son of QPSK and MSK P ow er

    78

  • 7/22/2019 Digital Communication by simon haykins

    87/120

    Figure 7.10: Figure7.29

    79

  • 7/22/2019 Digital Communication by simon haykins

    88/120

    Spe c t r ums

    3 / / c l e a r ;4 / / c l o s e ;5 // c l c ;6 rb = input ( E nt e r t he b i t r a t e i n b i t s p er s ec on d : )

    ;

    7 Eb = input ( E nt er t h e E ne rg y o f b i t : ) ;8 f = 0 : 1/ ( 10 0 * rb ) : (4 / r b );

    9 Tb = 1/ rb ; // b i t d u r at i o n i n s e co n d s10 for i = 1: length ( f )

    11 if ( f ( i ) = = 0 . 5 )

    12 S B_ MS K ( i ) = 4 * Eb * f ( i) ;

    13 else14 S B _M S K ( i ) = ( 3 2* E b / ( % p i ^ 2) ) * ( cos ( 2 * % p i * T b * f ( i ) )

    / ( ( 4 * T b * f ( i ) ) ^ 2 - 1 ) ) ^ 2 ;

    15 end

    16 S B _ QP S K ( i ) = 4 * E b * s i nc _ n ew ( ( 2 * T b * f ( i ) ) ) ^2 ;

    17 end

    18 a = gca () ;

    19 plot ( f * T b , S B _ M S K / ( 4 * E b ) ) ;

    20 plot ( f * T b , S B _ Q P S K / ( 4 * E b ) ) ;

    21 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i l dr e n ( 1 ) ;

    22 p ol y1 . f o r eg r ou n d = 3 ;

    23 x l a b e l ( N o r m a l i z e d F r e q u e n cy > )24 y l a b e l ( N o r ma l i ze d Power S p e c t r a l D e ns i ty > )25 t i t l e ( QPSK Vs MSK Power Sp ec tr a Comparison )26 l e g e n d ( [ Minimum S h i f t K e y in g , QPSK ])27 xgrid (1)

    28 / / R e s u l t29 // E nt e r t h e b i t r a te i n b i t s p er s ec o nd : 230 // E n te r t he Energ y o f b i t : 1

    Scilab code CF 7.31 Power spectra of M-ary PSK signals

    1 / / C a pt i on : Power s p e c t r a o f Ma r y PSK s i g n a l s2 / / F i g u re 7 . 3 1 C om pa ri so n o f Power S p e c t r a l D e n s i t i e s

    o f Ma ry PSK s i g n a l s

    80

  • 7/22/2019 Digital Communication by simon haykins

    89/120

    Figure 7.11: Figure7.30

    81

  • 7/22/2019 Digital Communication by simon haykins

    90/120

    3 rb = input ( E nt er t he b i t r a t e= ) ;

    4 Eb = input ( E nt e r t he e ne rg y o f t he b i t= ) ;5 f = 0 :1 /1 00 : rb ;6 Tb = 1/ rb ; / / B i t d u r a t i o n7 M = [ 2 ,4 , 8] ;

    8 for j = 1: length ( M )

    9 for i = 1 : length ( f )

    10 S B _ P S K ( j , i ) = 2 * E b * ( s i n c _ n e w ( f ( i ) * T b * log2 ( M ( j ) ) )

    ^ 2 ) * log2 ( M ( j ) ) ;

    11 end

    12 end

    13 a = gca () ;

    14 plot2d ( f * T b , S B _ P S K ( 1 , : ) / ( 2 * E b ) )15 plot2d ( f * T b , S B _ P S K ( 2 , : ) / ( 2 * E b ) , 2 )

    16 plot2d ( f * T b , S B _ P S K ( 3 , : ) / ( 2 * E b ) , 5 )

    17 x l a b e l ( N o r m a l i z e d F r e q u e n cy > )18 y l a b e l ( N o r ma l i ze d Power S p e c t r a l D e ns i ty > )19 t i t l e ( P ower S p e c tr a o f Ma r y s i g n a l s f o r M =2 , 4 ,8 )20 l e g e n d ( [ M=2 , M=4 , M=8 ])21 xgrid (1)

    22 / / R e s u l t23 // E nt e r t h e b i t r a te i n b i t s p er s ec o nd : 224

    // E n te r t he Energ y o f b i t : 1

    Scilab code CF 7.41 Matched Filter output of rectangular pulse

    1 // C ap ti on : Matched F i l t e r o ut pu t o f r e c t a n g u l a r p u l s e2 / / F i g u r e 7 . 4 13 / / Ma tch ed F i l t e r Ou tp ut4 clear ;

    5 clc ;

    6 T =4;

    7 a =2;8 t = 0 : T ;

    9 g = 2* ones ( 1 , T + 1