Digital Communication S. Haykin

Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

Scilab Textbook Companion for

Digital Communication
by S. Haykin1
Created by
Prof. R. Senthilkumar
B.Tech. + M.Tech
Electronics Engineering
Institute of Road and Transport Technology
College Teacher
Na
Cross-Checked by
Prof. Saravanan Vijayakumaran
May 24, 2016

1 Funded

by a grant from the National Mission on Education through ICT,


http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab
codes written in it can be downloaded from the Textbook Companion Project
section at the website http://scilab.in

Book Description
Title: Digital Communication
Author: S. Haykin
Publisher: Willey India, New Delhi
Edition: 1
Year: 2010
ISBN: 9788126508242

Scilab numbering policy used in this document and the relation to the
above book.
Exa Example (Solved example)
Eqn Equation (Particular equation of the above book)
AP Appendix to Example(Scilab Code that is an Appednix to a particular
Example of the above book)
For example, 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.

Contents
List of Scilab Codes

1 Introduction

2 Fundamental Limit on Performance

3 Detection and Estimation

14

4 Sampling Process

22

5 Waveform Coding Techniques

24

6 Baseband Shaping for Data Transmission

30

7 Digital Modulation Techniques

43

8 Error Control Coding

62

9 Spread Spectrum Modulation

70

List of Scilab Codes


Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

1.2
2.1
2.2
2.3
2.4
2.5
2.6
2.7
3.1
3.2
3.3
3.4
3.6
3.29
4.1
4.3
5.1
5.2
5.3
5.5
05.13
5.13
06.01
06.1
6.01
6.1
6.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 Channe . . . . . . . . . . . . . . .
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 . . . . .
Bound on Aliasing error for Time-shifted sinc pulse . .
Equalizer to compensate Aperture effect . . . . . . . .
Average Transmitted Power for PCM . . . . . . . . .
Comparison of M-ary PCM with ideal system . . . . .
Signal-to-Quantization Noise Ratio of PCM . . . . . .
Delta Modulation - to avoid slope overload distortion .
A-law companding . . . . . . . . . . . . . . . . . . . .
u-Law companding . . . . . . . . . . . . . . . . . . . .
Nonreturn-to-zero bipolar format . . . . . . . . . . . .
Nonreturn-to-zero polar format . . . . . . . . . . . . .
Nonreturn-to-zero unipolar format . . . . . . . . . . .
Bandwidth Requirements of the T1 carrier . . . . . . .
Frequency response of modified duobinary conversion
filter . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4

5
7
8
9
10
11
11
12
14
16
17
18
19
20
22
23
24
25
26
27
28
29
30
31
32
33
34

Exa
Exa
Exa
Exa
Exa
Exa

6.3
6.4
6.6
6.7
6.9
6.15

Generation of bipolar output for duobinary coder . . .


Power Spectra of different binary data formats . . . .
Ideal solution for zero ISI . . . . . . . . . . . . . . . .
Practical solution: Raised Cosine . . . . . . . . . . .
Frequency response of duobinary conversion filte . . .
Frequency response of modified duobinary conversion
filter . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exa 7.01 Waveforms of Different Digital Modulation techniques
Exa 7.1
Waveforms of Different Digital Modulation techniques
Exa 7.02 Signal Space diagram for coherent BPSK . . . . . . .
Exa 7.2
Signal Space diagram for coherent BPSK . . . . . . .
Exa 7.3
Illustrating the generation of DPSK signal . . . . . . .
Exa 7.4
Signal Space diagram for coherent BFSK . . . . . . .
Exa 7.4.7.20Comparison of error probability . . . . . . . . . . . .
Exa 7.06 Bandwidth efficiency of M-ary PSK signals . . . . . .
Exa 7.6
Signal space diagram for coherent QPSK waveform . .
Exa 7.7
Bandwidth efficiency of M-ary FSK signals . . . . . .
Exa 7.12.7.2Signal space diagram for MSK diagram . . . . . . . .
Exa 7.29 Power Spectra of BPSK and BFSK signals . . . . . . .
Exa 7.30 Power Spectra of QPSK and MSK signals . . . . . . .
Exa 7.31 Power spectra of M-ary PSK signals . . . . . . . . . .
Exa 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 . . . . . . . . . . . . . . . . .
Exa 8.11 ano metric for binary symmetric channel . . . . . . . .
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.4.9.5 Slow and Fast Frequency hopping: FH/MFSK . . . .
Exa 9.4.96 Direct Sequence Spread Coherent BPSK . . . . . . . .

35
36
38
39
40
41
43
45
47
48
49
51
52
53
54
55
56
57
58
59
60
62
62
63
64
65
66
66
68
68
70
71
73
74
75

Chapter 1
Introduction

Scilab code Exa 1.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
21

// c l e a r //
// 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 . 2 : Analog t o D i g i t a l C o n v e r s i o n
clear ;
close ;
clc ;
t = -1:0.01:1;
x = 2* sin (( %pi /2) * t ) ;
dig_data = [0 ,1 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,0 ,1 ,0 ,1]
//
figure
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds =[ -2 , -3;2 ,3]
plot (t , x )
plot2d3 ( gnn ,0.5 , sqrt (2) , -9)
plot2d3 ( gnn , -0.5 , - sqrt (2) , -9)
plot2d3 ( gnn ,1 ,2 , -9)
plot2d3 ( gnn , -1 , -2 , -9)
xlabel (
6

22

Time )
ylabel (

23
24
25
26
27
28
29

Voltage )
title ( Analog Waveform )
//
figure
a = gca () ;
a . data_bounds = [0 ,0;21 ,5];
plot2d2 ([1: length ( dig_data ) ] , dig_data ,5)
title ( D i g i t a l R e p r e s e n t a t i o n )

Chapter 2
Fundamental Limit on
Performance

Scilab code Exa 2.1 Entropy of Binary Memoryless source


1 // c l e a r //
2 // 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
3 // Example 2 . 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
4 // p a g e 18
5 clear ;
6 close ;
7 clc ;
8 Po = 0:0.01:1;
9 H_Po = zeros (1 , length ( Po ) ) ;
10 for i = 2: length ( Po ) -1
11
H_Po ( i ) = - Po ( i ) * log2 ( Po ( i ) ) -(1 - Po ( i ) ) * log2 (1 - Po ( i

));
12 end
13 // p l o t
14 plot2d ( Po , H_Po )
15 xlabel ( Symbol P r o b a b i l i t y , Po )
16 ylabel ( H( Po ) )
17 title ( Entropy f u n c t i o n H( Po ) )
18 plot2d3 ( gnn ,0.5 ,1)

Scilab code Exa 2.2 Second order Extension of Discrete Memoryless Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20

// c l e a r //
// 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 . 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 ;
clc ;
P0 = 1/4; // 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; // 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; // 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 ) ;
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 , 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 , P0 * P1 , P0 * P2 , P1 * P0 , P1 * P1 , P1 * P2 , P2 * P0
, P2 * P1 , P2 * P2 ];
disp ( T a b l e 2 . 1 A l p h a b e t P a r t i c u l a r s o f Secondo 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 , P r o b a b i l i t y p ( s i g m a ) , i = 0 , 1 . . . . . 8 )
disp (

)
21 disp (
)
22 H_Ruo_Square =0;
23 for i = 1: length ( P_sigma )
9

24

H_Ruo_Square = H_Ruo_Square + P_sigma ( i ) * log2 (1/


P_sigma ( i ) ) ;
25 end
26 disp ( b i t s , H_Ruo_Square , H( R u o S q u a r e )= )
27 disp ( H( R u o S q u a r e ) = 2H( Ruo ) )

Scilab code Exa 2.3 Entropy, Average length, 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

// c l e a r //
// C a p t i o n : Entropy , A v e r a g e l e n g t h , V a r i a n c e o f
Huffman E n c o d i n g
// Example 2 . 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 ;
clc ;
P0 = 0.4; // 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 e n g t h o f c o d e w o r d S0
P1 = 0.2; // 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;
// l e n g t h o f c o d e w o r d S1
P2 = 0.2; // p r o b i l i t y o f c o d e w o r d 1 1
L2 = 2;
// l e n g t h o f c o d e w o r d S2
P3 = 0.1; // p r o b i l i t y o f c o d e w o r d 0 1 0
L3 = 3;
// l e n g t h o f c o d e w o r d S3
P4 =0.1; // p r o b i l i t y o f c o d e w o r d 0 1 1
L4 = 3;
// 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 ;
H_Ruo = P0 * log2 (1/ P0 ) + P1 * log2 (1/ P1 ) + P2 * log2 (1/ P2 ) + P3
* log2 (1/ P3 ) + P4 * log2 (1/ P4 ) ;
disp ( b i t s ,L , A v e r a g e code word Length L )
disp ( b i t s , H_Ruo , 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 ,((L - H_Ruo ) / H_Ruo ) *100 , 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
10

)
23 sigma_1 = P0 *( L0 - L ) ^2+ P1 *( L1 - L ) ^2+ P2 *( L2 - L ) ^2+ P3 *( L3
- L ) ^2+ P4 *( L4 - L ) ^2;
24 disp ( sigma_1 , V a r i n a c e o f Huffman c o d e )

Scilab code Exa 2.4 Entropy, Average length, 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

