# Chapter 6 : Digital Modulation and Transmission¶

## Example 6.1 Page No : 341¶

In [12]:
import math
from numpy import zeros,bitwise_xor

#Given messages signal m  =  [1,0,1,1,0,1]
m  =  [1,0,1,1,0,1];

#Logical 0 corrsponds to pi i.e math.pi and Logical 1 corresponds to 0

################################################################################

#For BPSK, from the above deduction let the carrier phase be Carrier_Phase_BPSK
Carrier_Phase_BPSK =  zeros(5)
for i  in range(5):
if m[i] == 1:
Carrier_Phase_BPSK[i]  =  0;
else:
Carrier_Phase_BPSK[i]  =  math.pi;

print 'The Phase of the carrier signal for BPSK varies as ',Carrier_Phase_BPSK

################################################################################

#For DPSK
#Let b represent the input to balance modulator

#If the initial value of b be 0
b  =  zeros(5)

for i  in range(1,5):
b[i]  =  int(m[i])^int(b[i-1])

Carrier_Phase_DPSK = zeros(5)

#Now the carrier phase, Carrier_Phase_DPSK
for i  in range(5):
if b[i] == 1 :
Carrier_Phase_DPSK[i]  =  0;
else:
Carrier_Phase_DPSK[i]  =  math.pi;

Carrier_Amplitude_DPSK = zeros(5)
#Now the carrier amplitude, Carrier_Amplitude_DPSK
for i  in range(5):
Carrier_Amplitude_DPSK[i]  =  math.cos(Carrier_Phase_DPSK[i]);

print 'The Phase of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 1',Carrier_Phase_DPSK
print 'The Amplitude of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 1',Carrier_Amplitude_DPSK

#If the initial value of b be 1
b  =  zeros(5)

for i  in range(1,5):
b[i]  =  m[i]^int(b[i-1])

#Now the carrier phase, Carrier_Phase_DPSK
for i  in range(5):
if b[i] == 1:
Carrier_Phase_DPSK[i]  =  0;
else:
Carrier_Phase_DPSK[i]  =  math.pi;

#Now the carrier amplitude, Carrier_Amplitude_DPSK
for i  in range(5):
Carrier_Amplitude_DPSK[i]  =  math.cos(Carrier_Phase_DPSK[i]);

print 'The Phase of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 0',Carrier_Phase_DPSK
print 'The Amplitude of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 0',Carrier_Amplitude_DPSK

################################################################################

#For DEPSK
#The DEPSK transmitter output is same as that of DPSK

#If the initial value of b be 0
b  =  zeros(5)

for i  in range(1,5):
b[i]  =  m[i]^int(b[i-1])

Carrier_Phase_DEPSK = zeros(5)
#Now the carrier phase, Carrier_Phase_DPSK
for i  in range(5):
if b[i] == 1:
Carrier_Phase_DEPSK[i]  =  0;
else:
Carrier_Phase_DEPSK[i]  =  math.pi;

print 'The Phase of the carrier signal for DEPSK varies as follows, '+'when the initial value of b is 1',Carrier_Phase_DEPSK

#If the initial value of b be 1
b  =  zeros(5)
b[0] = 1

for i  in range(1,5):
b[i]  =  m[i]^int(b[i-1])

#Now the carrier phase, Carrier_Phase_DPSK
for i  in range(5):
if b[i] == 1:
Carrier_Phase_DEPSK[i]  =  0;
else:
Carrier_Phase_DEPSK[i]  =  math.pi;

print 'The Phase of the carrier signal for DEPSK  varies as, '+'when the initial value of b is 0',Carrier_Phase_DEPSK

