Chapter 7 Digital Modulation Techniques

Example 7.01 page 294

In [1]:
from __future__ import division
from numpy import arange, sin, pi,zeros
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,grid,show
#Caption:Waveforms of Different Digital Modulation techniques
#Figure7.1
#Digital Modulation Techniques
#To Plot the ASK, FSK and PSk Waveforms
f = 2 # the Analog Carrier Frequency in Hz
t = arange(0,1/512+1,1/512)
x = [sin(2*pi*f*tt) for tt in t]
I = [0,1,1,0,1,0,0,1] # the digital binary data
#Generation of ASK Waveform
#Xask = []#
Xask=zeros(len(x))
for n in range(0,len(I)):
  if((I[n]==1) and (n==0)):
    Xask = [x,Xask]#
  elif((I[n]==0) and (n==0)):
    Xask = [zeros(len(x)),Xask]
  elif((I[n]==1) and (n!=1)):
    Xask = [Xask,x]
  elif((I[n]==0) and (n!=1)):  
    Xask = [Xask,zeros(len(x))]
  

#Generation of FSK Waveform
Xfsk = []#
x1 = [sin(2*pi*f*tt) for tt in t]
x2 = [sin(2*pi*(2*f)*tt) for tt in t]
for n in range(0,len(I)):
  if (I[n]==1):
      Xfsk = [Xfsk,x2]
  elif (I[n]!=1):
    Xfsk = [Xfsk,x1]
  

#Generation of PSK Waveform
Xpsk = []#
x1 = [sin(2*pi*f*tt) for tt in t]
x2 = [-sin(2*pi*f*tt) for tt in t]
for n in range(0,len(I)):
  if (I[n]==1):
      Xpsk = [Xpsk,x1]
  elif (I[n]!=1):
    Xpsk = [Xpsk,x2]
  
plot(t,x)
title('Analog Carrier Signal for Digital Modulation')
grid()
show()

Example7.1 page 298

In [1]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show

M =4#
i = range(0,M)
t = arange(0,0.001+1,0.001)
s1=ones([len(i),len(t)])
s2=ones([len(i),len(t)])
for i in range(0,M):
  s1[i,:] = [cos(2*pi*2*tt)*cos((2*i-1)*pi/4) for tt in t]
  s2[i,:] = [-sin(2*pi*2*tt)*sin((2*i-1)*pi/4) for tt in t]

S1 =[]#
S2 = []#
S = []#
Input_Sequence =[0,1,1,0,1,0,0,0]
m = [3,1,1,2]
for i in range(0,len(m)):
  S1 = S1+[s1[m[i],:]]
  S2 = S2+[s2[m[i],:]]
S = S1+S2#
subplot(3,1,1)
plot(S1)
title('Binary PSK wave of Odd-numbered bits of input sequence') 
subplot(3,1,2)
plot(S2)
title('Binary PSK wave of Even-numbered bits of input sequence') 
subplot(3,1,3)
plot(S)
title('QPSK waveform') 
show()

Example 7.02 page 302

In [1]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show

M =2#
i = range(1,M+1)
y = [cos(2*pi+(ii-1)*pi) for ii in i]

annot = [bin(xx) for xx in arange(len(y)-1,-1,-1)]
annot = [bin(yy) for yy in arange(len(y)-1,-1,-1)]

print 'coordinates of message points',y

print 'Message points',annot
plot(y)
xlabel('                                                                      In-Phase')#
ylabel('                                                                      Quadrature')#
title('Constellation for BPSK')
show()
coordinates of message points [1.0, -1.0]
Message points ['0b1', '0b0']

Example7.2 page 304

In [4]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show,legend,grid,subplot
#Table 7.2 signal space characterization of MSK

M =2#
Tb =1#
t1 = arange(-Tb,0.01+Tb,Tb)
t2 = arange(0,0.01+2*Tb,2*Tb)
phi1 = [cos(2*pi*t11)* cos((pi/(2*Tb))*t11) for t11 in t1]
phi2 = [sin(2*pi*t22)*sin((pi/(2*Tb))*t22) for t22 in t2]
teta_0 = [0,pi]
teta_tb = [pi/2,-pi/2]
S1 = [];s1 = []
S2 = [];s2 = []
for i in range(0,M):
  s1.append(cos(teta_0[i]))
  s2.append(-sin(teta_tb[i]))
  S1 = S1+[s1[i]*phi1]
  S2 = S2+[s2[0]*phi2]

for i in arange(M,-1+1,1):
  S1 = S1+[s1[i]*phi1]
  S2 = S2+[s2(1)*phi2]