// c l e a r //
// C a p t i o n : Entropy , A v e r a g e l e n g t h , V a r i a n c e o f
Huffman E n c o d i n g
// Example2 . 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 ;
clc ;
P0 = 0.4; // p r o b a b i l i t y o f c o d e w o r d 1
L0 = 1;
// l e n g t h o f c o d e w o r d S0
P1 = 0.2; // 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;
// l e n g t h o f c o d e w o r d S1
P2 = 0.2; // p r o b i l i t y o f c o d e w o r d 0 0 0
L2 = 3;
// l e n g t h o f c o d e w o r d S2
P3 = 0.1; // 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 S3
P4 =0.1; // 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;
// 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 ;
H_Ruo = P0 * log2 (1/ P0 ) + P1 * log2 (1/ P1 ) + P2 * log2 (1/ P2 ) + P3
* log2 (1/ P3 ) + P4 * log2 (1/ P4 ) ;
disp ( b i t s ,L , A v e r a g e code word Length L )
disp ( b i t s , H_Ruo , Entropy o f Huffman c o d i n g r e s u l t
H)
sigma_2 = P0 *( L0 - L ) ^2+ P1 *( L1 - L ) ^2+ P2 *( L2 - L ) ^2+ P3 *( L3
- L ) ^2+ P4 *( L4 - L ) ^2;
11

22

disp ( sigma_2 , V a r i n a c e o f Huffman c o d e )

Scilab code Exa 2.5 Binary Symmetric Channe


1 // c l e a r //
2 // C a p t i o n : B i n a r y Symmetric Channel
3 // Example2 . 5 : B i n a r y Symmetric Channel
4 clear ;
5 clc ;
6 close ;
7 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 n
8 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 )

transition probility
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 e n t= )
10 disp ( T r a n s i t i o n p r o b i l i t y )
11 disp ( pe , 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= )
9

Scilab code Exa 2.6 Channel Capacity of a Binary Symmetric Channel


1
2
3
4
5
6
7
8
9

// c l e a r //
// 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 . 6 : Channel C a p a c i t y o f B i n a r y Symmetri
Channel
clear ;
close ;
clc ;
p = 0:0.01:0.5;
for i =1: length ( p )
if ( i ~=1)
12

10
11
12
13
14
15
16
17
18
19
20

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


;
elseif ( i ==1)
C ( i ) =1;
elseif ( i == length ( p ) )
C ( i ) =0;
end
end
plot2d (p ,C ,5)
xlabel ( T r a n s i t i o n P r o b i l i t y , p )
ylabel ( Channel C a p a c i t y , C )
title ( F i g u r e 2 . 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.7 Significance of the Channel Coding theorem


1
2
3
4
5
6
7
8
9
10
11
12
13

// c l e a r //
// 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 . 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
// 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
clear ;
clc ;
close ;
p =10^ -2;
pe_1 = p ; // 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 c o d e r a t e
r = 1
pe_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 e
r a t e r =1/3
pe_5 = 10* p ^3*(1 - p ) ^2+5* p ^4*(1 - p ) + p ^5; // e r r o r f o r
c o d e r a t e r =1/5
pe_7 = ((7*6*5) /(1*2*3) ) * p ^4*(1 - p ) ^3+(42/2) * p ^5*(1 - p
) ^2+7* p ^6*(1 - p ) + p ^7; // e r r o r f o r c o d e r a t e r =1/7
r = [1 ,1/3 ,1/5 ,1/7];
13

14 pe = [ pe_1 , pe_3 , pe_5 , pe_7 ];


15 a = gca () ;
16 a . data_bounds =[0 ,0;1 ,0.01];
17 plot2d (r , pe ,5)
18 xlabel ( Code r a t e , r )
19 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 , Pe )
20 title ( F i g u r e 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
21
22
23
24

of the
channel coding theorem )
legend ( R e p e t i t i o n c o d e s )
xgrid (1)
disp ( T a b l e 2 . 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 )
disp (

)
25 disp (r , Code Rate , r =1/n ,pe , A v e r a g e P r o b i l i t y o f
E r r o r , Pe )
26 disp (
)

14

Chapter 3
Detection and Estimation

Scilab code Exa 3.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

// c l e a r //
// 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 GramSchmidt 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 ;
close ;
clc ;
T = 1;
t1 = 0:0.01: T /3;
t2 = 0:0.01:2* T /3;
t3 = T /3:0.01: T ;
t4 = 0:0.01: T ;
s1t = [0 , ones (1 , length ( t1 ) -2) ,0];
s2t = [0 , ones (1 , length ( t2 ) -2) ,0];
s3t = [0 , ones (1 , length ( t3 ) -2) ,0];
s4t = [0 , ones (1 , length ( t4 ) -2) ,0];
t5 = 0:0.01: T /3;
phi1t = sqrt (3/ T ) *[0 , ones (1 , length ( t5 ) -2) ,0];
t6 = T /3:0.01:2* T /3;
phi2t = sqrt (3/ T ) *[0 , ones (1 , length ( t6 ) -2) ,0];
15

21 t7 = 2* T /3:0.01: T ;
22 phi3t = sqrt (3/ T ) *[0 , ones (1 , length ( t7 ) -2) ,0];
23 //
24 figure
25 title ( F i g u r e 3 . 4 ( a ) S e t o f s i g n a l s t o be
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

orthonormalized )
subplot (4 ,1 ,1)
a = gca () ;
a . data_bounds = [0 ,0;2 ,2];
plot2d2 ( t1 , s1t ,5)
xlabel ( t )
ylabel ( s 1 ( t ) )
subplot (4 ,1 ,2)
a = gca () ;
a . data_bounds = [0 ,0;2 ,2];
plot2d2 ( t2 , s2t ,5)
xlabel ( t )
ylabel ( s 2 ( t ) )
subplot (4 ,1 ,3)
a = gca () ;
a . data_bounds = [0 ,0;2 ,2];
plot2d2 ( t3 , s3t ,5)
xlabel ( t )
ylabel ( s 3 ( t ) )
subplot (4 ,1 ,4)
a = gca () ;
a . data_bounds = [0 ,0;2 ,2];
plot2d2 ( t4 , s4t ,5)
xlabel ( t )
ylabel ( s 4 ( t ) )
//
figure
title ( F i g u r e 3 . 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 ,1 ,1)
a = gca () ;
a . data_bounds = [0 ,0;2 ,4];
plot2d2 ( t5 , phi1t ,5)
16

57
58
59
60
61
62
63
64
65
66
67
68
69
70

xlabel ( t )
ylabel ( p h i 1 ( t ) )
subplot (3 ,1 ,2)
a = gca () ;
a . data_bounds = [0 ,0;2 ,4];
plot2d2 ( t6 , phi2t ,5)
xlabel ( t )
ylabel ( p h i 2 ( t ) )
subplot (3 ,1 ,3)
a = gca () ;
a . data_bounds = [0 ,0;2 ,4];
plot2d2 ( t7 , phi3t ,5)
xlabel ( t )
ylabel ( p h i 3 ( t ) )

Scilab code Exa 3.2 M-ARY Signaling


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// c l e a r //
// C a p t i o n :MARY S i g n a l i n g
// Example3 . 2 : MARY 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 ;
close ;
clc ;
a =1; // a m p l i t u d e =1
T =1; // 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 ) ,( -1/2) * a * sqrt ( T ) ,(3/2) * a *
sqrt ( T ) ,(1/2) * a * sqrt ( T ) ];
a = gca () ;
a . data_bounds = [ -2 , -0.5;2 ,0.5]
plot2d ( Si1 ,[0 ,0 ,0 ,0] , -10)
xlabel ( p h i 1 ( t ) )
title ( F i g u r e 3 . 8 ( a ) S i g n a l c o n s t e l l a t i o n )
xgrid (1)
17

