#Variable declaration
Fm=20; # in KHz
#Calculations
print "An Engineering version of the Nyquist sampling rate : fs>=2.2*fm."
print 'Therefore sampling rate of >= %d ksps should be used '%(2.2*Fm);
print "The sampling rate for a compact disc digital audio player = 44.1 ksps and for a studio quality audio player = 48 ksps are used."
import math
#Variable declaration
Rt=1; #Resistance(ohm)
#L= Number of quantization values
L1=32;
L2=64;
L3=128;
L4=256;
#Calculations
# L=2**R i.e R=math.log2(L);
R1=math.log(L1,2);
R2=math.log(L2,2);
R3=math.log(L3,2);
R4=math.log(L4,2);
#P=A**2/2; #average power of signal
#sig**2=0.333*A**2*2**(-2*Rt); #Avg quantization noise power
#SNR=P/sig**2;
# SNR(dB)=1.8+ 6R;
SNR1=1.8+6*R1;
SNR2=1.8+6*R2;
SNR3=1.8+6*R3;
SNR4=1.8+6*R4;
#Result
print 'For L=32, SNR is %.1f dB\n '%SNR1
print 'For L=64, SNR is %.1f dB\n '%SNR2
print 'For L=128, SNR is %.1f dB\n '%SNR3
print 'For L=256, SNR is %.1f dB\n '%SNR4
#Variable declaration
Fs=8*10**3; #in Hz
Fm=3.4*10**3; # in Hz
VCH=24; #voice channels
SCH=1; #sunchronization channel
PDur=1; #extra pulse duration in microsec
#Calculations&Results
Ts=1/(Fs);
TimeCH=Ts/(VCH+SCH)*10**6; # in microsec
print 'Time between the pulses is %d microsec\n'%(TimeCH-PDur);
#Now by using the engineering version of Nyquist rate sampling
NyquistRate=2.2*Fm;
Ts1_microsec=1/NyquistRate*10**6;
Tc=round(Ts1_microsec)/(VCH+SCH);
print "Time between the pulses by using engineering version of Nyquist rate sampling is %.2f microsec\n"%(Tc-PDur);
import math
#Variable declaration
Fm=3000; #highest modulating frequency in signal(Hz)
M=32; # number of pulse levels
b=5; #bits per symbol
p=0.01; #Quantization distortion
#Calculations
#2**R = L >= 1/2P
# where R is the number of bits required to represent quantization levels L
R=math.log10(1./(2*p))/math.log10(2);
Fs=2*Fm; # Nyquist sampling criteria (samples per second)
fs=round(R)*Fs;
Rs=fs/b;
#Result
print 'The minimum number of bits/sample or bits/PCM word that should be used are %d'%(round(R));
print 'The minimum sampling rate is %d samples per second\n '%Fs;
print 'The resulting transmission rate is %d bps\n '%fs;
print 'The PCM pulse or symbol transmission rate is %d symbols/sec\n'%Rs
import math
#Variable declaration
S_No=53.; #dB-Hz
R=9.6*10**3; #bps
BW=4.8*10**3; #Khz
Pb=10**-5; #BER<=10**-5;
#Calculations
print "Since the required data rate of 9.6 kbps is more than the available bandwidth of 4.8 kHz, the channel is bandwidth-limited."
Eb_No=S_No-10*math.log10(R); #dB
# Try for 8-PSK modulation scheme
M=8;
Ps=math.log(M,2)*Pb; #Max ps
Es_No=math.log(M,2)*10**(0.1*Eb_No);
#Ps(8)=2*Q(math.sqrt(2*Es_No)*sin(math.pi/8));
#2*Q(math.sqrt(2*Eb_No))=erfc(math.sqrt(Eb_No)); #Refer EQn C(7) from appendix C
Ps8=math.erfc(math.sqrt(Es_No)*math.sin(math.pi/8));
#Result
print 'Symbol error rate is given as %.5f \n '%Ps
print 'The ratio of signal energy to noise is %.2f \n '%Es_No;
print 'Symbol error rate for 8-PSK is %.5f \n '%Ps8;
print "As symbol error rate for 8-PSK modulation is lower than threshold value. so, We can use 8-PSK modulation."
import math
#Variable declaration
SNR=48.; #dB-Hz
BW=45.*10**3; #in Hz
R=9.6*10**3; #bps
Pb=10**-5; #Bit error rate
e=2.71828; #Natural exponent e
#Calculations&Results
print "since the available bandwidth of 45 kHz is more than adequate to support the required data rate of 9.6 kbps.";
print "So, the channel is not bandwidth limited ";
Eb_No=SNR-10*math.log10(R);
#We try the 16-FSK modulation scheme
M=16;
Es_No=math.log(M,2)*Eb_No;
Ps=(M-1)/2*e**(-Es_No/2);
#For orthogonal signalling
Ps16=(2**M-1)/(2**(M-1))*Pb;
print ""
print 'The maximum symbol error probability is %0.5f \n '%Ps16
print 'The symbol error probability achieved by 16-PSK is %.9f \n '%Ps;
print "As achieved symbol error probability is far less than maximum tolerable value";
print "So, we can meet the given speciļ¬cations for this power-limited channel with a 16-FSK modulation scheme without any error-correction coding"