我正在实现IEEE 802.16d模型,以预测Python中的路径损耗
我创建了2个单独的文件:一个是包含IEEE模型函数的库,另一个是将要调用函数的主代码
lib文件中的代码:
def PL_IEEE_80216d(fc,d,Type,htx,hrx,corr_fact,mod=False):
'''
IEEE 802.16d model
Inputs:
fc: Carrier frequency [Hz]
d: Distance between transmitter and receiver station [m]
htx: Height of transmitter [m]
hrx: Height of receiver [m]
corr_fact: Correlation coefficient
mod: Modified [True/False]
'''
PL=[]
lambda = 3.10e8/fc
d0=100
if(Type == 'A'):
a=4.6;b=0.0075;c=12.6
elif(Type == 'B'):
a=4;b=0.0065;c=17.1
elif(Type == 'C'):
a=3.6;b=0.005;c=20
else:
a=0;b=0;c=0
if(corr_fact == 'AT&T'):
if( Type == 'A' or Type == 'B'):
C_rx = -10.8 * log10(hrx/2)
else:
C_rx = -20 * log10(hrx/2)
elif(corr_fact == 'OKUMURA'):
if(hrx <= 3):
C_rx = -10 * log10(hrx/3)
else:
C_rx = -20 * log10(hrx/3)
else:
C_rx = 0
gamma=a-b*htx+c/htx
Cf=6*log10(fc/2000)
if(mod == True):
d0_pr = d0 * 10 **(-(Cf+C_rx)/(10*gamma))
else:
d0_pr = d0
A = 20 * log10(4*pi*d0_pr/lambda)+Cf+C_rx
for i in range(0,len(d)):
print('i=%d'%i)
if(d[i] > d0_pr):
PL[i]=A+10*gamma*log10(d[i]/d0)
else:
PL[i]=20*log10(4*pi*d[i]/lambda)
PL = PL.append(P[i])
return PL
我的主要代码:
from model_lib import *
import matplotlib.pyplot as plt
fc=2e9
htx=[30,30]
hrx=[2,10]
distance=arrange(1,3) #2 distance=[1,2] => d[0]=1,d[1]=2
print("length of distance is %d"%len(distance))
for k in range(0,2):
print('k=%d'%k)
y_IEEE16d[k]=PL_IEEE_80216d(fc,distance,'A',htx[k],hrx[k],'AT&T')
但是,当我运行代码时,出现错误:
列表分配索引超出范围
尽管我已经尝试了很多次,但我不知道它超出了范围。
答案 0 :(得分:0)
由于已将PL初始化为空列表,因此无法使用PL [i]。
请改用append函数。 PL.append(...)