disp ( F i g u r e 3 . 8 ( b ) . 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 )
19 disp ( Loc . o f meg . 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) )
20 disp (
18

21
22
23
24
25
26

)
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 . 8 ( c ) . 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 (

01

01

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

Scilab code Exa 3.3 Matched Filter output for RF pulse


1
2
3
4
5
6
7
8
9
10
11
12

// c l e a r //
// 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 . 3 : MATCHED FILTER FOR RF PULSE
clear ;
close ;
clc ;
fc =4; // c a r r i e r f r e q u e n c y i n Hz
T =1;
t1 = 0:0.01: T ;
phit = sqrt (2/ T ) * cos (2* %pi * fc * t1 ) ;
hopt = phit ;
phiot = convol ( phit , hopt ) ;
18

13
14
15
16
17
18
19
20
21

phiot = phiot / max ( phiot ) ;


t2 = 0:0.01:2* T ;
subplot (2 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -1;1 ,1];
plot2d ( t1 , phit ) ;
xlabel (

t )
22 ylabel (

23
24
25
26
27
28
29
30

phi ( t ) )
title ( F i g u r e 3 . 1 3 ( a ) RF p u l s e i n p u t )
subplot (2 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -1;1 ,1];
plot2d ( t2 , phiot ) ;
xlabel (

t )
31 ylabel (

32

phi0 ( 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.4 Matched Filter output for Noise-like signal
// c l e a r //
// 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
3 // Example3 . 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
2

19

4
5
6
7
8
9
10
11
12
13
14
15
16
17

input
clear ;
close ;
clc ;
phit =0.1* rand (1 ,10 , u n i f o r m ) ;
hopt = phit ;
phi0t = convol ( phit , hopt ) ;
phi0t = phi0t / max ( phi0t ) ;
subplot (2 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -1;1 ,1];
plot2d ([1: length ( phit ) ] , phit ) ;
xlabel (

18

t )
ylabel (

19
20
21
22
23
24
25
26

phi ( t ) )
title ( F i g u r e 3 . 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 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -1;1 ,1];
plot2d ([1: length ( phi0t ) ] , phi0t ) ;
xlabel (

27

t )
ylabel (

28

phi0 ( t ) )
title ( F i g u r e 3 . 1 6 ( b ) Matched F i l t e r o u t p u t )

20

Scilab code Exa 3.6 Linear Predictor of Order one


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// c l e a r //
// 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 . 6 : LINEAR PREDICTION : P r e d i c t o r o f Order
One
clear ;
close ;
clc ;
Rxx = [0.6 1 0.6];
h01 = Rxx (3) / Rxx (2) ; // Rxx ( 2 ) = Rxx ( 0 ) , Rxx ( 3 ) =
Rxx ( 1 )
sigma_E = Rxx (2) - h01 * Rxx (3) ;
sigma_X = Rxx (2) ;
disp ( sigma_E , 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 , 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 Exa 3.29 Implementation of LMS ADAPTIVE FILTER


1
2
3
4
5
6
7
8
9
10
11
12

// c l e a r //
// 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 ;
clc ;
close ;
order = 18;
t =0:0.01:1;
x = sin (2* %pi *5* t ) ;
noise = rand (1 , length ( x ) ) ;
x_n = x + noise ;
ref_noise = noise * rand (10) ;
21

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

w = zeros ( order ,1) ;


mu = 0.01*( sum ( x .^2) / length ( x ) ) ;
N = length ( x ) ;
for k =1:1010
for i = 1: N - order -1
buffer = ref_noise ( i : i + order -1) ;
desired ( i ) = x_n ( i ) - buffer * w ;
w = w +( buffer * mu * desired ( i ) ) ;
end
end
subplot (4 ,1 ,1)
plot2d (t , x )
title ( O r i g n a l I n p u t S i g n a l )
subplot (4 ,1 ,2)
plot2d (t , noise ,2)
title ( random n o i s e )
subplot (4 ,1 ,3)
plot2d (t , x_n ,5)
title ( S i g n a l+n o i s e )
subplot (4 ,1 ,4)
plot ( desired )
title ( n o i s e removed s i g n a l )

22

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

// c l e a r //
// 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 )
23

19
20
21
22
23
24
25
26
27
28
29

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)
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 Equalizer to compensate Aperture effect


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// c l e a r //
// 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
// Example4 . 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 ;
close ;
T_Ts = 0.01:0.01:0.6;
//E = 1 / ( s i n c n e w ( 0 . 5 T Ts ) ) ;
E (1) =1;
for i = 2: length ( T_Ts )
E ( i ) = (( %pi /2) * T_Ts ( i ) ) /( sin (( %pi /2) * T_Ts ( i ) ) ) ;
end
a = gca () ;
a . data_bounds = [0 ,0.8;0.8 ,1.2];
plot2d ( T_Ts ,E ,5)
xlabel ( Duty c y c l e T/ Ts )
ylabel ( 1/ s i n c ( 0 . 5 ( T/ Ts ) ) )
title ( F i g u r e 4 . 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 )

24

Chapter 5
Waveform Coding Techniques

Scilab code Exa 5.1 Average Transmitted Power for PCM


1 // c l e a r //
2 // 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
3 // Example5 . 1 : A v e r a g e T r a n s m i t t e d Power o f PCM
4 // Page 187
5 clear ;
6 clc ;
7 sigma_N = input ( E n t e r t h e n o i s e v a r i a n c e ) ;
8 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
9
10
11
12
13
14
15
16
17

s i g n a l i n g );
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;
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 . 0 0 0 0 1 2 2
25

Scilab code Exa 5.2 Comparison of M-ary PCM with ideal system
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 l e a r //
// C a p t i o n : Comparison o f Ma r y PCM w i t h i d e a l s y s t e m
( Channel C a p a c i t y Theorem )
// Example5 . 2 : Comparison o f Ma r y PCM s y s t e m
// Channel C a p a c i t y t h e o r e m
clear ;
close ;
clc ;
P_NoB_dB = [ -20:30]; // I n p u 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
P_NoB = 10^( P_NoB_dB /10) ;
k =7; // f o r Ma r y PCM s y s t e m ;
Rb_B = log2 (1+(12/ k ^2) * P_NoB ) ; // 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 ) ; // 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 () ;
a . data_bounds = [ -30 ,0;40 ,10];
plot2d ( P_NoB_dB , C_B ,5)
plot2d ( P_NoB_dB , Rb_B ,5)
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
poly1 . line_style = 4;
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 , d e c i b e l s
)
ylabel ( Bandwidth e f f i c i e n c y , Rb/B , b i t s p e r s e c o n d
per hertz )
title ( F i g u r e 5 . 9 Comparison o f Ma r y PCM w i t h t h e
i d e a l ssytem )
legend ([ I d e a l System , PCM ])

26

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


1 // c l e a r //
2 // 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
3 // Example5 . 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
4 // Channel Bandwidth B
5 clear ;
6 clc ;
7 n = input ( E n t e r no . o f b i t s u s e d t o e n c o d e : )
8 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 :
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

)
B = n*W;
disp (B , Channel w i d t h i n Hz : )
SNRo = 6* n - 7.2;
disp ( SNRo , Output S i g n a l t o n o i s e r a t i o i n dB : )
// R e s u l t 1 i f n = 8 b i t s
// E n t e r no . o f b i t s u s e d t o e n c o d e : 8
// 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
// Channel w i d t h i n Hz :
32000.
// Output S i g n a l t o n o i s e r a t i o i n dB : 4 0 . 8
// / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
// R e s u l t 2 i f n = 9 b i t s
// E n t e r no . o f b i t s u s e d t o e n c o d e : 9
// 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
// Channel w i d t h i n Hz : 3 6 0 0 0 .
// Output S i g n a l t o n o i s e r a t i o i n dB : 4 6 . 8
// / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
// 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
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 .

27

Scilab code Exa 5.5 Delta Modulation - to avoid slope overload distortion
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 l e a r //
// 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 ;
clc ;
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
: );
f0 = input ( 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 : ) ;
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 : );
Ts = 1/ fs ; // S a m p l i n g i n t e r v a l
delta = 2* %pi * f0 * a0 * Ts ; // S t e p s i z e t o a v o i d 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
//
28

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

// 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
28 // 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
29 //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
30 //
//////////////////////////////////////////////////////////////////
25
26
27

// 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
32 // 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
31

Scilab code Exa 05.13 A-law companding


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// c l e a r //
// C a p t i o n : Alaw companding
// F i g u r e 5 . 1 3 ( b )Alaw companding , N o n l i n e a r
Quantization
// P l o t t i n g Alaw 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 )
[ Cx (i ,:) , Xmax ( i ) ] = Alaw (x , A ( 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 : ALaw companding ,
29

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 ) | )
;
16 legend ([ A =1 ] ,[ A=2 ] ,[ A= 8 7 . 5 6 ])

Scilab code Exa 5.13 u-Law companding


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16

// c l e a r //
// C a p t i o n : uLaw 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 : uLaw 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 ])

30

Chapter 6
Baseband Shaping for Data
Transmission

Scilab code Exa 06.01 Nonreturn-to-zero bipolar format


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// c l e a r //
// 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 . 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 ] . B i P o l a r NRZ
// p a g e 235
clear ;
close ;
clc ;
x = [0 1 1 0 0 1 0 0 1 1];
binary_negative = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];
binary_zero = [0 0 0 0 0 0 0 0 0 0];
binary_positive = [1 1 1 1 1 1 1 1 1 1];
L = length ( x ) ;
L1 = length ( binary_negative ) ;
total_duration = L * L1 ;
// p l o t t i n g
a = gca () ;
a . data_bounds =[0 -2; L * L1 2];
for i =1: L
31

20
if ( x ( i ) ==0)
21
plot ([ i *L - L +1: i * L ] , binary_zero ) ;
22
poly1 = a . children (1) . children (1) ;
23
poly1 . thickness =3;
24
elseif (( x ( i ) ==1) &( x (i -1) ~=1) )
25
plot ([ i *L - L +1: i * L ] , binary_positive ) ;
26
poly1 = a . children (1) . children (1) ;
27
poly1 . thickness =3;
28
else
29
plot ([ i *L - L +1: i * L ] , binary_negative ) ;
30
poly1 = a . children (1) . children (1) ;
31
poly1 . thickness =3;
32
end
33 end
34 xgrid (1)
35 title ( B i P o l a r NRZ )

Scilab code Exa 06.1 Nonreturn-to-zero polar format


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// c l e a r //
// 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
// F i g u r e 6 . 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 ] . P o l a r NRZ
// p a g e 235
clear ;
close ;
clc ;
x = [0 1 0 0 0 1 0 0 1 1];
binary_negative = [ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1];
binary_positive = [1 1 1 1 1 1 1 1 1 1];
L = length ( x ) ;
L1 = length ( binary_negative ) ;
total_duration = L * L1 ;
// p l o t t i n g
a = gca () ;
32

17 a . data_bounds =[0 -2; L * L1 2];


18 for i =1: L
19
if ( x ( i ) ==0)
20
plot ([ i *L - L +1: i * L ] , binary_negative ) ;
21
poly1 = a . children (1) . children (1) ;
22
poly1 . thickness =3;
23
else
24
plot ([ i *L - L +1: i * L ] , binary_positive ) ;
25
poly1 = a . children (1) . children (1) ;
26
poly1 . thickness =3;
27
end
28 end
29 xgrid (1)
30 title ( P o l a r NRZ )

Scilab code Exa 6.01 Nonreturn-to-zero unipolar format


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// c l e a r //
// 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 . 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 ] . U n i p o l a r NRZ
// p a g e 235
clear ;
close ;
clc ;
x = [0 1 0 0 0 1 0 0 1 1];
binary_zero = [0 0 0 0 0 0 0 0 0 0];
binary_one = [1 1 1 1 1 1 1 1 1 1];
L = length ( x ) ;
L1 = length ( binary_zero ) ;
total_duration = L * L ;
// p l o t t i n g
a = gca () ;
a . data_bounds =[0 -2; L * L1 2];
for i =1: L
33

