forked from vtwireless/HLSI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path15_rule_based_avoidance.html
219 lines (173 loc) · 5.39 KB
/
15_rule_based_avoidance.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>HLSI Ex 15</title>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" media="all" href="hlsi.css">
<style>
output {font-weight: bold;}
</style>
<script src=d3.v5.min.js></script>
<script src=fft.js></script>
<script src=common.js></script>
<script src=signal.js></script>
<script src=sliders.js></script>
<script src=powerSpectrumPlot.js></script>
<script src=spectralEfficiencyPlot.js></script>
<script src=label.js></script>
<script src=capacityBanner.js></script>
<script src=capacityRunner.js></script>
<script src=throughputPlot.js></script>
<script src=hoppingInterferer.js></script>
</head>
<body>
<h2>Exercise 15 Rule Based Interferer Avoidance</h2>
<p><a href="index.html">[exercises]</a></p>
<p>
Press the "Start" button to start the changing of signal parameters
gain and bandwidth as time go on. The interferer has a "frequency
hopping mind" of its' own, which we do not control; we just try to
avoid it by selecting one of the pre-programmed rules.
</p>
<p id=capacityRunner></p>
<p id=hoppingInterferer></p>
<p id=capacityBanner></p>
<p>
<input type="range" id=freq />
</p>
<p>
<input type="range" id=bw />
</p>
<p>
<input type="range" id=gn />
</p>
<p>
<input type="range" id=mcs />
</p>
</body>
<script>
'use strict';
var sig = new Signal(conf.sig0, '', {
bw_max: 38.0e6, // Hz
bw_init: 10.0e6, // Hz
bw_min: 2.0e6, // Hz
gn_max: 1.0, // dB
gn_init: -10.0, // dB
gn_min: -40, // dB
mcs_init: 4 // array index int 0 to 11
});
var interferer = new Signal(conf.sig0, 'interferer', {
bw_max: 38.0e6, // Hz
bw_init: 2.5e6, // Hz
gn_max: 0.0, // dB
gn_init: -12, // dB
gn_min: -40, // dB
freq_init: 1785.0e6 // Hz
});
var noise = Signal(conf.noise, "Noise", { gn_init: -40});
// How many bits of randomness are there in Math.random()?
//
// Lets say it's 30 bits (due too float round-off of 32 bits) and just
// cycle the value after that. Computing Math.random() is not cheap.
const rbits = 30;
const rsize = (0x01 << rbits) - 1;
// rsize = 2^(rbits)
const randBits = Math.round(Math.random()*rsize);
// randBits is now a big random integer.
var randBit = 1; // one bit gets set in randBit.
//
// Coin() returns +1 or -1 depending on randomness in randBits.
function Coin() {
// pick a bit
let bit = randBits & randBit;
// Go to the next bit.
randBit = randBit << 1;
if(randBit > rsize)
// Reset back to the first bit.
randBit = 1;
return (bit)?(1):(-1);
}
// The list of "Rule Based" functions in the <select> after the "Start"
// button.
var funcs = {
"Select pre-configured Strategy ...":
"This is not an otional function",
"No Adaptation":
function() { },
"Random Frequency":
function(t) {
sig.freq = sig.freq_min + Math.random()*(sig.freq_max - sig.freq_min);
},
"Frequency Adaptation":
function(t) {
let i = interferer;
let s = sig;
// A small standard frequency change size.
let delta = 0.1 * (s.freq_max - s.freq_min);
// The mean frequency.
let favg = (s.freq_max + s.freq_min)/2.0;
let f_lower = s.freq - 0.5*s.bw,
f_upper = s.freq + 0.5*s.bw,
i_lower = i.freq - 0.5*i.bw,
i_upper = i.freq + 0.5*i.bw;
if(!(f_lower > i_upper || f_upper < i_lower)) {
// The interferer and the signal overlap.
let ch1 = f_lower - i_lower;
let ch2 = f_upper - i_upper;
let ch3 = Math.abs(i_upper - f_lower);
let ch4 = Math.abs(i_lower - f_upper);
if((ch2 > 0) && (ch1 > 0)) {
if(f_lower < s.freq_min || f_upper > s.freq_max) s.freq = favg;
s.freq += Coin() * ch3 + delta;
return;
}
if((ch2 > 0) && (ch1 < 0)) {
if(f_lower < s.freq_min || f_upper > s.freq_max) s.freq = favg;
let ch5 = Math.abs(ch3) + Math.abs(ch4);
s.freq += Coin() * ch5 + delta;
return;
}
if((ch2 < 0) && (ch1 < 0)) {
if(f_lower < s.freq_min || f_upper > s.freq_max) s.freq = favg;
s.freq += Coin() * ch4 + delta;
return;
}
s.freq = favg;
return;
}
},
"Frequency and Bandwidth Adaptation":
function(t) {
let i = interferer;
let s = sig;
// A small standard frequency change size.
let delta = 0.1 * (s.freq_max - s.freq_min);
// The mean frequency.
let favg = (s.freq_max + s.freq_min)/2.0;
let f_lower = s.freq - 0.5*s.bw,
f_upper = s.freq + 0.5*s.bw,
i_lower = i.freq - 0.5*i.bw,
i_upper = i.freq + 0.5*i.bw;
if(i.freq < favg) {
s.freq = (i.freq_max + i_upper)/2.0;
s.bw = i.freq_max - i_upper - delta
} else {
s.freq = (i_lower + i.freq_min)/2.0;
s.bw = i_lower - i.freq_min - delta;
}
}
}
CapacityRunner(sig, funcs, '#capacityRunner', {
tStep: 0.3/*seconds*/
});
Slider(sig, 'freq', '#freq');
Slider(sig, 'bw', '#bw');
Slider(sig, 'gn', '#gn');
Slider(sig, 'mcs', '#mcs');
HoppingInterferer(interferer, '#hoppingInterferer');
CapacityBanner(sig, '#capacityBanner');
PowerSpectrumPlot();
ThroughputPlot(sig);
SpectralEfficiencyPlot(sig);
</script>
</html>