-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcapacityBanner.js
More file actions
148 lines (132 loc) · 4.24 KB
/
Copy pathcapacityBanner.js
File metadata and controls
148 lines (132 loc) · 4.24 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* The `CapacityBanner` function creates a banner that displays various signal parameters and calculations
* related to capacity and efficiency, such as Signal-to-Noise Ratio (SNR), information capacity, spectral
* efficiency, link margin, and actual data rate.
*
* @param {Object} sig - A signal object containing properties related to signal characteristics, such as
* signal-to-noise ratio (SNR), bandwidth, modulation scheme (MCS), and data rate. These properties are used
* within the function to calculate and display various capacity metrics.
* @param {HTMLElement|string|null} [parentElement=null] - Specifies the parent element where the banner content
* will be appended. If not provided, a new `<p>` element is created and appended to the `<body>` by default.
* @returns {HTMLElement} A dynamically created HTML element that displays various signal parameters, such as
* SNR, information capacity, spectral efficiency, link margin, and actual rate. These values are calculated
* based on the input signal object and are updated using the `Label` function as needed.
*/
function CapacityBanner(sig, parentElement = null) {
var id = (CapacityBanner.count++).toString() + "_cap";
var innerHTML =
"\
<label for=signal_to_noise_ratio" +
id +
">" +
sig.snrLabel +
": </label>\
<output for=signal_to_noise_ratio" +
id +
" id=snr" +
id +
"></output>,\
<label for=information_capacity" +
id +
">Capacity: </label>\
<output for=information_capacity" +
id +
" id=cap" +
id +
"></output>,\
<label for=spectral_efficiency" +
id +
">Spect. Eff.: </label>\
<output for=spectral_efficiency" +
id +
" id=eta" +
id +
"></output>,\
<label for=link_margin" +
id +
">Link Margin: </label>\
<output for=link_margin" +
id +
" id=margin" +
id +
"></output>,\
<label for=actual_rate" +
id +
">Actual Rate: </label>\
<output for=actual_rate" +
id +
" id=rate" +
id +
"></output>\
";
function getElement(sel) {
return document.querySelector(sel + id);
}
if (parentElement === null) {
parentElement = document.createElement("p");
document.body.appendChild(parentElement);
} else if (typeof parentElement === "string") {
parentElement = document.querySelector(parentElement);
}
parentElement.innerHTML = innerHTML;
Label(sig, "sinr", { element: "#snr" + id });
Label(sig, "sinr", {
func: function (sinr) {
// sinr is SNR in dB
let C = sig.bw * Math.log2(1 + Math.pow(10.0, sinr / 10));
let [scale, units] = scale_units(C, 0.1);
return d3.format(".1f")(C * scale) + " " + units + "b/s";
},
element: "#cap" + id,
});
Label(sig, "sinr", {
func: function (sinr) {
// sinr is SNR in dB
let se = Math.log2(1 + Math.pow(10.0, sinr / 10.0));
return d3.format(".3f")(se) + " b/s/Hz";
},
element: "#eta" + id,
});
// This Label trigger a change from 2 signal parameters.
var margin = getElement("#margin");
Label(sig, ["sinr", "mcs"], {
func: function () {
// sig.sinr is SNR in dB
let m = sig.sinr - conf.schemes[sig.mcs].SNR;
if (m <= 0) margin.className = "red";
else margin.className = "";
return d3.format(".2f")(m) + " dB";
},
element: "#margin" + id,
});
// This Label triggers a change from 2 signal parameters.
var rate = getElement("#rate");
Label(sig, ["sinr", "mcs"], {
func: function () {
let r = sig.rate;
if (r <= 0) {
rate.className = "red";
return "0 b/s";
}
rate.className = "";
let [scale, units] = scale_units(r, 1.0);
let percent =
(100.0 * r) / (sig.bw * Math.log2(1 + Math.pow(10.0, sig.sinr / 10.0)));
if (percent > 100) {
rate.className = "red";
return "0 b/s";
}
return (
d3.format(".2f")(r * scale) +
" " +
units +
"b/s (" +
d3.format(".1f")(percent) +
"% capacity)"
);
},
element: "#rate" + id,
});
}
// Used to get ids.
CapacityBanner.count = 0;