19
if ( x ( i ) ==0)
20
plot ([ i *L - L +1: i * L ] , binary_zero ) ;
21
poly1 = a . children (1) . children (1) ;
22
poly1 . thickness =3;
23
else
24
plot ([ i *L - L +1: i * L ] , binary_one ) ;
25
poly1 = a . children (1) . children (1) ;
26
poly1 . thickness =3;
27
end
28 end
29 xgrid (1)
30 title ( U n i p o l a r NRZ )

Scilab code Exa 6.1 Bandwidth Requirements of the T1 carrier


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// c l e a r //
// 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 . 1 : Bandwidth R e q u i r e m e n t s o f t h e T1
Carrier
// Page 251
clear ;
clc ;
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 ) ; // 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; // c o s i n e r o l l o f f f a c t o r
f1 = Bo *(1 - alpha ) ;
B = 2* Bo - f1 ;
disp (B , 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
34

:0.64710 6
16 // 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 : 1 5 4 5 5 9 5 . 1

Scilab code Exa 6.2 Frequency response of modified duobinary conversion


filter
1 // c l e a r //
2 // C a p t i o n : D u o b i n a r y E n c o d i n g
3 // Example6 . 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
4 // Page 256
5 clc ;
6 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 r
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

input
a (1) = xor (1 , b (1) ) ;
if ( a (1) ==1)
a_volts (1) = 1;
end
for k =2: length ( b )
a ( k ) = xor ( a (k -1) ,b ( k ) ) ;
if ( a ( k ) ==1)
a_volts ( k ) =1;
else
a_volts ( k ) = -1;
end
end
a = a ;
a_volts = a_volts ;
disp (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 , 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) ;
for k =2: length ( a )
c ( k ) = a_volts (k -1) + a_volts ( k ) ;
end
35

28 c = c ;
29 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 : )
30 // 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
31 for k =1: length ( c )
32
if ( abs ( c ( k ) ) >1)
33
b_r ( k ) = 0;
34
else
35
b_r ( k ) = 1;
36
end
37 end
38 b_r = b_r ;
39 disp ( b_r , R e c o v e r e d
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

o r i g i n a l sequence at 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 :
//
// 1 .
1.
0.
0.
1.
//
// P r e c o d e r o u t p u t i n v o l t s :
//
// 1 .
1. 1. 1.
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 .
2.
0. 2.
0.
//
// 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 .
0.
1.
0.
1.

0.

0.

1.

1.

:
0.

2.

d e t e c t o r oupupt :
1.

0.

Scilab code Exa 6.3 Generation of bipolar output for duobinary coder
1
2

// c l e a r //
// 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
36

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

coder
// Example6 . 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 . 4
clc ;
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 :
precoder input
y (1) = 1;
for k =2: length ( x ) +1
y ( k ) = xor ( x (k -1) ,y (k -1) ) ;
end
y_delay = y (1: $ -1) ;
y = y ;
y_delay = y_delay ;
disp (y , Modulo 2 a d d e r o u t p u t : )
disp ( y_delay , 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) - y_delay ( k ) ;
end
z = z ;
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
: )
// R e s u l t
// Modulo 2 a d d e r o u t p u t :
//
1.
1.
0.
1.
1.
0.
0.
0.
0.
1.
0.
// D e l a y e l e m e n t o u t p u t :
//
1.
1.
0.
1.
1.
0.
0.
0.
0.
1.
// 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. 1.
1.
0. 1.
0.
0.
0.
1. 1.

Scilab code Exa 6.4 Power Spectra of different binary data formats
37

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

// c l e a r //
// 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 . 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 ] . NRZ P o l a r Format [ 2 ] . NRZ B i p o l a r f o r m a t
// [ 3 ] . NRZ U n i p o l a r f o r m a t [ 4 ] . M a n c h e s t e r f o r m a t
// Page 241
close ;
clc ;
// [ 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 : ) ;
fb = input ( E n t e r t h e b i t r a t e : ) ;
Tb = 1/ fb ; // b i t d u r a t i o n
f = 0:1/(100* Tb ) :2/ Tb ;
for i = 1: length ( f )
Sxxf_NRZ_P ( i ) = ( a ^2) * Tb *( sinc_new ( f ( i ) * Tb ) ^2) ;
Sxxf_NRZ_BP ( i ) = ( a ^2) * Tb *(( sinc_new ( f ( i ) * Tb ) ) ^2)
*(( sin ( %pi * f ( i ) * Tb ) ) ^2) ;
if ( i ==1)
Sxxf_NRZ_UP ( i ) = ( a ^2) *( Tb /4) *(( sinc_new ( f ( i ) * Tb
) ) ^2) +( a ^2) /4;
else
Sxxf_NRZ_UP ( i ) = ( a ^2) *( Tb /4) *(( sinc_new ( f ( i ) * Tb
) ) ^2) ;
end
Sxxf_Manch ( i ) = ( a ^2) * Tb *( sinc_new ( f ( i ) * Tb /2) ^2) *(
sin ( %pi * f ( i ) * Tb /2) ^2) ;
end
// P l o t t i n g
a = gca () ;
plot2d (f , Sxxf_NRZ_P )
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
plot2d (f , Sxxf_NRZ_BP ,2)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
plot2d (f , Sxxf_NRZ_UP ,5)
38

34
35
36
37
38
39
40
41
42
43
44
45
46

poly1 = a . children (1) . children (1) ;


poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
plot2d (f , Sxxf_Manch ,9)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
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 B i p o l a r f o r m a t , NRZ
U n i p o l a r f o r m a t , M a n c h e s t e r f o r m a t ]) ;
// 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 Exa 6.6 Ideal solution for zero ISI


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// c l e a r //
// 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 . 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
// SINC p u l s e
// p a g e 249
rb = input ( E n t e r t h e b i t r a t e : ) ;
Bo = rb /2;
t = -3:1/100:3;
x = sinc_new (2* Bo * t ) ;
plot (t , x )
xlabel ( t> ) ;
ylabel ( p ( t )> ) ;
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
39

Scilab code Exa 6.7 Practical solution: Raised Cosine


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

// c l e a r //
// 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 . 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 ;
clc ;
rb = input ( E n t e r t h e b i t r a t e : ) ;
Tb =1/ rb ;
t = -3:1/100:3;
Bo = rb /2;
Alpha =0;
// I n t i a l i z e d t o z e r o
x = t / Tb ;
for j =1:3
for i =1: length ( t )
if (( j ==3) &(( t ( i ) ==0.5) |( t ( i ) == -0.5) ) )
p (j , i ) = sinc_new (2* Bo * t ( i ) ) ;
else
num = sinc_new (2* Bo * t ( i ) ) * cos (2* %pi * Alpha *
Bo * t ( i ) ) ;
den =
1 -16*( Alpha ^2) *( Bo ^2) *( t ( i ) ^2) +0.01;
p (j , i ) = num / den ;
end
end
Alpha = Alpha +0.5;
end
a = gca () ;
plot2d (t , p (1 ,:) )
plot2d (t , p (2 ,:) )
poly1 = a . children (1) . children (1) ;
poly1 . foreground =2;
40

31
32
33
34
35
36
37
38
39
40
41

plot2d (t , p (3 ,:) )
poly2 = a . children (1) . children (1) ;
po1y2 . foreground =4;
poly2 . line_style = 3;
xlabel ( t /Tb> ) ;
ylabel ( p ( t )> ) ;
title ( RAISED COSINE SPECTRUM P r a c t i c a l S o l u t i o n
for ISI )
legend ([ 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 o r =0.5 ,
R O l l o f f F a c t o r =1 ])
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 Exa 6.9 Frequency response of duobinary conversion filte


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// c l e a r //
// 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 . 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 ;
close ;
clc ;
rb = input ( E n t e r t h e b i t r a t e= ) ;
Tb =1/ rb ; // B i t d u r a t i o n
f = - rb /2:1/100: rb /2;
Amplitude_Response = abs (2* cos ( %pi * f .* Tb ) ) ;
Phase_Response = -( %pi * f .* Tb ) ;
subplot (2 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
41

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

a . y_location = o r i g i n ;
plot2d (f , Amplitude_Response ,2)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
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 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d (f , Phase_Response ,5)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
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 Exa 6.15 Frequency response of modified duobinary conversion filter
1
2
3
4
5
6
7
8

// c l e a r //
// 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
// F i g u r e 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
// ( 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
// p a g e 259
clear ;
close ;
42

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

clc ;
rb = input ( E n t e r t h e b i t r a t e= ) ;
Tb =1/ rb ; // B i t d u r a t i o n
f = - rb /2:1/100: rb /2;
Amplitude_Response = abs (2* sin (2* %pi * f .* Tb ) ) ;
Phase_Response = -(2* %pi * f .* Tb ) ;
subplot (2 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d (f , Amplitude_Response ,2)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
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 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d (f , Phase_Response ,5)
poly1 = a . children (1) . children (1) ;
poly1 . thickness = 2; // t h e t i c k n e s s o f a c u r v e .
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

43

Chapter 7
Digital Modulation Techniques

Scilab code Exa 7.01 Waveforms of Different Digital Modulation techniques


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// c l e a r //
// 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
// F i g u r e 7 . 1
// 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
//To P l o t t h e ASK, FSK and PSk Waveforms
clear ;
clc ;
close ;
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
);
t = 0:1/512:1;
x = sin (2* %pi * f * t ) ;
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 ) ;
// G e n e r a t i o n o f ASK Waveform
Xask = [];
for n = 1: length ( I )
if (( I ( n ) ==1) &( n ==1) )
Xask = [x , Xask ];
elseif (( I ( n ) ==0) &( n ==1) )
Xask = [ zeros (1 , length ( x ) ) , Xask ];
44

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

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


