{
"metadata": {
"name": "",
"signature": "sha256:b3d2be73bc592628c8051a60fe72eeaf96055185267343b2a99d6f76396ff6c2"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 6 : Digital Modulation and Transmission"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 6.1 Page No : 341"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math \n",
"from numpy import zeros,bitwise_xor\n",
"\n",
"#Given messages signal m = [1,0,1,1,0,1]\n",
"m = [1,0,1,1,0,1];\n",
"\n",
"#Logical 0 corrsponds to pi i.e math.pi and Logical 1 corresponds to 0\n",
"\n",
"################################################################################\n",
"\n",
"#For BPSK, from the above deduction let the carrier phase be Carrier_Phase_BPSK\n",
"Carrier_Phase_BPSK = zeros(5)\n",
"for i in range(5):\n",
" if m[i] == 1:\n",
" Carrier_Phase_BPSK[i] = 0;\n",
" else:\n",
" Carrier_Phase_BPSK[i] = math.pi;\n",
"\n",
"print 'The Phase of the carrier signal for BPSK varies as ',Carrier_Phase_BPSK\n",
"\n",
"################################################################################\n",
"\n",
"#For DPSK\n",
"#Let b represent the input to balance modulator\n",
"\n",
"#If the initial value of b be 0\n",
"b = zeros(5)\n",
"\n",
"for i in range(1,5):\n",
" b[i] = int(m[i])^int(b[i-1])\n",
"\n",
"Carrier_Phase_DPSK = zeros(5)\n",
"\n",
"#Now the carrier phase, Carrier_Phase_DPSK\n",
"for i in range(5):\n",
" if b[i] == 1 :\n",
" Carrier_Phase_DPSK[i] = 0;\n",
" else:\n",
" Carrier_Phase_DPSK[i] = math.pi;\n",
"\n",
"Carrier_Amplitude_DPSK = zeros(5)\n",
"#Now the carrier amplitude, Carrier_Amplitude_DPSK\n",
"for i in range(5):\n",
" Carrier_Amplitude_DPSK[i] = math.cos(Carrier_Phase_DPSK[i]);\n",
"\n",
"\n",
"print 'The Phase of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 1',Carrier_Phase_DPSK\n",
"print 'The Amplitude of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 1',Carrier_Amplitude_DPSK\n",
"\n",
"#If the initial value of b be 1\n",
"b = zeros(5)\n",
"\n",
"for i in range(1,5):\n",
" b[i] = m[i]^int(b[i-1])\n",
"\n",
"\n",
"#Now the carrier phase, Carrier_Phase_DPSK\n",
"for i in range(5):\n",
" if b[i] == 1:\n",
" Carrier_Phase_DPSK[i] = 0;\n",
" else:\n",
" Carrier_Phase_DPSK[i] = math.pi;\n",
"\n",
"#Now the carrier amplitude, Carrier_Amplitude_DPSK\n",
"for i in range(5):\n",
" Carrier_Amplitude_DPSK[i] = math.cos(Carrier_Phase_DPSK[i]);\n",
"\n",
"\n",
"print 'The Phase of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 0',Carrier_Phase_DPSK\n",
"print 'The Amplitude of the carrier signal for DPSK varies as follows, '+'when the initial value of b is 0',Carrier_Amplitude_DPSK\n",
"\n",
"################################################################################\n",
"\n",
"#For DEPSK\n",
"#The DEPSK transmitter output is same as that of DPSK\n",
"\n",
"#If the initial value of b be 0\n",
"b = zeros(5)\n",
"\n",
"for i in range(1,5):\n",
" b[i] = m[i]^int(b[i-1])\n",
"\n",
"\n",
"Carrier_Phase_DEPSK = zeros(5)\n",
"#Now the carrier phase, Carrier_Phase_DPSK\n",
"for i in range(5): \n",
" if b[i] == 1:\n",
" Carrier_Phase_DEPSK[i] = 0;\n",
" else:\n",
" Carrier_Phase_DEPSK[i] = math.pi;\n",
"\n",
"\n",
"print 'The Phase of the carrier signal for DEPSK varies as follows, '+'when the initial value of b is 1',Carrier_Phase_DEPSK\n",
"\n",
"#If the initial value of b be 1\n",
"b = zeros(5)\n",
"b[0] = 1\n",
"\n",
"for i in range(1,5):\n",
" b[i] = m[i]^int(b[i-1])\n",
"\n",
"\n",
"#Now the carrier phase, Carrier_Phase_DPSK\n",
"for i in range(5):\n",
" if b[i] == 1:\n",
" Carrier_Phase_DEPSK[i] = 0;\n",
" else:\n",
" Carrier_Phase_DEPSK[i] = math.pi;\n",
"\n",
"print 'The Phase of the carrier signal for DEPSK varies as, '+'when the initial value of b is 0',Carrier_Phase_DEPSK"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The Phase of the carrier signal for BPSK varies as [ 0. 3.14159265 0. 0. 3.14159265]\n",
"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]\n",
"The Amplitude of the carrier signal for DPSK varies as follows, when the initial value of b is 1 [-1. -1. 1. -1. -1.]\n",
"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]\n",
"The Amplitude of the carrier signal for DPSK varies as follows, when the initial value of b is 0 [-1. -1. 1. -1. -1.]\n",
"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]\n",
"The Phase of the carrier signal for DEPSK varies as, when the initial value of b is 0 [ 0. 0. 3.14159265 0. 0. ]\n"
]
}
],
"prompt_number": 12
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 6.2 Page No : 341"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math \n",
"from numpy import zeros\n",
"\n",
"#From Ex6_1 the obtained carrier amplitude is c\n",
"\n",
"################################################################################\n",
"\n",
"#For DPSK\n",
"#Considering the initial value of the storage element to be 0 in polar and -1 in biploar\n",
"c = [1,1,-1,1,1];\n",
"y = zeros(5)\n",
"y[0] = -1;\n",
"#Let the output be y\n",
"for i in range(1,5):\n",
" y[i] = c[i]*c[i-1]\n",
"\n",
"output_binary = zeros(5)\n",
"#Converting back to binary data\n",
"for i in range(5):\n",
" if y[i] == -1:\n",
" output_binary[i] = 0;\n",
" else:\n",
" output_binary[i] = 1;\n",
"\n",
"#Now inverting the output we get:\n",
"for i in range(5):\n",
" output_binary[i] = int(output_binary[i]);\n",
"\n",
"print 'The DPSK output is',output_binary\n",
"\n",
"\n",
"################################################################################\n",
"\n",
"#For DEPSK\n",
"\n",
"#From example Ex6_1, we have b when initial storage value is assumed to be 1\n",
"b = [1,1,0,1,1]; \n",
"\n",
"#Output y \n",
"y[0] = 1;\n",
"for i in range(1,5):\n",
" y[i] = b[i]^b[i-1]\n",
"\n",
"\n",
"print 'The DEPSK output is',y"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The DPSK output is [ 0. 1. 0. 0. 1.]\n",
"The DEPSK output is [ 1. 0. 1. 1. 0.]\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 6.4 Page No : 365"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math \n",
"\n",
"#Given energy per bit Eb = 0.01\n",
"Eb = 0.01;\n",
"\n",
"#Given fundamental frequency is fb = 8 KHz \n",
"fb = 8*10**3;\n",
"\n",
"#No of symbols M = 16\n",
"M = 16.;\n",
"\n",
"N = math.log(M,2);\n",
"\n",
"BW_BPSK = 2*fb;\n",
"print 'Bandwidth for BPSK is ',BW_BPSK,'Hz'\n",
"\n",
"BW_QPSK = fb;\n",
"print 'Bandwidth for QPSK is ',BW_QPSK,'Hz'\n",
"\n",
"BW_16MPSK = fb/2;\n",
"print 'Bandwidth for 16 MPSK is ',BW_16MPSK,'Hz'\n",
"\n",
"BW_BFSK = 4*fb;\n",
"print 'Bandwidth for BFSK is ',BW_BFSK,'Hz'\n",
"\n",
"BW_MSK = 1.5*fb;\n",
"print 'Bandwidth for MSK is ',BW_MSK,'Hz'\n",
"\n",
"BW_16MFSK = 2*M*fb;\n",
"print 'Bandwidth for 16 MFSK is ',BW_16MFSK,'Hz'\n",
"\n",
"\n",
"Min_dist_BPSK = 2*(Eb)**0.5;\n",
"print 'Minimum dismath.tance in signal space in BPSK is ',Min_dist_BPSK\n",
"\n",
"Min_dist_QPSK = 2*(Eb)**0.5;\n",
"print 'Minimum dismath.tance in signal space in QPSK is ',Min_dist_QPSK\n",
"\n",
"#The given answer in the textbook is 0.0152, which appears to be wrong. The correct answer is 0.078\n",
"Min_dist_16MPSK = (4*N*Eb*(math.sin(math.pi/16))**2)**0.5;\n",
"print 'Minimum dismath.tance in signal space in 16 MPSK is %.4f'%Min_dist_16MPSK\n",
"\n",
"Min_dist_BFSK = (2*Eb)**0.5;\n",
"print 'Minimum dismath.tance in signal space in ortho BFSK is %.4f'%Min_dist_BFSK\n",
"\n",
"Min_dist_MSK = 2*(Eb)**0.5;\n",
"print 'Minimum dismath.tance in signal space in MSK is ',Min_dist_MSK\n",
"\n",
"Min_dist_16MFSK = (2*N*Eb)**0.5;\n",
"print 'Minimum dismath.tance in signal space in ortho 16 MFSK is %.4f'%Min_dist_16MFSK\n",
"\n",
"print 'The best method that provides least noise susceptibility is 16 MFSK, then BPSK, then QPSK, then\\\n",
" comes MSK, then orthogonal BFSK and finally 16 MPSK'\n",
"\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Bandwidth for BPSK is 16000 Hz\n",
"Bandwidth for QPSK is 8000 Hz\n",
"Bandwidth for 16 MPSK is 4000 Hz\n",
"Bandwidth for BFSK is 32000 Hz\n",
"Bandwidth for MSK is 12000.0 Hz\n",
"Bandwidth for 16 MFSK is 256000.0 Hz\n",
"Minimum dismath.tance in signal space in BPSK is 0.2\n",
"Minimum dismath.tance in signal space in QPSK is 0.2\n",
"Minimum dismath.tance in signal space in 16 MPSK is 0.0780\n",
"Minimum dismath.tance in signal space in ortho BFSK is 0.1414\n",
"Minimum dismath.tance in signal space in MSK is 0.2\n",
"Minimum dismath.tance in signal space in ortho 16 MFSK is 0.2828\n",
"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\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 6.5 Page No : 381"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math \n",
"from numpy import zeros\n",
"\n",
"#Given input signal is d\n",
"d = [0,1,1,1,0,1,0,1,1];\n",
"\n",
"################################################################################\n",
"#The answers obtained here are different from the ones mentioned in the textbook.\n",
"#The given answers have been checked rigorously and have been found out to be true.\n",
"\n",
"#When precoded\n",
"\n",
"#Signal b is initially assumed to be 0 \n",
"b = zeros(9)\n",
"b[0] = 0;\n",
"\n",
"for i in range(1,9):\n",
" b[i] = int(b[i-1])^d[i]\n",
"\n",
"\n",
"bp = zeros(9)\n",
"#Changing bit code to polar signal we get, 0 --> -1, 1 --> +1\n",
"for i in range(9): \n",
" if b[i] == 1:\n",
" bp[i] = 1;\n",
" else:\n",
" bp[i] = -1;\n",
"\n",
"Vd = zeros(9)\n",
"#Let initial value of Vd be 0\n",
"#Vd = 0;\n",
"for i in range(1,9):\n",
" Vd[i] = bp[i] + bp[i-1]\n",
"\n",
"da = zeros(9)\n",
"#Converting polar signal to bit code we get, -2 --> 0, 0 --> 1, 2 --> 0\n",
"for i in range(9):\n",
" if Vd[i] == -2:\n",
" da[i] = 0;\n",
" elif Vd[i] == 2:\n",
" da[i] = 0;\n",
" else:\n",
" da[i] = 1;\n",
"\n",
"print 'Decoded output when precoded is ',da\n",
"\n",
"################################################################################\n",
"\n",
"#When not precoded exor gate is not there\n",
"dp = zeros(9)\n",
"#Changing bit code to polar signal we get, 0 --> -1, 1 --> +1\n",
"for i in range(9): \n",
" if d[i] == 1:\n",
" dp[i] = 1;\n",
" else:\n",
" dp[i] = -1;\n",
"\n",
"for i in range(1,9):\n",
" Vd[i] = dp[i] + dp[i-1]\n",
"\n",
"\n",
"#Converting polar signal to bit code we get, -2 --> 0, 0 --> 1, 2 --> 1\n",
"for i in range(1,9):\n",
" if Vd[i] == -2:\n",
" da[i] = 0;\n",
" elif Vd[i] == 2:\n",
" da[i] = 0;\n",
" else:\n",
" da[i] = ~int(da[i-1]);\n",
"\n",
"print 'Decoded output when not precoded is ',da"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Decoded output when precoded is [ 1. 1. 1. 1. 0. 1. 0. 1. 1.]\n",
"Decoded output when not precoded is [ 1. -2. 0. 0. -1. 0. -1. 0. 0.]\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 6.6 Page No : 381"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math \n",
"\n",
"#Given Bandwidth BW = 4 kHz\n",
"BW = 4*10**3;\n",
"\n",
"#Given data rate is fb = 6 kbps\n",
"fb = 6*10**3;\n",
"\n",
"#The roll off factor alpha is \n",
"alpha = ((2*BW)/fb) - 1;\n",
"\n",
"print 'The roll off factor is ',alpha;\n",
"\n",
"#######################################/\n",
"\n",
"#The required data rate supported at alpha = 0.25 is D\n",
"alpha = 0.25\n",
"\n",
"#The corresponding expression for D is\n",
"D = (2*BW)/(1+alpha);\n",
"\n",
"print 'The supported data rate is ',D,' kbps'\n",
"\n",
"#For full roll-off alpha = 1.0, \n",
"alpha = 1;\n",
"\n",
"fb = 2*BW/(1+alpha);\n",
"\n",
"print 'The data rate is ',fb,' kbps'\n",
"\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The roll off factor is 0\n",
"The supported data rate is 6400.0 kbps\n",
"The data rate is 4000 kbps\n"
]
}
],
"prompt_number": 20
}
],
"metadata": {}
}
]
}