Input_Sequence =[1,1,0,1,0,0,0]
S = []
t = arange(0,0.01+1,1)
S = S+[cos(0)*cos(2*pi*tt)-sin(pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(0)*cos(2*pi*tt)-sin(pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(pi)*cos(2*pi*tt)-sin(pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(pi)*cos(2*pi*tt)-sin(-pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(0)*cos(2*pi*tt)-sin(-pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(0)*cos(2*pi*tt)-sin(-pi/2)*sin(2*pi*tt) for tt in t]
S = S+[cos(0)*cos(2*pi*tt)-sin(-pi/2)*sin(2*pi*tt) for tt in t]

y = [[s1[0],s2[0]],[s1[1],s2[0]],[s1[1],s2[1]],[s1[0],s2[1]]]
print 'coordinates of message points'
for yy in y:
    print yy
    

subplot(3,1,1)
plot(S1[0])
title('Scaled time function s1*phi1(t)')
#subplot(3,1,2)plot(S2[0])title('Scaled time function s2*phi2(t)')
subplot(3,1,3)
plot(S)
title('Obtained by adding s1*phi1(t)+s2*phi2(t) on a bit-by-bit basis')    
show()
coordinates of message points
[1.0, -1.0]
[-1.0, -1.0]
[-1.0, 1.0]
[1.0, 1.0]

Example 7.3 page 308

In [2]:
from __future__ import division
from math import pi


bk = [1,0,0,1,0,0,1,1]##input digital sequence
bk_not=[]
for i in range(0,len(bk)):
  if(bk[i]==1):
    bk_not.append(0)
  else:
    bk_not.append(1)
  
dk_1 = [ 1 and bk[0]]#  #initial value of differential encoded sequence
dk_1_not =[ 0 and bk_not[0]]
dk = [dk_1[0]^dk_1_not[0]] #first bit of dpsk encoder
for i in range(1,len(bk)):
  dk_1.append(dk[(i-1)])
  if dk[(i-1)]==1:
     xxx=0
  else:
    xxx=1
  dk_1_not.append(xxx)
  dk.append(((dk_1[i] and bk[i])^(dk_1_not[i] and bk_not[i])))
dk_radians=[]
for i in range(0,len(dk)):
  if(dk[i]==1):
    dk_radians.append(0)
  elif(dk[i]==0):
    dk_radians.append(pi)
  
print 'Table 7.3 Illustrating the Generation of DPSK Signal'
print '_____________________________________________________'
print '\n(bk)',bk
print '\n(bk_not)',bk_not
print '\nDifferentially encoded sequence (dk)'
for dd in dk:
    print dd,'\t',
print '\n\nTransmitted phase in radians'
for ddd in dk_radians:
    print ddd,'\t',
print '\n\n_____________________________________________________'
Table 7.3 Illustrating the Generation of DPSK Signal
_____________________________________________________

(bk) [1, 0, 0, 1, 0, 0, 1, 1]

(bk_not) [0, 1, 1, 0, 1, 1, 0, 0]

Differentially encoded sequence (dk)
1 	0 	1 	1 	0 	1 	1 	1 	

Transmitted phase in radians
0 	3.14159265359 	0 	0 	3.14159265359 	0 	0 	0 	

_____________________________________________________

Example 7.4 page 314

In [1]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show,legend,grid

M =2#
y = [[1,0],[0,1]]
annot = [bin(xx) for xx in (arange(M-1,-1,-1))]
print 'coordinates of message points'
for yy in y:
    print y

print 'Message points',annot

plot(y[0])
plot(y[1])
xlabel('                                                                      In-Phase')#
ylabel('                                                                    Quadrature')#
title('Constellation for BFSK')
legend(['message point 1 (binary 1)','message point 2 (binary 0)'])
show()
coordinates of message points
[[1, 0], [0, 1]]
[[1, 0], [0, 1]]
Message points ['0b1', '0b0']

Example 7.4. page 320

In [1]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show,legend,grid
from scipy.special import erfc
from math import log10,sqrt,exp
from __future__ import division
#Comparison of Symbol Error Probability
#of Different Digital Transmission System
#Eb =  Energy of the bit  No = Noise Spectral Density
Eb_No =[18,0.3162278]
x = arange(Eb_No[1],1/100+Eb_No[0],1./100)
x_dB = [10*log10(xx) for xx in x]
Pe_BPSK=ones(len(x))
Pe_BFSK=ones(len(x))
Pe_DPSK=ones(len(x))
Pe_NFSK=ones(len(x))
Pe_QPSK_MSK=ones(len(x))
for i in range(0,len(x)):
  #Error Probability of Coherent BPSK 
  Pe_BPSK[i]= (1/2)*erfc(sqrt(x[i]))#
  #Error Probability of Coherent BFSK
  Pe_BFSK[i]= (1/2)*erfc(sqrt(x[i]/2))#
  #Error Probability Non-Coherent PSK = DPSK 
  Pe_DPSK[i]= (1/2)*exp(-x[i])#
  #Error Probability Non-Coherent FSK
  Pe_NFSK[i]= (1/2)*exp(-(x[i]/2))#
  #Error Probability of QPSK & MSK
  Pe_QPSK_MSK[i]= erfc(sqrt(x[i]))-((1/4)*(erfc(sqrt(x[i]))**2))

plot(x_dB,Pe_BPSK)
plot(x_dB,Pe_BFSK)
plot(x_dB,Pe_NFSK)
plot(x_dB,Pe_QPSK_MSK)
xlabel('Eb/No in dB ---->')
ylabel('Probability of Error Pe--->')
title('Comparison of Noise Performance of different PSK & FSK Scheme')
legend(['BPSK','BFSK','DPSK','Non-Coherent FSK','QPSK & MSK'])
grid()
show()

Example 7.06 page 324

In [1]:
from math import log

#Bandwidth Efficiency of M-ary PSK signals
M = [2,4,8,16,32,64]##M-ary
Ruo = [log(MM,2)/2 for MM in M]# #Bandwidth efficiency in bits/s/Hz
print 'Table 7.7 Bandwidth Efficiency of M-ary PSK signals'
print '______________________________________________________'
print 'M\n',M
print '______________________________________________________'
print 'r in bits/s/Hz\n',Ruo
print '______________________________________________________'
Table 7.7 Bandwidth Efficiency of M-ary PSK signals
______________________________________________________
M
[2, 4, 8, 16, 32, 64]
______________________________________________________
r in bits/s/Hz
[0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
______________________________________________________

Example 7.6 page 326

In [1]:
from numpy import ones,arange,cos,sin,pi
%matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show


#Figure7.6 Signal Space Diagram for coherent QPSK system
M =4#
i = range(0,M)
y = [cos((2*ii-1)*pi/4)-sin((2*ii-1)*pi/4)*1J for ii in i]
annot = [bin(xx)[2:] for xx in range(0,M)]
print 'coordinates of message points\n'
for yyy in y:
    print yyy

print 'dibits value',annot
plot([y[0].real,y[1].real,y[2].real,y[3].real],[y[0].imag,y[1].imag,y[2].imag,y[3].imag])
xlabel('                                             In-Phase')#
ylabel('                                             Quadrature')#
title('Constellation for QPSK')
show()
print y[0].imag
print y[0].real
coordinates of message points

(0.707106781187+0.707106781187j)
(0.707106781187-0.707106781187j)
(-0.707106781187-0.707106781187j)
(-0.707106781187+0.707106781187j)
dibits value ['0', '1', '10', '11']
0.707106781187
0.707106781187

Example 7.7 page 329

In [1]:
from math import log
# Bandwidth Efficiency of M-ary FSK
M = [2,4,8,16,32,64]##M-ary
Ruo = [2*log(MM,2)/MM for MM in M]# #Bandwidth efficiency in bits/s/Hz
#M = M'#
#Ruo = Ruo'#
print 'Table 7.7 Bandwidth Efficiency of M-ary FSK signals'
print '______________________________________________________'
print 'M = \n',M
print '______________________________________________________'
print 'r in bits/s/Hz=\n',Ruo
print '______________________________________________________'
Table 7.7 Bandwidth Efficiency of M-ary FSK signals
______________________________________________________
M = 
[2, 4, 8, 16, 32, 64]
______________________________________________________
r in bits/s/Hz=
[1.0, 1.0, 0.75, 0.5, 0.3125, 0.1875]
______________________________________________________

Example7.12.7.2 page 332

In [1]:
from __future__ import division
from numpy import pi,sin,cos,arange,ones,sinc
from math import log
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,show,legend,grid

M =2#
teta_0 = [0,pi]#
teta_tb = [pi/2,-pi/2]#
s1=[]
s2=[]
for i in range(0,M):
  s1.append(cos(teta_0[i]))
  s2.append(-sin(teta_tb[i]))
y = [[s1[0],s2[0]],[s1[1],s2[1]],[s1[1],s2[1]],[s1[0],s2[1]]]
print 'coordinates of message points\n'
for xx in y:
    print xx
plot(y[0])
plot(y[1])
plot(y[2])
plot(y[3])
xlabel('                                                                      In-Phase')#
ylabel('                                                                    Quadrature')#
title('Constellation for MSK')
legend(['message point 1 (0, pi/2)','message point 2 (pi, pi/2)','message point 3  (pi,  - pi/2)','message point 4(0, - pi/2)'])
show()
coordinates of message points

[1.0, -1.0]
[-1.0, 1.0]
[-1.0, 1.0]
[1.0, 1.0]

Example7.29 page 334

In [1]:
from __future__ import division
from numpy import arange,ones,sinc,pi,sin,cos
from math import log
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,show,legend,grid

rb = 2 # the bit rate in bits per second
Eb = 1 # the Energy of bit

f = arange(0,1/100+8/rb,8/rb)
Tb = 1/rb#  #Bit duration
SB_PSK=ones(len(f))
SB_FSK=ones(len(f))
for i in range(0,len(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))
   
   SB_PSK[i]=2*Eb*(sinc(f[i]*Tb)**2)

plot([ff*Tb for ff in f],[yy/(2*Eb) for yy in SB_FSK])    
plot([ff*Tb for ff in f],[yy/(2*Eb) for yy in SB_PSK])    
xlabel('Normalized Frequency ---->')
ylabel('Normalized Power Spectral Density--->')
title('PSK Vs FSK Power Spectra Comparison')
legend(['Frequency Shift Keying','Phase Shift Keying'])
grid() 
show()

Example7.30 page 336

In [1]:
from __future__ import division
from numpy import arange,ones,sinc,pi,cos
from math import log
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,show,legend,grid

rb = 2 # the bit rate in bits per second
Eb = 1 # the Energy of bit
f = arange(0,1/(100*rb)+(4/rb),1/(100*rb))
Tb = 1/rb# #bit duration in seconds
SB_MSK=ones(len(f))
SB_QPSK=ones(len(f))
for i in range(0,len(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
  
  SB_QPSK[i]=4*Eb*sinc((2*Tb*f[i]))**2

plot([ff*Tb for ff in f],[yy/(4*Eb) for yy in SB_MSK])
plot([ff*Tb for ff in f],[yy/(4*Eb) for yy in SB_QPSK])
xlabel('Normalized Frequency ---->')
ylabel('Normalized Power Spectral Density--->')
title('QPSK Vs MSK Power Spectra Comparison')
legend(['Minimum Shift Keying','QPSK'])
grid()
show()

Example7.31 page 338

In [1]:
from __future__ import division
from numpy import arange,ones,sinc
from math import log
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,show,legend,grid

rb = 2 # the bit rate
Eb = 1 # the energy of the bit
f = arange(0,1.0/100+rb,1./100)
Tb = 1/rb#  #Bit duration
M = [2,4,8]#
SB_PSK=ones([len(M),len(f)])
for j in range(0,len(M)):
  for i in range(0,len(f)):
    SB_PSK[j,i]=2*Eb*(sinc(f[i]*Tb*log(M[j],2))**2)*log(M[j],2)
  
plot([ff*Tb for ff in f],[xx/(2*Eb) for xx in SB_PSK[0,:]])
plot([ff*Tb for ff in f],[xx/(2*Eb) for xx in SB_PSK[1,:]])
plot([ff*Tb for ff in f],[xx/(2*Eb) for xx in SB_PSK[2,:]])
xlabel('Normalized Frequency ---->')
ylabel('Normalized Power Spectral Density--->')
title('Power Spectra of M-ary signals for M =2,4,8')
legend(['M=2','M=4','M=8'])
grid()
show()

Example7.41 page 340

In [1]:
from numpy import ones,convolve as convol
%matplotlib inline
from matplotlib.pyplot import plot,xlabel,ylabel,title,show
#Matched Filter Output
T =4#
a =2#
t = range(0,T+1)
g = [2*xx for xx in ones([1,T+1])][0]
h  =[abs(x) for x in (convol(g,g))]
for i in range(0,len(h)):
  if(h[i]<0.01):
    h[i]=0
  
h = [hh-T for hh in h]
t1 = range(0,len(h))
plot(t,g)
xlabel('t--->')
ylabel('g(t)---->')
title('Rectangular pulse duration T = 4, a =2')
show()
plot(t1,h)
xlabel('t--->')
ylabel('Matched Filter output')
title('Output of filter matched to rectangular pulse g(t)')
show()