-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtypes.go
125 lines (105 loc) · 3.57 KB
/
types.go
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
// CM implements the functions & types for implementation of Channel models in 38-901-e00
package CM
import (
"fmt"
"math"
"math/rand"
clr "github.com/fatih/color"
"github.com/wiless/vlib"
)
// // dist3D returns the 3D distance between two Nodes considering d_out & d_in as in Eq. 7.4.1
// func dist3D(src, dest deployment.Node) (d float64) {
// d3d:=dest.Location.DistanceFrom(src)
//
// }
const C float64 = 3.0e8 // Speed of light
var DEFAULTERR_PL float64 = 99999
type TestEnv int
const (
RMA TestEnv = iota
UMA
UMi
Inh
)
func (te TestEnv) String() string {
return [...]string{"RMa", "UMa", "UMi", "InH"}[te]
}
var msqrt = math.Sqrt
var mlog = math.Log10
var mpow = math.Pow
var max = math.Max
var mexp = math.Exp
const pi = math.Pi
func IndB(v float64) string {
return fmt.Sprintf("%.3f%s", v, clr.CyanString("dB"))
}
func InGHz(v float64) string {
return fmt.Sprintf("%.3f%s", v, clr.GreenString("GHz"))
}
func Inmtrs(v float64) string {
return fmt.Sprintf("%.3f%s", v, clr.GreenString("m "))
}
type Frequency float64
func (f *Frequency) fromGHz(fghz Frequency) Frequency {
*f = 1.0e9 * fghz
return *f
}
func (f *Frequency) GHz(fghz Frequency) {
*f = 1.0e-9 * fghz
}
type PLModel interface {
Init(fGHz float64)
IsSupported(fGHz float64) bool
PLbetween(node1, node2 vlib.Location3D) (plDb float64, isNLOS bool, err error)
PLbetweenIndoor(node1, node2 vlib.Location3D, dIn float64) (plDb float64, isLOS bool, err error)
IsLOS(dist float64) bool /// Given a distance returns LoS or NLOS statistical (it need not always return same value)
PLnlos(dist float64) (plDb float64, e error)
PLlos(dist float64) (plDb float64, e error)
PL(dist float64) (plDb float64, isNLOS bool, err error)
O2ILossDb(fGHz float64, d2Din float64) (o2ilossdB float64)
O2ICarLossDb() float64 // returns the Loss between O2I inside a Car
Env() string // Return the name of the environment e.g RMa, UMa, InH , allows custom implementations
IsShadowLoss() bool // Returns if shadowloss need to be added
}
// EvaluatePL returns the pathloss values for all the distances for the frequency, when fGHz or dist is not Supported, it returns error and corresponding values with DEFAULTERR_PL=99999 (not communicatable channel)
func EvaluatePL(pm *PLModel, fGHz float64, dists ...float64) {
}
// https://wikimedia.org/api/rest_v1/media/math/render/svg/2748541aa04938707a3d25923da2290f4d32ab59
func FreeSpace(dmtrs float64, fGHz float64) (plDb float64) {
// return 20*mlog(dmtrs) + 20*mlog(fGHz*1e9) - 27.55
// return 20*mlog(dmtrs) + 20*mlog(fGHz)+20*mlog(1e9)-147.55
return 20*mlog(dmtrs) + 20*mlog(fGHz) + 32.45
}
// O2ICarLossDb returns the Car penetration loss in dB
// Ref M.2412 Section 3.3 μ = 9, and σP = 5
func O2ICarLossDb() float64 {
// μ = 9, and σP = 5
mean := 9.0
sigmaP := 5.0
return rand.NormFloat64()*sigmaP + mean
}
// All loss below are in dB
func Lglass(fGHz float64) float64 {
return 2 + 0.2*fGHz
}
func LIRRglass(fGHz float64) float64 {
return 23 + 0.3*fGHz
}
func Lconcrete(fGHz float64) float64 {
return 5 + 4*fGHz
}
func Lwood(fGHz float64) float64 {
return 4.85 + 0.12*fGHz
}
// RandLogNorm returns a log-normal distributed random variable
// with mean = u and std-devation = sigma
func RandLogNorm(meanDb float64, sigmaDb float64) float64 {
// m := meanDb
// v := sigmaDb * sigmaDb // mean and variance of Y
// phi := msqrt(v + m*m)
// mu := mlog(m * m / phi) // mean of log(Y)
// sigma := msqrt(mlog(phi * phi / (m * m))) // std dev of log(Y)
// result := mexp(mu + sigma*rand.Float64())
result := mexp(meanDb + sigmaDb*rand.Float64())
return result
}