def reldist_linpol(tx_soa, beacon_soa):
# Interpolate between two nearest beacon samples
beacon_rx0, beacon_rx1 = beacon_soa[:, 0], beacon_soa[:, 1]
tx_rx0, tx_rx1 = tx_soa[:, 0], tx_soa[:, 1]
high_idx = np.searchsorted(beacon_rx0, tx_rx0)
low_idx = high_idx - 1
length = len(beacon_soa[:, 0])
if high_idx[-1] >= length:
high_idx[-1] = length - 1
if low_idx[0] < 0:
high_idx[0] = 0
weight = ((tx_rx0 - beacon_rx0[low_idx]) /
(beacon_rx0[high_idx] - beacon_rx0[low_idx]))
weight[np.isinf(weight)] = 1 # remove nan
# Reldist in samples
reldist = (tx_rx1 - (beacon_rx1[low_idx] * (1-weight) +
beacon_rx1[high_idx] * weight)) # / 2.0
return reldist
评论列表
文章目录