Xask = [ Xask , x ];
elseif (( I ( n ) ==0) &( n ~=1) )
Xask = [ Xask , zeros (1 , length ( x ) ) ];
end
end
// G e n e r a t i o n o f FSK Waveform
Xfsk = [];
x1 = sin (2* %pi * f * t ) ;
x2 = sin (2* %pi *(2* f ) * t ) ;
for n = 1: length ( I )
if ( I ( n ) ==1)
Xfsk = [ Xfsk , x2 ];
elseif ( I ( n ) ~=1)
Xfsk = [ Xfsk , x1 ];
end
end
// G e n e r a t i o n o f PSK Waveform
Xpsk = [];
x1 = sin (2* %pi * f * t ) ;
x2 = - sin (2* %pi * f * t ) ;
for n = 1: length ( I )
if ( I ( n ) ==1)
Xpsk = [ Xpsk , x1 ];
elseif ( I ( n ) ~=1)
Xpsk = [ Xpsk , x2 ];
end
end
figure
plot (t , x )
xtitle ( Analog C a r r i e r S i g n a l f o r D i g i t a l M o d u l a t i o n
)
xgrid
figure
plot ( Xask )
xtitle ( A m p l i t u d e S h i f t Keying )
xgrid
figure
45

57
58
59
60
61
62
63
64
65
66

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 , 1 , 1 , 0 , 1 , 0 , 0 , 1 ]

Scilab code Exa 7.1 Waveforms of Different Digital Modulation techniques


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// c l e a r //
// 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 . 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 ;
clc ;
close ;
M =4;
i = 1: M ;
t = 0:0.001:1;
for i = 1: M
s1 (i ,:) = cos (2* %pi *2* t ) * cos ((2* i -1) * %pi /4) ;
s2 (i ,:) = - sin (2* %pi *2* t ) * sin ((2* i -1) * %pi /4) ;
end
S1 =[];
S2 = [];
S = [];
Input_Sequence =[0 ,1 ,1 ,0 ,1 ,0 ,0 ,0];
m = [3 ,1 ,1 ,2];
for i =1: length ( m )
S1 = [ S1 s1 ( m ( i ) ,:) ];
46

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54

S2 = [ S2 s2 ( m ( i ) ,:) ];
end
S = S1 + S2 ;
figure
subplot (3 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
plot ( S1 )
title ( B i n a r y PSK wave o f Oddnumbered b i t s o f i n p u t
sequence )
subplot (3 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
plot ( S2 )
title ( B i n a r y PSK wave o f Evennumbered b i t s o f
input sequence )
subplot (3 ,1 ,3)
a = gca () ;
a . x_location = o r i g i n ;
plot ( S )
title ( QPSK waveform )
// s i n ( ( 2 i 1) %pi / 4 ) %i ;
// a n n o t = d e c 2 b i n ( [ 0 : l e n g t h ( y ) 1] , l o g 2 (M) ) ;
// d i s p ( y , 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 , d i b i t s v a l u e )
// f i g u r e ;
// a =g c a ( ) ;
// a . d a t a b o u n d s = [ 1 , 1 ; 1 , 1 ] ;
// a . x l o c a t i o n = o r i g i n ;
// a . y l o c a t i o n = o r i g i n ;
// p l o t 2 d ( r e a l ( y ( 1 ) ) , imag ( y ( 1 ) ) , 2)
// p l o t 2 d ( r e a l ( y ( 2 ) ) , imag ( y ( 2 ) ) , 4)
// p l o t 2 d ( r e a l ( y ( 3 ) ) , imag ( y ( 3 ) ) , 5)
// p l o t 2 d ( r e a l ( y ( 4 ) ) , imag ( y ( 4 ) ) , 9)
// x l a b e l (
In
Phase ) ;
// y l a b e l (
47

55
56

Quadrature ) ;
// 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 ) ; m e s s a g e
p o i nt 2 ( d i b i t 00) ; message p o i nt 3 ( d i b i t 01)
; message p o in t 4 ( d i b i t 11) ] , 5 )

Scilab code Exa 7.02 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
20

// c l e a r //
// 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 . 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 ;
close ;
M =2;
i = 1: M ;
y = cos (2* %pi +( i -1) * %pi ) ;
annot = dec2bin ([ length ( y ) -1: -1:0] , log2 ( M ) ) ;
disp (y , 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 , Mes sa ge p o i n t s )
figure ;
a = gca () ;
a . data_bounds = [ -2 , -2;2 ,2];
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( real ( y (1) ) , imag ( y (1) ) , -9)
plot2d ( real ( y (2) ) , imag ( y (2) ) , -5)
xlabel (

InPhase ) ;
21 ylabel (
Quadrature );
48

22
23

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 ) ; m e s s a g e p o i n t
2 ( b i n a r y 0 ) ] ,5)

Scilab code Exa 7.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
20
21
22
23
24
25
26
27
28
29

// c l e a r //
// 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 . 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 ;
close ;
M =2;
Tb =1;
t1 = - Tb :0.01: Tb ;
t2 = 0:0.01:2* Tb ;
phi1 = cos (2* %pi * t1 ) .* cos (( %pi /(2* Tb ) ) * t1 ) ;
phi2 = sin (2* %pi * t2 ) .* sin (( %pi /(2* Tb ) ) * t2 ) ;
teta_0 = [0 , %pi ];
teta_tb = [ %pi /2 , - %pi /2];
S1 = [];
S2 = [];
for i = 1: M
s1 ( i ) = cos ( teta_0 ( i ) ) ;
s2 ( i ) = - sin ( teta_tb ( i ) ) ;
S1 = [ S1 s1 ( i ) * phi1 ];
S2 = [ S2 s2 (1) * phi2 ];
end
for i = M : -1:1
S1 = [ S1 s1 ( i ) * phi1 ];
S2 = [ S2 s2 (2) * phi2 ];
end
Input_Sequence =[1 ,1 ,0 ,1 ,0 ,0 ,0];
S = [];
49

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

t
S
S
S

= 0:0.01:1;
= [ S cos (0) * cos (2* %pi * t ) - sin ( %pi /2) * sin (2* %pi * t ) ];
= [ S cos (0) * cos (2* %pi * t ) - sin ( %pi /2) * sin (2* %pi * t ) ];
= [ S cos ( %pi ) * cos (2* %pi * t ) - sin ( %pi /2) * sin (2* %pi * t )
];
S = [ S cos ( %pi ) * cos (2* %pi * t ) - sin ( - %pi /2) * sin (2* %pi * t
) ];
S = [ S cos (0) * cos (2* %pi * t ) - sin ( - %pi /2) * sin (2* %pi * t )
];
S = [ S cos (0) * cos (2* %pi * t ) - sin ( - %pi /2) * sin (2* %pi * t )
];
S = [ S cos (0) * cos (2* %pi * t ) - sin ( - %pi /2) * sin (2* %pi * t )
];
y = [ s1 (1) , s2 (1) ; s1 (2) , s2 (1) ; s1 (2) , s2 (2) ; s1 (1) , s2 (2)
];
disp (y , 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 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
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 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
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 ,1 ,3)
a = gca () ;
a . 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 byb i t b a s i s )

Scilab code Exa 7.3 Illustrating the generation of DPSK signal