The Phase of the carrier signal for BPSK varies as  [ 0.          3.14159265  0.          0.          3.14159265]
The Phase of the carrier signal for DPSK varies as follows, when the initial value of b is 1 [ 3.14159265  3.14159265  0.          3.14159265  3.14159265]
The Amplitude of the carrier signal for DPSK varies as follows, when the initial value of b is 1 [-1. -1.  1. -1. -1.]
The Phase of the carrier signal for DPSK varies as follows, when the initial value of b is 0 [ 3.14159265  3.14159265  0.          3.14159265  3.14159265]
The Amplitude of the carrier signal for DPSK varies as follows, when the initial value of b is 0 [-1. -1.  1. -1. -1.]
The Phase of the carrier signal for DEPSK varies as follows, when the initial value of b is 1 [ 3.14159265  3.14159265  0.          3.14159265  3.14159265]
The Phase of the carrier signal for DEPSK  varies as, when the initial value of b is 0 [ 0.          0.          3.14159265  0.          0.        ]


## Example 6.2 Page No : 341¶

In [14]:
import math
from numpy import zeros

#From Ex6_1 the obtained carrier amplitude is c

################################################################################

#For DPSK
#Considering the initial value of the storage element to be 0 in polar and -1 in biploar
c  =  [1,1,-1,1,1];
y = zeros(5)
y[0]  =  -1;
#Let the output be y
for i  in range(1,5):
y[i]  =  c[i]*c[i-1]

output_binary = zeros(5)
#Converting back to binary data
for i  in range(5):
if y[i] ==  -1:
output_binary[i]  =  0;
else:
output_binary[i]  =  1;

#Now inverting the output we get:
for i  in range(5):
output_binary[i]  =  int(output_binary[i]);

print 'The DPSK output is',output_binary

################################################################################

#For DEPSK

#From example Ex6_1, we have b when initial storage value is assumed to be 1
b  =  [1,1,0,1,1];

#Output y
y[0]  =  1;
for i  in range(1,5):
y[i]  =  b[i]^b[i-1]

print 'The DEPSK output is',y

The DPSK output is [ 0.  1.  0.  0.  1.]
The DEPSK output is [ 1.  0.  1.  1.  0.]


## Example 6.4 Page No : 365¶

In [1]:
import math

#Given energy per bit Eb  =  0.01
Eb  =  0.01;

#Given fundamental frequency is fb  =  8 KHz
fb  =  8*10**3;

#No of symbols M  =  16
M  =  16.;

N  =  math.log(M,2);

BW_BPSK  =  2*fb;
print 'Bandwidth for BPSK is ',BW_BPSK,'Hz'

BW_QPSK  =  fb;
print 'Bandwidth for QPSK is ',BW_QPSK,'Hz'

BW_16MPSK  =  fb/2;
print 'Bandwidth for 16 MPSK is ',BW_16MPSK,'Hz'

BW_BFSK  =  4*fb;
print 'Bandwidth for BFSK is ',BW_BFSK,'Hz'

BW_MSK  =  1.5*fb;
print 'Bandwidth for MSK is ',BW_MSK,'Hz'

BW_16MFSK  =  2*M*fb;
print 'Bandwidth for 16 MFSK is ',BW_16MFSK,'Hz'

Min_dist_BPSK  =  2*(Eb)**0.5;
print 'Minimum dismath.tance in signal space in BPSK is ',Min_dist_BPSK

Min_dist_QPSK  =  2*(Eb)**0.5;
print 'Minimum dismath.tance in signal space in QPSK is ',Min_dist_QPSK

#The given answer in the textbook is 0.0152, which appears to be wrong. The correct answer is 0.078
Min_dist_16MPSK  =  (4*N*Eb*(math.sin(math.pi/16))**2)**0.5;
print 'Minimum dismath.tance in signal space in 16 MPSK is %.4f'%Min_dist_16MPSK

Min_dist_BFSK  =  (2*Eb)**0.5;
print 'Minimum dismath.tance in signal space in ortho BFSK is %.4f'%Min_dist_BFSK

Min_dist_MSK  =  2*(Eb)**0.5;
print 'Minimum dismath.tance in signal space in MSK is ',Min_dist_MSK

Min_dist_16MFSK  =  (2*N*Eb)**0.5;
print 'Minimum dismath.tance in signal space in ortho 16 MFSK is %.4f'%Min_dist_16MFSK

