# Chapter 5 : Pulse Modulation and Digital Transmission of Analog Signal¶

## Example 5.2 Page No : 247¶

In :
import math
#page 247
#problem 5.2

#Highest frequency(fH)  =  10000/2  =  5000 Hz
fH  =  5000.
#Lowest frequency(fL)  =  6000/2  =  3000 Hz
fL  =  3000.
#Minimum sampling frequency from low pass consideration(S_LOW)  =  2*fH
S_LOW  =  2*fH

print 'Minimum sampling frequency from low pass consideration is ',S_LOW,' Hz'

#B  =  fH-fL  =  2000 Hz
B  =  fH-fL
#k  =  floor(fH/B)  =  2, where floor(x) gives the largest integer that does not exceed x
k  =  math.floor(fH/B)

#The required sampling frequency from band pass consideration(S_BAND)  =  2*fH/k
S_BAND  =  2*fH/k

print 'Minimum sampling frequency from band pass consideration is ',S_BAND,' Hz'

Minimum sampling frequency from low pass consideration is  10000.0  Hz
Minimum sampling frequency from band pass consideration is  5000.0  Hz


## Example 5.3 Page No : 259¶

In :
import math
#page 259
#problem 5.3

#Given width of each pulse W  =  150 us
W  =  150. * 10**-6

#One cycle is a period,T  =  1ms
T  =  1000. * 10**-6

#There are 5 messages multiplexed each utilizeallocated time pulse width  =  s(T_5)  =  T/5
T_5  =  T/5

#Gaurd time(GT_5)  =  allocated time-pulse width  =  T_5-W
GT_5  =  T_5-W

print 'Gaurd time where 5 messages multiplexed is ',GT_5,' seconds'

#Here there are 10 messages multiplexed each utilizeallocated time pulse width  =  s(T_10)  =  T/10
T_10  =  T/10

#Gaurd time(GT_10)  =  allocated time-pulse width  =  T_10-norrow pulses width  =  T_10 -50* 10**-6
GT_10  =  T_10 - 50 * 10**-6

print 'Gaurd time where 10 messages multiplexed is ',GT_10,' seconds'

Gaurd time where 5 messages multiplexed is  5e-05  seconds
Gaurd time where 10 messages multiplexed is  5e-05  seconds


## Example 5.5 Page No : 272¶

In :
import math

#Let Abe the maximum value of the discrete samples.
#Error tolerated is 0.1% i.e. 0.001A
#If D is step size then possible maximum error is D/2
#Thus D/2  =  0.001A or A/D  =  500  =  no of levels required(Levels)
Levels  =  500.

#minimum no of binary digits required(B)  =  rounded value to the next higher integer of math.log2 (Levels)
B  =  round(math.log(Levels))

print 'Minimum no of binary digits required ',B

Minimum no of binary digits required  6.0


## Example 5.6 Page No : 273¶

In :
import math

#The y axis is uniformly quantized with step size(step_size)  =  1/((2**8)/(2-1)) in both +ve & -ve direction between 1 & -1 when peak of input varies between 1 & -1.
#The smallest step in x direction occurs nearest to x = 0 i.e between y1  =  0 & y2  =  step_size
step_size  =  1./((2**8)/2-1)
y1  =  0.
y2  =  step_size

#Then, y1  =  (ln(1+255*x1))/(ln(1+255))

x1  =  (math.e**(y1*math.log(256)) - 1)/255;

#y2  =  (ln(1+255*x2))/(ln(1+255))
x2  =  (math.e**(y2*math.log(256)) - 1)/255;

#The smallest step size is 10*(x2-x1)
print 'The smallest step size is ',round(10*(x2-x1),4),' Volts'

#The largest step size occurs when x is at its extreme between y1  =  1-1/127  =  126/127 & y2  =  1
y1  =  1-1/127.
y2  =  1

#Then, y1  =  (ln(1+255*x1))/(ln(1+255))

x1  =  (math.e**(y1*math.log(256)) - 1)/255;

#y2  =  (ln(1+255*x2))/(ln(1+255))
x2  =  (math.e**(y2*math.log(256)) - 1)/255;

#The largest step size is 10*(x2-x1)
print 'The largest step size is ',round(10*(x2-x1),4),' Volts'

The smallest step size is  0.0018  Volts
The largest step size is  0.4289  Volts


## Example 5.9 Page No : 296¶

In :
import math
from numpy import zeros

#for error calculation e(n)  =  m(n) - [**hj(n)*m(n-1)+**hj(n)*m(n-2)+**hj(n)*m(n-3)+ ........+**hj(n)*m(n-N)]

#for coefficient upgradation **hj(n+1)  =  **hj(n)+um(n-j)e(n) where u  =  learning parameter  =  0.1.
u  =  0.1

#Assign m values taking from m  =  -3 to 5
#Denoting m(x) as matrix m where each element repesents from n  =  -3 to 5
m  =  [0, 0, 0, 1, 2, 3, 4, 5, 6]