50

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 l e a r //
// 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
// T a b l e 7 . 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 ;
bk = [1 ,0 ,0 ,1 ,0 ,0 ,1 ,1]; // 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;
else
bk_not ( i ) = 1;
end
end
dk_1 (1) = 1& bk (1) ; // 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) ;
dk (1) = xor ( dk_1 (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_1_not ( i ) = ~ dk (i -1) ;
dk ( i ) = xor (( dk_1 ( i ) & bk ( i ) ) ,( dk_1_not ( i ) & bk_not ( i )
));
end
for i =1: length ( dk )
if ( dk ( i ) ==1)
dk_radians ( i ) =0;
elseif ( dk ( i ) ==0)
dk_radians ( i ) = %pi ;
end
end
disp ( T a b l e 7 . 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 (

)
30 disp ( bk , ( bk ) )
31 bk_not = bk_not ;
51

32 disp ( bk_not , ( b k n o t ) )
33 dk = dk ;
34 disp ( dk , 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 ) )
35 dk_radians = dk_radians ;
36 disp ( dk_radians , 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 )
37 disp (

Scilab code Exa 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
19

// c l e a r //
// 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 . 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 ;
close ;
M =2;
y = [1 ,0;0 ,1];
annot = dec2bin ([ M -1: -1:0] , log2 ( M ) ) ;
disp (y , 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 , Mes sa ge p o i n t s )
figure ;
a = gca () ;
a . data_bounds = [ -2 , -2;2 ,2];
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( y (1 ,1) ,y (1 ,2) , -9)
plot2d ( y (2 ,1) ,y (2 ,2) , -5)
xlabel (

InPhase ) ;
20 ylabel (

52

Quadrature );
21 title ( C o n s t e l l a t i o n f o r BFSK )
22 legend ([ m e s s a g e p o i n t 1 ( b i n a r y 1 ) ; m e s s a g e p o i n t
2 ( b i n a r y 0 ) ] ,5)

Scilab code Exa 7.4.7.20 Comparison of error probability


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

// c l e a r //
// C a p t i o n : Comparison o f e r r o r p r o b a b i l i t y o f
d i f f e r e n t data t r a n s m i s s i o n schemes
// T a b l e 7 . 4 : F i g u r e 7 . 2 0
// Comparison o f Symbol E r r o r P r o b a b i l i t y
// o f D i f f e r e n t D i g i t a l T r a n s m i s s i o n System
clear ;
close ;
clc ;
//Eb = Energy o f t h e b i t No = N o i s e S p e c t r a l
Density
Eb_No =[18 ,0.3162278];
x = Eb_No (2) :1/100: Eb_No (1) ;
x_dB = 10* log10 ( x ) ;
for i = 1: length ( x )
// E r r o r P r o b a b i l i t y o f C o h e r e n t BPSK
Pe_BPSK ( i ) = (1/2) * erfc ( sqrt ( x ( i ) ) ) ;
// E r r o r P r o b a b i l i t y o f C o h e r e n t BFSK
Pe_BFSK ( i ) = (1/2) * erfc ( sqrt ( x ( i ) /2) ) ;
// E r r o r P r o b a b i l i t y NonC o h e r e n t PSK = DPSK
Pe_DPSK ( i ) = (1/2) * exp ( - x ( i ) ) ;
// E r r o r P r o b a b i l i t y NonC o h e r e n t FSK
Pe_NFSK ( i ) = (1/2) * exp ( -( x ( i ) /2) ) ;
// E r r o r P r o b a b i l i t y o f QPSK & MSK
Pe_QPSK_MSK ( i ) = erfc ( sqrt ( x ( i ) ) ) -((1/4) *( erfc (
sqrt ( x ( i ) ) ) ^2) ) ;
end
a = gca () ;
53

26 a . data_bounds =[ -5 ,0;12.5 ,0.5];


27 plot2d ( x_dB , Pe_BPSK )
28 plot2d ( x_dB , Pe_BFSK )
29 poly1 = a . children (1) . children (1) ;
30 poly1 . foreground = 3;
31 plot2d ( x_dB , Pe_DPSK )
32 poly1 = a . children (1) . children (1) ;
33 poly1 . foreground = 4;
34 plot2d ( x_dB , Pe_NFSK )
35 poly1 = a . children (1) . children (1) ;
36 poly1 . foreground = 6;
37 plot2d ( x_dB , Pe_QPSK_MSK )
38 poly1 = a . children (1) . children (1) ;
39 poly1 . foreground = 7;
40 xlabel ( Eb/No i n dB > )
41 ylabel ( P r o b a b i l i t y o f E r r o r Pe> )
42 title ( Comparison o f N o i s e P e r f o r m a n c e o f

different
PSK & FSK Scheme )
43 legend ([ BPSK , BFSK , DPSK , NonC o h e r e n t FSK ,
QPSK & MSK ])
44 xgrid (1)

Scilab code Exa 7.06 Bandwidth efficiency of M-ary PSK signals


1
2
3
4
5
6
7
8
9

// c l e a r //
// C a p t i o n : Bandwidth e f f i c i e n c y o f Ma r y PSK s i g n a l s
// T a b l e 7 . 6 : Bandwidth E f f i c i e n c y o f Ma r y PSK
signals
clear ;
clc ;
close ;
M = [2 ,4 ,8 ,16 ,32 ,64]; //Ma r y
Ruo = log2 ( M ) ./2; // 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 . 7 Bandwidth E f f i c i e n c y o f Ma r y PSK
54

signals )
10 disp (

11
12

)
disp (M , M )
disp (

)
13 disp ( Ruo , r i n b i t s / s /Hz )
14 disp (
)

Scilab code Exa 7.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

// c l e a r //
// 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 . 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 ;
close ;
M =4;
i = 1: M ;
y = cos ((2* i -1) * %pi /4) - sin ((2* i -1) * %pi /4) * %i ;
annot = dec2bin ([0: M -1] , log2 ( M ) ) ;
disp (y , 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 ;
a = gca () ;
a . data_bounds = [ -1 , -1;1 ,1];
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( real ( y (1) ) , imag ( y (1) ) , -2)
55

19
20
21
22

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


plot2d ( real ( y (3) ) , imag ( y (3) ) , -5)
plot2d ( real ( y (4) ) , imag ( y (4) ) , -9)
xlabel (
In

Phase ) ;
23 ylabel (

24
25

Quadrature );
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 ) ; m e s s a g e p o i n t
2 ( d i b i t 00) ; message p o i nt 3 ( d i b i t 01) ;
m e s s a g e p o i n t 4 ( d i b i t 1 1 ) ] ,5)

Scilab code Exa 7.7 Bandwidth efficiency of M-ary FSK signals


1 // c l e a r //
2 // C a p t i o n : Bandwidth e f f i c i e n c y o f Ma r y FSK s i g n a l s
3 // T a b l e 7 . 7 : Bandwidth E f f i c i e n c y o f Ma r y FSK
4 clear ;
5 clc ;
6 close ;
7 M = [2 ,4 ,8 ,16 ,32 ,64]; //Ma r y
8 Ruo = 2* log2 ( M ) ./ M ; // Bandwidth e f f i c i e n c y i n b i t s / s
9
10
11
12

/Hz
//M = M ;
// Ruo = Ruo ;
disp ( T a b l e 7 . 7 Bandwidth E f f i c i e n c y o f Ma r y FSK
signals )
disp (

)
13 disp (M , M )
14 disp (

56

)
15 disp ( Ruo , r i n b i t s / s /Hz )
16 disp (
)

Scilab code Exa 7.12.7.2 Signal space diagram for MSK diagram
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

// c l e a r //
// 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 MSK d i a g r a m
// F i g u r e 7 . 1 2 S i g n a l S p a c e Diagram f o r c o h e r e n t MSK
system
// 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 ;
close ;
M =2;
teta_0 = [0 , %pi ];
teta_tb = [ %pi /2 , - %pi /2];
for i = 1: M
s1 ( i ) = cos ( teta_0 ( i ) ) ;
s2 ( i ) = - sin ( teta_tb ( i ) ) ;
end
y = [ s1 (1) , s2 (1) ; s1 (2) , s2 (1) ; s1 (2) , s2 (2) ; s1 (1) , s2 (2)
];
disp (y , 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 ;
a = gca () ;
a . data_bounds = [ -2 , -2;2 ,2];
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( y (1 ,1) ,y (1 ,2) , -2)
plot2d ( y (2 ,1) ,y (2 ,2) , -4)
plot2d ( y (3 ,1) ,y (3 ,2) , -6)
plot2d ( y (4 ,1) ,y (4 ,2) , -9)
57

26

xlabel (

InPhase ) ;
27 ylabel (
Quadrature );
28 title ( C o n s t e l l a t i o n f o r MSK )
29 legend ([ m e s s a g e p o i n t 1 ( 0 , %pi / 2 ) ; m e s s a g e p o i n t
2 ( %pi , %pi / 2 ) ; m e s s a g e p o i n t 3 ( %pi , %pi / 2 )
; m e s s a g e p o i n t 4 ( 0 , %pi / 2 ) ] ,5)

Scilab code Exa 7.29 Power Spectra of BPSK and BFSK signals
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// c l e a r //
// 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 . 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 ;
rb = input ( E n t e r t h e b i t r a t e= ) ;
Eb = input ( E n t e r t h e e n e r g y o f t h e b i t= ) ;
f = 0:1/100:8/ rb ;
Tb = 1/ rb ; // 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 ) ;
else
SB_FSK ( i ) = (8* Eb *( cos ( %pi * f ( i ) * Tb ) ^2) ) /(( %pi
^2) *(((4*( Tb ^2) *( f ( i ) ^2) ) -1) ^2) ) ;
end
SB_PSK ( i ) =2* Eb *( sinc_new ( f ( i ) * Tb ) ^2) ;
end
a = gca () ;
plot ( f * Tb , SB_FSK /(2* Eb ) )
plot ( f * Tb , SB_PSK /(2* Eb ) )
58

21
22
23
24
25
26
27
28
29
30

poly1 = a . children (1) . children (1) ;


poly1 . foreground = 6;
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 , 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 Exa 7.30 Power Spectra of QPSK and MSK signals
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// c l e a r //
// 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 . 3 0 : Comparison o f QPSK and MSK Power
Spectrums
// c l e a r ;
// c l o s e ;
// c l c ;
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 : )
;
Eb = input ( E n t e r t h e Energy o f b i t : ) ;
f = 0:1/(100* rb ) :(4/ rb ) ;
Tb = 1/ rb ; // 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.5)
SB_MSK ( i ) = 4* Eb * f ( i ) ;
else
SB_MSK ( i ) = (32* Eb /( %pi ^2) ) *( cos (2* %pi * Tb * f ( i ) )
/((4* Tb * f ( i ) ) ^2 -1) ) ^2;
end
SB_QPSK ( i ) = 4* Eb * sinc_new ((2* Tb * f ( i ) ) ) ^2;
end
59