print 'The best method that provides least noise susceptibility is 16 MFSK, then BPSK, then QPSK, then\
comes MSK, then orthogonal BFSK and finally 16 MPSK'

Bandwidth for BPSK is  16000 Hz
Bandwidth for QPSK is  8000 Hz
Bandwidth for 16 MPSK is  4000 Hz
Bandwidth for BFSK is  32000 Hz
Bandwidth for MSK is  12000.0 Hz
Bandwidth for 16 MFSK is  256000.0 Hz
Minimum dismath.tance in signal space in BPSK is  0.2
Minimum dismath.tance in signal space in QPSK is  0.2
Minimum dismath.tance in signal space in 16 MPSK is 0.0780
Minimum dismath.tance in signal space in ortho BFSK is 0.1414
Minimum dismath.tance in signal space in MSK is  0.2
Minimum dismath.tance in signal space in ortho 16 MFSK is 0.2828
The best method that provides least noise susceptibility is 16 MFSK, then BPSK, then QPSK, then comes MSK, then orthogonal BFSK and finally 16 MPSK


## Example 6.5 Page No : 381¶

In [19]:
import math
from numpy import zeros

#Given input signal is d
d  =  [0,1,1,1,0,1,0,1,1];

################################################################################
#The answers obtained here are different from the ones mentioned in the textbook.
#The given answers have been checked rigorously and have been found out to be true.

#When precoded

#Signal b is initially assumed to be 0
b = zeros(9)
b[0]  =  0;

for i  in range(1,9):
b[i]  =  int(b[i-1])^d[i]

bp = zeros(9)
#Changing bit code to polar signal we get, 0 --> -1, 1 --> +1
for i  in range(9):
if b[i] == 1:
bp[i]  =  1;
else:
bp[i]  =  -1;

Vd = zeros(9)
#Let initial value of Vd be 0
#Vd  =  0;
for i  in range(1,9):
Vd[i]  =  bp[i] + bp[i-1]

da = zeros(9)
#Converting polar signal to bit code we get, -2 --> 0, 0 --> 1, 2 --> 0
for i  in range(9):
if Vd[i] ==  -2:
da[i]  =  0;
elif Vd[i] ==  2:
da[i]  =  0;
else:
da[i]  =  1;

print 'Decoded output when precoded is ',da

################################################################################

#When not precoded exor gate is not there
dp = zeros(9)
#Changing bit code to polar signal we get, 0 --> -1, 1 --> +1
for i  in range(9):
if d[i] == 1:
dp[i]  =  1;
else:
dp[i]  =  -1;

for i  in range(1,9):
Vd[i]  =  dp[i] + dp[i-1]

#Converting polar signal to bit code we get, -2 --> 0, 0 --> 1, 2 --> 1
for i  in range(1,9):
if Vd[i] ==  -2:
da[i]  =  0;
elif Vd[i] ==  2:
da[i]  =  0;
else:
da[i] =  ~int(da[i-1]);

print 'Decoded output when not precoded is ',da

Decoded output when precoded is  [ 1.  1.  1.  1.  0.  1.  0.  1.  1.]
Decoded output when not precoded is  [ 1. -2.  0.  0. -1.  0. -1.  0.  0.]


## Example 6.6 Page No : 381¶

In [20]:
import math

#Given Bandwidth BW  =  4 kHz
BW  =  4*10**3;

#Given data rate is fb  =  6 kbps
fb  =  6*10**3;

#The roll off factor alpha is
alpha  =  ((2*BW)/fb) - 1;

print 'The roll off factor is ',alpha;

#######################################/

#The required data rate supported at alpha  =  0.25 is D
alpha  =  0.25

#The corresponding expression for D is
D  =  (2*BW)/(1+alpha);

print 'The supported data rate is ',D,' kbps'

#For full roll-off alpha  =  1.0,
alpha  =  1;

fb  =  2*BW/(1+alpha);

print 'The data rate is ',fb,' kbps'

The roll off factor is  0
The supported data rate is  6400.0  kbps
The data rate is  4000  kbps