#Variable declaration
Area=8; #in km^2
Cover=4000.;# in km^2
CallBH=1.2; #Avg calls during BH
HT=100; # Avg holding time in sec
Block=0.02; #Blocking=2%
N=4.;#Frequency reuse factor
Spectrum=12.5;# in MHz
CHBW=200;# in kHz
User_CH=8;#No of users per RF channel
#Calculations&Results
RFCH=Spectrum*1000/CHBW;
TCH=int(RFCH)*User_CH;
SigCH=3;#No of signalling channels per cell
TCH_cell=TCH/N-SigCH;
Cells=Cover/Area;
OffLoad=108.4; # in Erlangs
print 'Using Erlang-B Tables, Total traffic offered by %d channels at 0.02 blocking = %.1f Erlangs/cell'%(TCH_cell,OffLoad*(1-Block));
CarLoad=OffLoad*(1-Block);
Calls_hr_cell=CarLoad*3600/HT;
MaxUser_hr_cell=Calls_hr_cell/CallBH;
Seff=CarLoad*Cells/(Spectrum*Cover);
print 'Spectral Efficiency is %.2f Erlangs/MHz/km^2'%Seff;
#Variable declaration
TCH=395; # Traffic Channels
SysBW=12.5; #in MHz
CHspace=30.; # in kHz
#Calculations
Eff=TCH*CHspace/(SysBW*1000);
#Result
print 'Multiple access spectral efficiency of FDMA System is %.3f'%Eff
#Variable declaration
Tf=40; #Frame duration in msec
Mt=6; # Frames per slot
Bu=30; #bandwidth(KHz) of an individual user during his or her time slot
Nu=395.;# number of users sharing the same time slot in the system, but having access to different frequency sub-bands
Bw=12.5; # in MHz
DR=16.2;#Data rate in kbps
FDur=40.; # Frame duration in msec
slots=6; #No of slots per time frame
IndiRate=16.2; #Individual data rate in kbps
Srate=13.; #Speech rate in kbps
#Calculations
TimeSlot=(Srate/IndiRate)*(FDur/slots);
Seff=TimeSlot*slots*Bu*Nu/(FDur*Bw*1000);
#Results
print 'Multiple access spectral efficiency of TDMA is %.2f'%Seff;
print 'The overhead portion of the frame is %d percent'%((1-Seff)*100);
#Variable declaration
nb=0.9; #BW efficiency factor
u=2; # Bit Efficiency with QPSK
Vf=1; # Voice activity factor
BW=12.5; #in MHz
IR=16.2; # in kbps
N=19; #frequency reuse factor
#Calculations
Nu=nb*u*BW*1000/(Vf*IR*N);# number of channels (mobile users) per cell
Seff=int(Nu)*IR/(BW*1000);
#Results
print 'Capacity of system is %d mobile users per cell'%Nu;
print 'Spectral efficiency of TDMA system is %.3f bit/sec/Hz'%Seff
#Variable declaration
Nr=2.;# number of reference bursts per frame
Nt=24; # number of traffic bursts (slots) per frame(120msec)
FL=120; #Frame length in msec
Br=148; # number of overhead bits per reference burst
Bp=34; # number of overhead bits per preamble per slot
Bg=8.25;#number of equivalent bits in each guard time interval
Tf=120; # frame duration in msec
Rrf=270.83333333; # bit rate of the RF channel in kbps
R=22.8; #bit rate of each channel in kbps
#Calculations
B0=Nr*(8*Br)+Nt*(8*Bp)+(Nt+Nr)*(8*Bg);#The number of overhead bits per frame
Bt=FL*10**-3*Rrf*10**3;#The total number of bits per frame
Eff=(1-B0/Bt)*100;
CH_Frame=(Eff/100)*Rrf/R;#No of channels/frame
#Results
print 'The frame efficiency is %.2f percent'%Eff;
print 'Number of channels/frame are %d'%(CH_Frame)
#Variable declaration
nb=0.9;#bandwidth efficiency
nf=0.45;#frequency reuse efficiency
Cd=0.8; #capacity degradation factor
Vf=0.4;#voice activity factor
Eb_I0=7; # desired energy-to-interference ratio in dB
L=1;# efficiency of sector-antenna in cell
BW=12.5;#One way system BW in MHz
R=16.2;#Information rate in kbps
#Calculations
Eb_I=10**(Eb_I0*0.1);#To convert from dB to a normal value
Nu=(nf*nb*Cd*L/Vf)*(BW*1000/(Eb_I*R));#Capacity of system
Seff=round(Nu)*R/(12.5*10**3);
#Results
print 'Capacity of system is %d mobile users per cell'%round(Nu);
print 'Spectral efficiency of TDMA system is %.3f bits/sec/Hz'%Seff;
#Variable declaration
#Given Data from Exa 6.4 and Exa 6.6
Cd=0.8; #capacity degradation factor
R=16.2;#Data rate in kbps
Eb_I0=7; #in dB
Eb_I=10**(Eb_I0*0.1);#To convert from dB to a normal value
Vf=0.4;#voice activity factor
u=2; # Bit Efficiency
IR=16.2; # in kbps
N=19; #frequency reuse factor
nf=0.45;#frequency reuse efficiency
#Calculations
Ncdma_by_Ntdma=Cd*N*nf*IR/(Eb_I*Vf*u*R);
#Result
print 'The ratio of capacity of DS-CDMA to TDMA is %.3f'%Ncdma_by_Ntdma
import math
#Variable declaration
Bss=600; #Hopping bandwidth in MHz
stepsize=400; # in Hz
#Calculations
No_of_Tones=Bss*10**6/stepsize;
Min_chips_required=math.log(No_of_Tones,2);
#Result
print 'Minimum number of chips required are %d chips'%Min_chips_required
#Variable declaration
e=2.71828; #Euler's number
Tprop=0.4; #Max propogation delay in sec
R=10; #data rate in Mbps
PackLen=400; #packet length in bits
#Calculations
Tp=PackLen/R; #packet transmission time in microsec
a=Tprop/Tp;
G=Tp*10**-6*R*10**6/PackLen;#normalized offered traffic load
#Slotted nonpersistent
S0=a*G*e**(-a*G)/(1-e**(-a*G)+a);#normalized throughput
#Unslotted nonpersistent
S1=G*e**(-a*G)/(1+(2*a)+e**(-a*G));#normalized throughput
#Slotted 1-persistent
S2=G*e**(-G*(1+a))*(1+a-e**(-a*G))/((1+a)*(1-e**(-a*G))+a*e**(-G*(1+a)));#normalized throughput
#Results
print 'The Normalized throughput with an unslotted non persistent,a slotted persistent and a slotted 1-persistent CSMA protocol are \n %.3f,%.3f and %.3f respectively'%(S0,S1,S2);
#Variable declaration
Tprop=4; #maximum propogation delay in sec
R=10; # data rate in Mbps
PackLen=400.; #data packet length in bits
ACK=20; #length of ACK packet in bits
Tproc=1; #processing time(sec)
p=0.01;#probability that a data packet or its ACK can be corrupted during transmission
#Calculations
Tp=PackLen/R; #packet transmission time in microsec
Ta=ACK/R; # transmission time for an ACK in microsec
T=Tp+2*Tprop+2*Tproc+Ta;# total time for transmission time
# Stop and wait ARQ
Eff0=(1-p)*Tp/((1-p)*T+p*Tp);
#SRP with window size W=8
W=8;
Eff1=(2+p*(W-1))/(2+p*(3*W-1));
#Go-Back-N protocol with window size W=8
Eff2=1./(1+W*(p/(1-p)));
#Results
print 'The data link protocol efficiency with Stop and Wait protocol, SRP and GBN are \n %.3f, %.3f abd %.3f respectively'%(Eff0,Eff1,Eff2);