19 a = gca () ;
20 plot ( f * Tb , SB_MSK /(4* Eb ) ) ;
21 plot ( f * Tb , SB_QPSK /(4* Eb ) ) ;
22 poly1 = a . children (1) . children (1) ;
23 poly1 . foreground = 3;
24 xlabel ( N o r m a l i z e d F r e q u e n c y > )
25 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 > )
26 title ( QPSK Vs MSK Power S p e c t r a Comparison )
27 legend ([ Minimum S h i f t Keying , QPSK ])
28 xgrid (1)
29 // R e s u l t
30 // 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
31 // E n t e r t h e Energy o f b i t : 1

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// c l e a r //
// C a p t i o n : Power s p e c t r a o f Ma r y PSK s i g n a l s
// F i g u r e 7 . 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 Ma r y PSK s i g n a l s
rb = input ( E n t e r t h e b i t r a t e= ) ;
Eb = input ( E n t e r t h e e n e r g y o f t h e b i t= ) ;
f = 0:1/100: rb ;
Tb = 1/ rb ; // B i t d u r a t i o n
M = [2 ,4 ,8];
for j = 1: length ( M )
for i = 1: length ( f )
SB_PSK (j , i ) =2* Eb *( sinc_new ( f ( i ) * Tb * log2 ( M ( j ) ) )
^2) * log2 ( M ( j ) ) ;
end
end
a = gca () ;
plot2d ( f * Tb , SB_PSK (1 ,:) /(2* Eb ) )
plot2d ( f * Tb , SB_PSK (2 ,:) /(2* Eb ) ,2)
plot2d ( f * Tb , SB_PSK (3 ,:) /(2* Eb ) ,5)
60

18
19
20
21
22
23
24
25

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 Ma r y s i g n a l s f o r M = 2 , 4 , 8 )
legend ([ M=2 , M=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 Exa 7.41 Matched Filter output of rectangular pulse


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 l e a r //
// 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 . 4 1
// Matched F i l t e r Output
clear ;
clc ;
T =4;
a =2;
t = 0: T ;
g = 2* ones (1 , T +1) ;
h = abs ( convol (g , g ) ) ;
for i = 1: length ( h )
if ( h ( i ) <0.01)
h ( i ) =0;
end
end
h = h-T;
t1 = 0: length ( h ) -1;
figure
a = gca () ;
a . data_bounds = [0 ,0;6 ,4];
plot2d (t ,g ,5)
xlabel ( t> )
ylabel ( g ( t )> )
61

25
26
27
28
29
30

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 , a =2 )
figure
plot2d ( t1 ,h ,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 ) )

62

Chapter 8
Error Control Coding

Scilab code Exa 8.1 Repetition Codes


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// c l e a r //
// C a p t i o n : R e p e t i t i o n Codes
// Example8 . 1 : R e p e t i t i o n Codes
clear ;
clc ;
n =5; // b l o c k o f i d e n t i c a l n b i t s
k =1; // one b i t
m = 1; // b i t v a l u e = 1
I = eye (n -k ,n - k ) ; // I d e n t i t y m a t r i x
P = ones (1 ,n - k ) ; // c o e f f i c i e n t m a t r i x
H = [ I P ]; // p a r i t y c h e c k m a t r i x
G = [ P 1]; // g e n e r a t o r m a t r i x
x = m .* G ; // c o d e word
disp (G , g e n e r a t o r m a t r i x ) ;
disp (H , p a r i t y c h e c k m a t r i x ) ;
disp (x , c o d e word f o r b i n a r y one i n p u t ) ;

Scilab code Exa 8.2 Hamming Codes


63

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// c l e a r //
// C a p t i o n : Hamming Codes
// Example8 . 2 : Hamming c o d e s
clear ;
clc ;
k = 4; // m e s s a g e b i t s l e n g t h
n = 7; // b l o c k l e n g t h
m = n - k ; // Number o f p a r i t y b i t s
I = eye (k , k ) ; // i d e n t i t y m a t r i x
disp (I , i d e n t i t y m a t r i x I k )
P =[1 ,1 ,0;0 ,1 ,1;1 ,1 ,1;1 ,0 ,1]; // c o e f f i c i e n t m a t r i x
disp (P , c o e f f i c i e n t m a t r i x P )
G = [ P I ]; // g e n e r a t o r m a t r i x
disp (G , g e n e r a t o r m a t r i x G )
H = [ eye (k -1 ,k -1) P ]; // p a r i t y c h e c k m a t r i x
disp (H , 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 ,0 ,0;0 ,0 ,0 ,1;0 ,0 ,1 ,0;0 ,0 ,1 ,1;0 ,1 ,0 ,0;0 ,1 ,0 ,1;0 ,1 ,1 ,0;0 ,1 ,1 ,1;1

19 //
20 C = m * G ;
21 C = modulo (C ,2) ;
22 disp (C , Code words o f

( 7 , 4 ) Hamming c o d e )

Scilab code Exa 8.3 Hamming Codes Revisited


1 // c l e a r //
2 // C a p t i o n : Hamming Codes R e v i s i t e d
3 // Example8 . 3 : ( 7 , 4 ) Hamming Code R e v i s i t e d
4 // m e s s a g e s e q u e n c e = [ 1 , 0 , 0 , 1 ]
5 //D = p o l y ( 0 ,D) ;
6 clc ;
7 D = poly (0 , D ) ;
8 g = 1+ D +0+ D ^3; // g e n e r a t o r p o l y n o m i a l

64

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

m = ( D ^3) *(1+0+0+ D ^3) ; // m e s s a g e s e q u e n c e


[r , q ] = pdiv (m , g ) ;
p = coeff ( r ) ;
disp (r , r e m a i n d e r i n p o l y n o m i a l form )
disp (p , P a r i t y b i t s a r e : )
G = [ g ; g * D ; g * D ^2; g * D ^3];
G = coeff ( G ) ;
disp (G , G )
G (3 ,:) = G (3 ,:) + G (1 ,:) ;
G (3 ,:) = modulo ( G (3 ,:) ,2) ;
G (4 ,:) = G (1 ,:) + G (2 ,:) + G (4 ,:) ;
G (4 ,:) = modulo ( G (4 ,:) ,2) ;
disp (G , G e n e r a t o r M a t r i x G = )
h = 1+ D ^ -1+ D ^ -2+ D ^ -4;
H_D = [ D ^4* h ; D ^5* h ; D ^6* h ];
H_num = numer ( H_D ) ;
H = coeff ( H_num ) ;
H (1 ,:) = H (1 ,:) + H (3 ,:) ;
H (1 ,:) = modulo ( H (1 ,:) ,2) ;
disp (H , P a r t i y Check m a t r i x H = )

Scilab code Exa 8.4 Encoder for the (7,4) Cyclic Hamming Code
1
2
3
4
5
6
7
8
9
10
11

// c l e a r //
// C a p t i o n : E n c o d e r f o r t h e ( 7 , 4 ) C y c l i c Hamming Code
// Example8 . 4 : E n c o d e r f o r t h e ( 7 , 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 , 0 , 0 , 1 ]
//D = p o l y ( 0 ,D) ;
D = poly (0 , D ) ;
g = 1+ D +0+ D ^3; // 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) ; // m e s s a g e s e q u e n c e
[r , q ] = pdiv (m , g ) ;
p = coeff ( r ) ;
disp (r , r e m a i n d e r i n p o l y n o m i a l form )
65

disp (p , P a r i t y b i t s a r e : )
disp ( T a b l e 8 . 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 . 7 f o r Me ss age S e q u e n c e ( 1 0 0 1 )
)
14 disp (
12
13

)
disp ( S h i f t
Contents )
16 disp (
15

17
18
19
20
21

)
disp ( 1
disp ( 2
disp ( 3
disp ( 4
disp (

Input

1
0
0
1

Register

1
0
1
0

1
1
1
1

0 )
1 )
1 )
1 )

Scilab code Exa 8.5 syndrome calculator for the(7,4) Cyclic Hamming Code
1
2
3
4
5
6
7
8
9
10
11
12

// c l e a r //
// 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 , 4 ) C y c l i c
Hamming Code
// Example8 . 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 , 1 , 1 , 1 , 0 , 0 , 1 ]
clc ;
D = poly (0 , D ) ;
g = 1+ D +0+ D ^3; // 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; // 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; // m i d d l e b i t i s e r r o r
[ r1 , q1 ] = pdiv ( C1 , g ) ;
S1 = coeff ( r1 ) ;
S1 = modulo ( S1 ,2) ;
66

13
14
15
16
17
18
19

disp ( r1 , r e m a i n d e r i n
disp ( S1 , Syndrome b i t s
)
[ r2 , q2 ] = pdiv ( C2 , g ) ;
S2 = coeff ( r2 ) ;
S2 = modulo ( S2 ,2) ;
disp ( r2 , r e m a i n d e r i n
codeword )
disp ( S2 , Syndrome b i t s

p o l y n o m i a l form )
f o r e r r o r f r e e codeword a r e :

p o l y n o m i a l form f o r e r r o r e d
for errored

codeword a r e : )

Scilab code Exa 8.6 Reed-Solomon Codes


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// c l e a r //
// C a p t i o n : ReedSolomon Codes
// Example8 . 6 : ReedSolomon Codes
// 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
clc ;
m =2; //mb i t symbol
k = 1^2; // number o f m e s s a g e b i t s
t =1; // 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; // c o d e word l e n g t h i n 2 b i t b y t e
p = n - k ; // 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 ; // c o d e r a t e
disp (n , n )
disp (p , nk )
disp (r , Code r a t e : r = k / n = )
disp (2* t , I t can c o r r e c t any e r r o r u p t o = )

Scilab code Exa 8.7 Convolutional Encoding - Time domain approach


1
2

// c l e a r //
// 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
67

3 // Example8 . 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
4 // Time Domain Approach
5 close ;
6 clc ;
7 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 := )
8 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 :=
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

)
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 , m ) ) ;
x2 = round ( convol ( g2 , m ) ) ;
x1 = modulo ( x1 ,2) ;
x2 = modulo ( x2 ,2) ;
N = length ( x1 ) ;
for i =1: length ( x1 )
x (i ,:) =[ x1 (N - i +1) , x2 (N - i +1) ];
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 , 1 , 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 , 0 , 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 , 1 , 0 , 0 , 1 ]
// x =
// ! 1 1 !
// !
!
// ! 1 0 !
// !
!
// ! 1 1 !
// !
!
// ! 1 1 !
// !
!
// ! 0 1 !
// !
!
// ! 0 1 !
// !
!
// ! 1 1 !

