-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlora_tools.py
More file actions
130 lines (95 loc) · 2.5 KB
/
lora_tools.py
File metadata and controls
130 lines (95 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This library contains useful lora and radio related functions
import numpy as np
# The log-distance model
# Lpl = Lpld0 + 10*gamma*log10(d/d0) + X_normal
# model paramaters are initialized to NaNs to ensure they're setup befor being used
Lpld0 = np.nan
d0 = np.nan
gamma = np.nan
var = np.nan
GL = np.nan
def dBmtomW(pdBm):
"""[summary]
[description]
Arguments:
pdBm {[type]} -- [description]
Returns:
[type] -- [description]
"""
pmW = 10.0**(pdBm/10.0)
return pmW
def dBmtonW(pdBm):
"""[summary]
[description]
Arguments:
pdBm {[type]} -- [description]
Returns:
[type] -- [description]
"""
pnW = 10.0**((pdBm+90.0)/10.0)
return pnW
def getRXPower(pTX, distance):
"""[summary]
[description]
Arguments:
pTX {[type]} -- [description]
distance {[type]} -- [description]
Returns:
[type] -- [description]
"""
# get ideal RX power estimate assuming log-distance model
pRX = pTX - Lpld0 - 10.0*gamma*np.log10(distance/d0)
return pRX
def getTXPower(pRX, distance):
"""[summary]
[description]
Arguments:
pRX {[type]} -- [description]
distance {[type]} -- [description]
Returns:
[type] -- [description]
"""
# get ideal TX power estimate assuming log-distance model
pTX = pRX + Lpld0 + 10.0*gamma*np.log10(distance/d0)
return pTX
def getDistanceFromPL(pLoss):
"""[summary]
[description]
Arguments:
pLoss {float} -- path loss in dBm
Returns:
float -- distance the signal must travel for given path loss
"""
d = d0*(10.0**((pLoss-Lpld0)/(10.0*gamma)))
return d
def getDistanceFromPower(pTX, pRX):
"""[summary]
[description]
Arguments:
pTX {[type]} -- [description]
pRX {[type]} -- [description]
Returns:
[type] -- [description]
"""
return getDistanceFromPL(pTX - pRX)
def getFreqBucketsFromSet(BSFreqSetList):
"""[summary]
This function gives a list of frequencies for various bandwidths used by
our base-stations. This is currently only applicable to the US 902-928 +
white space specifications. Other regions would need their own functions
Arguments:
BSFreqSetList {[type]} -- [description]
Returns:
[type] -- [description]
"""
freqSetList = np.unique(BSFreqSetList)
freqBuckets = set()
for i in freqSetList:
if i < 8:
freqBuckets.update(np.linspace(902300 + 200*8*i, 903700 + 200*8*i, 8, dtype=int))
else:
# assuming channel 5 is used for white spaces
freqBuckets.update(np.linspace(72100 + 200*8*(i-8), 73700 + 200*8*(i-8), 8, dtype=int))
return freqBuckets