#taking e(n) as matrix e, **hj(n) as matrises h_j
e  =  zeros(5)
h_1  =  zeros(6)
h_2  =  zeros(6)

#given **h1(0) =  **h2(0)  =  0

for i  in range(5):
e[i]  =  m[i+3] - h_1[i]*m[i+2] - h_2[i]*m[i+1]
h_1[i+1]  =  h_1[i] + u*m[i+2]*e[i]
h_2[i+1]  =  h_2[i] + u*m[i+1]*e[i]

#here e(3) is given as 1.32 but it is print laying 0.92
#here **h2(3) is given as 0.26 but it is print laying 0.46

for i  in range(5):
print 'e(',i,')  =  ',e[i],
print '**h1(',i,')  =  ',h_1[i+1],
print '**h2(',i,')  =  ',h_2[i+1]

e( 0 )  =   1.0 **h1( 0 )  =   0.0 **h2( 0 )  =   0.0
e( 1 )  =   2.0 **h1( 1 )  =   0.2 **h2( 1 )  =   0.0
e( 2 )  =   2.6 **h1( 2 )  =   0.72 **h2( 2 )  =   0.26
e( 3 )  =   1.32 **h1( 3 )  =   1.116 **h2( 3 )  =   0.524
e( 4 )  =   -1.036 **h1( 4 )  =   0.7016 **h2( 4 )  =   0.2132


## Example 5.11 Page No : 296¶

In :
import math

#case 1(a)
#f  =  400Hertz, fs  =  8000Hertz
f  =  400.
fs  =  8000.

#We know that maximum signal to noise ratio(SNR_max)  =  3*(fs**2)/(8*(pi**2)*(f**2))
SNR_max  =  3*(fs**2)/(8*(math.pi**2)*(f**2))
#SNR_max in decibels is SNR_max_db
SNR_max_db  =  10*math.log10 (SNR_max)

print 'Maximum signal to noise ratio for f  =  400 & fs  =  8000 is %.4f'%SNR_max,'  =  %.4f'%SNR_max_db,' db'

#case 1(b)
#f  =  400Hertz, fs  =  16000Hertz
f  =  400.
fs  =  16000.

#We know that maximum signal to noise ratio(SNR_max)  =  3*(fs**2)/(8*(pi**2)*(f**2))
SNR_max  =  3*(fs**2)/(8*(math.pi**2)*(f**2))

#SNR_max in decibels is SNR_max_db
SNR_max_db  =  10*math.log10 (SNR_max)

#Given solution is 13.8385 dB obtained solution is 17.838515 dB

print 'Maximum signal to noise ratio for f  =  400 & fs  =  16000 is %.4f'%SNR_max,'  =  %.4f'%SNR_max_db,' db'

#case 2(a)
#f  =  400Hertz, fs  =  8000Hertz & fc  =   1000Hertz
f  =  400.
fs  =  8000.
fc  =  1000.

#If a 1kHz low pass post reconstruction filter is used then maximum signal to noise ratio(SNR_max)  =  3*(fs**3)/(8*(pi**2)*(f**2)*fc)
SNR_max  =  3*(fs**3)/(8*(math.pi**2)*(f**2)*fc)
#SNR_max in decibels is SNR_max_db
SNR_max_db  =  10*math.log10 (SNR_max)

print ('If a 1kHz low pass post reconstruction filter is used then')

print 'Maximum signal to noise ratio for f  =  400, fs  =  8000 & fc  =  1000 is %.4f'%SNR_max,'  =  %.4f'%SNR_max_db,' db'

#case 2(b)
#f  =  400Hertz, fs  =  16000Hertz & fc  =   1000Hertz
f  =  400.
fs  =  16000.
fc  =  1000.

#If a 1kHz low pass post reconstruction filter is used then maximum signal to noise ratio(SNR_max)  =  3*(fs**3)/(8*(pi**2)*(f**2)*fc)
SNR_max  =  3*(fs**3)/(8*(math.pi**2)*(f**2)*fc)
#SNR_max in decibels is SNR_max_db
SNR_max_db  =  10*math.log10 (SNR_max)

print 'Maximum signal to noise ratio for f  =  400, fs  =  16000 & fc  =  1000 is %.4f'%SNR_max,'  =  %.4f'%SNR_max_db,' db'

Maximum signal to noise ratio for f  =  400 & fs  =  8000 is 15.1982   =  11.8179  db
Maximum signal to noise ratio for f  =  400 & fs  =  16000 is 60.7927   =  17.8385  db
If a 1kHz low pass post reconstruction filter is used then
Maximum signal to noise ratio for f  =  400, fs  =  8000 & fc  =  1000 is 121.5854   =  20.8488  db
Maximum signal to noise ratio for f  =  400, fs  =  16000 & fc  =  1000 is 972.6834   =  29.8797  db