68

Scilab code Exa 8.8 Convolutional Encoding


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// c l e a r //
// 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 . 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 ;
D = poly (0 , D ) ;
g1D = 1+ D + D ^2; // g e n e r a t o r p o l y n o m i a l 1
g2D = 1+ D ^2; // 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; // 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 ; // t o p o u t p u t p o l y n o m i a l
x2D = g2D * mD ; // bottom o u t p u t p o l y n o m i a l
x1 = coeff ( x1D ) ;
x2 = coeff ( x2D ) ;
disp ( modulo ( x1 ,2) , t o p o u t p u t s e q u e n c e )
disp ( modulo ( x2 ,2) , 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.
1.
1.
1.
0.
0.
1.
//
// bottom o u t p u t s e q u e n c e
//
1.
0.
1.
1.
1.
1.
1.

Scilab code Exa 8.11 ano metric for binary symmetric channel
1
2

// c l e a r //
// 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

69

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// Example8 . 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 ;
r = 1/2; // c o d e r a t e
n =2; // number o f b i t s
pe = 0.04; // t r a n s i t i o n p r o b i l i t y
p = 1 - pe ; // 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 - r ) ; // b r a n c h m e t r i c f o r
correct reception
gamma_2 = log2 ( pe * 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 , 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 , 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 , 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.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.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.2877124

70

Chapter 9
Spread Spectrum Modulation

Scilab code Exa 9.1 PN sequence generation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// c l e a r //
// 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 . 1 and F i g u r e 9 . 1 : Maximuml 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 ;
// 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;
x1 = 0;
x2 =0;
x3 =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 ;
x1 = x0 ;
x0 = xor ( x1 , x3 ) ;
disp (i , The PN s e q u e n c e a t s t e p )
x = [ x1 x2 x3 ];
71

20
disp (x , x= )
21 end
22 m = [7 ,8 ,9 ,10 ,11 ,12 ,13 ,17 ,19];
23 N = 2^ m -1;
24 disp ( T a b l e 9 . 1 Range o f PN S e q u e n c e l e n g t h s )
25 disp (

26
27
28
29
30

)
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 (

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

)
// 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.
// x=
1.
0.
0.
// The PN s e q u e n c e a t s t e p
2.
// x=
1.
1.
0.
// The PN s e q u e n c e a t s t e p
3.
// x=
1.
1.
1.
// The PN s e q u e n c e a t s t e p
4.
// x=
0.
1.
1.
// The PN s e q u e n c e a t s t e p
5.
// x=
1.
0.
1.
// The PN s e q u e n c e a t s t e p
6.
// x=
0.
1.
0.
// The PN s e q u e n c e a t s t e p
7.
// x=
0.
0.
1.

Scilab code Exa 9.2 Maximum length sequence property


1
2

// c l e a r //
// 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
72

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

// Example9 . 2 and F i g u r e 9 . 2 : Maximuml e n g t h s e q u e n c e


// P e r i o d o f PN S e q u e n c e N = 7
// P r o p e r i t e s o f maximuml e n g t h s e q u e n c e
clc ;
// 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;
x1 = 0;
x2 =0;
x3 =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 )
one_count = 0;
zero_count = 0;
for i =1: N
x3 = x2 ;
x2 = x1 ;
x1 = x0 ;
x0 = xor ( x1 , x3 ) ;
disp (i , The PN s e q u e n c e a t s t e p )
x = [ x1 x2 x3 ];
disp (x , x= )
C ( i ) = x3 ;
if ( C ( i ) ==1)
C_level ( i ) =1;
one_count = one_count +1;
elseif ( C ( i ) ==0)
C_level ( i ) = -1;
zero_count = zero_count +1;
end
end
disp (C , Output S e q u e n c e ) // r e f e r e q u a t i o n 9 . 4
disp ( C_level , Output S e q u e n c e l e v e l s ) // r e f e r
equation 9.5
if ( zero_count < one_count )
disp ( one_count , Number o f 1 s i n t h e g i v e n PN
sequence )
disp ( zero_count , 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
73

)
38
39
40
41
42
43
44
45
46
47

54

end
Rc_tuo = corr ( C_level , N ) ;
t = 1:2* length ( C_level ) ;
//
figure
a = gca () ;
a . x_location = o r i g i n ;
plot2d (t ,[ C_level ; C_level ])
xlabel (
t )
title ( Waveform o f maximuml 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] )
//
figure
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ([ - length ( Rc_tuo ) +1: -1 ,0: length ( Rc_tuo ) -1] ,[
Rc_tuo ( $ : -1:2) , Rc_tuo ] ,5)
xlabel (

55

tuo )
ylabel (

56

Rc ( t u o ) )
title ( A u t o c o r r e l a t i o n o f maximuml e n g t h s e q u e n c e )

48
49
50
51
52
53

Scilab code Exa 9.3 Processing gain, PN sequence length, Jamming margin in dB
// c l e a r //
// C a p t i o n : P r o c e s s i n g g a i n , PN s e q u e n c e l e n g t h ,
Jamming m a r g i n i n dB
3 // Example9 . 3 : P r o c e s s i n g g a i n and Jamming Margin
4 clear ;
1
2

74

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

clc ;
close ;
Tb = 4.095*10^ -3; // 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; //PN c h i p d u r a t i o n
PG = Tb / Tc ; // P r o c e s s i n g g a i n
disp ( PG , The p r o c e s s i n g g a i n i s : )
N = PG ; //PN s e q u e n c e l e n g t h
m = log2 ( N +1) ; // 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 , The r e q u i r e d PN s e q u e n c e i s : )
disp (m , 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 : )
Eb_No = 10; // Energy t o n o i s e d e n s i t y r a t i o
J_P = PG / Eb_No ; // Jamming Margin
disp (10* log10 ( J_P ) , Jamming Margin i n dB : )
// R e s u l t
// The p r o c e s s i n g g a i n i s :
4095.
// The r e q u i r e d PN s e q u e n c e i s : 4 0 9 5 .
// 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 .
// Jamming Margin i n dB : 2 6 . 1 2 2 5 3 9

Scilab code Exa 9.4.9.5 Slow and Fast Frequency hopping: FH/MFSK
1
2
3
4
5
6
7
8
9
10
11
12
13

// c l e a r //
// 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 . 4 and Example9 . 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 ;
close ;
clc ;
K =2; // number o f b i t s p e r symbol
M = 2^ K ; // Number o f MFSK t o n e s
N = 2^ M -1; // P e r i o d o f t h e PN s e q u e n c e
k = 3; // l e n g t h o f PN s e q u e n c e p e r hop
disp (K , number o f b i t s p e r symbol K = )
disp (M , Number o f MFSK t o n e s M= )
75

14
15
16
17
18
19
20
21
22

disp (N , P e r i o d o f t h e PN s e q u e n c e N = )
disp (k , 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 , 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 .
// Number o f MFSK t o n e s M = 4 .
// 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 = 3 .
// T o t a l number o f f r e q u e n c y h o p s = 8 .

Scilab code Exa 9.4.96 Direct Sequence Spread Coherent BPSK


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

// c l e a r //
// 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
// F i g u r e 9 . 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 ;
close ;
clc ;
t = 0:13;
N = 7;
wt = 0:0.01:1;
bt = [1* ones (1 , N ) -1* ones (1 , N ) ];
ct = [0 ,0 ,1 ,1 ,1 ,0 ,1 ,0 ,0 ,1 ,1 ,1 ,0 ,1];
ct_polar = [ -1 , -1 ,1 ,1 ,1 , -1 ,1 , -1 , -1 ,1 ,1 ,1 , -1 ,1];
mt = bt .* ct_polar ;
Carrier = 2* sin ( wt *2* %pi ) ;
st = [];
for i = 1: length ( mt )
st = [ st mt ( i ) * Carrier ];
end
//
figure
subplot (3 ,1 ,1)
a = gca () ;
76

23 a . x_location = o r i g i n ;
24 a . y_location = o r i g i n ;
25 a . data_bounds = [0 , -2;20 ,2];
26 plot2d2 (t , bt ,5)
27 xlabel (

28
29
30
31
32
33
34
35

t )
title ( Data b ( t ) )
subplot (3 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -2;20 ,2];
plot2d2 (t , ct_polar ,5)
xlabel (

36
37
38
39
40
41
42
43

t )
title ( S p r e a d i n g c o d e c ( t ) )
subplot (3 ,1 ,3)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -2;20 ,2];
plot2d2 (t , mt ,5)
xlabel (

44
45
46
47
48
49
50
51
52
53

t )
title ( P r o d u c t S i g n a l m( t ) )
//
figure
subplot (3 ,1 ,1)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -2;20 ,2];
plot2d2 (t , mt ,5)
xlabel (

77

54
55
56
57
58
59
60
61

t )
title ( P r o d u c t S i g n a l m( t ) )
subplot (3 ,1 ,2)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -2;20 ,2];
plot ( Carrier )
xlabel (

62
63
64
65
66
67
68
69

t )
title ( C a r r i e r S i g n a l )
subplot (3 ,1 ,3)
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
a . data_bounds = [0 , -2;20 ,2];
plot ( st )
xlabel (

t )
70 title ( DS/BPSK s i g n a l s ( t ) )
71 //

78

You might also like