-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.html
371 lines (284 loc) · 9.19 KB
/
examples.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<html>
<head>
<title> rf.js Examples </title>
<script type="text/javascript" src="https://root.cern/js/5.9.1/scripts/JSRootCore.js?2d&hierarchy&io&tree"> </script>
<script type="text/javascript" src="KissFFT.js"></script>
<script type="text/javascript" src="FFT.js"></script>
<script type="text/javascript" src="rf.js"></script>
<script type="text/javascript">
function runElement(which)
{
var f = new Function(document.getElementById(which).value);
f();
}
function runAll()
{
["js1","js2"].map(runElement);
}
</script>
<style>
td
{
width: 600px;
height: 300px;
}
td div
{
height: 100%
}
textarea {
background-color: #111;
color: #0e0;
font-family: monospace;
}
body
{
max-width: 1200px;
margin: 40px ;
line-height: 1.5;
color: 222;
}
h1,h2,h3
{
line-height: 1.2;
color: #4682b4;
}
hr
{
color: #b0c4de;
height: 2px;
}
</style>
</head>
<body onLoad="runAll()">
<h1> rf.js Examples</h1>
(Work in progress)
<hr>
Contents:
<ul>
<li> <a href="#intro">Basics</a>
<li> <a href="#interferometry">Interferometry</a>
<li> <a href="#spectrograms">Spectrograms</a>
</ul>
<hr>
<a id="intro"></a><h2> Basics</h2>
<p> <tt>rf.js</tt> (<a href="https://github.com/cozzyd/rfjs">source</a>) is a set of javascript functions for doing signal processing
with <tt>jsroot</tt> <tt>TGraph</tt>'s. It is intended for web monitoring applications for
detectors trying to detect ultra-high-energy neutrinos via radio emission,
but might be useful for others as well.
<p>Most operations assume your waveforms are stored as TGraph's. All operations are part of the RF object. Here is a basic example
showing a few things that can be done.
<table>
<tr>
<td rowspan="2">
<textarea id="js1" cols=80 rows=40>
// RF.range will generate a 512 values starting at 0 with a step of 0.5
var N = 512;
var ts = RF.range(0,N,0.5);
// Generate a waveform of some sort
var ys = RF.randomGaussian(N);
for (var i =0; i < N; i++)
{
var t = ts[i];
ys[i]+= 5*Math.sin(0.09*t*2*Math.PI) + 3*Math.cos(0.03*t*2*Math.PI);
}
//Make a graph and draw it
var g= JSROOT.CreateTGraph(N, ts,ys);
g.InvertBit(JSROOT.BIT(18));
g.fTitle="A waveform and its envelope and a filtered versinon;ns;V";
JSROOT.draw('c1', g);
//now draw its hilbert enveope
var h = RF.hilbertEnvelope(g);
h.InvertBit(JSROOT.BIT(18));
h.fLineColor = 3; //different color to differentiate
JSROOT.draw('c1',h);
//now lets get a filtered version. the filtering is in place.
var f = JSROOT.CreateTGraph(N,ts,ys);
f.InvertBit(JSROOT.BIT(18));
//some IIR coefficients corresponding to a 2nd order butterworth lowpass
//in the future might implement filter design
var b= [0.020083,0.040167,0.020083];
var a= [1.00000,-1.56102,0.64135];
RF.IIRFilter( f, b,a);
f.fLineColor = 2; //different color to differentiate
JSROOT.draw('c1',f);
// take the power spectrum and draw it
var G = RF.makePowerSpectrum(g);
var F = RF.makePowerSpectrum(f);
F.fLineColor=2;
G.fTitle = "Spectra!; GHz; dBish";
JSROOT.draw('c2',G);
JSROOT.draw('c2',F);
</textarea> <br>
<input type="button" value="Run" onClick="runElement('js1');">
<input type="button" value="Clear" onClick="JSROOT.cleanup('c1'); JSROOT.cleanup('c2');">
</td>
<td>
c1
<div id="c1" >
</div>
</td>
</tr>
<tr>
<td>
c2
<div id="c2">
</div>
</td>
</tr>
</table>
<hr>
<h2> <a id="interferometry"></a>Interferometry</h2>
<p> One of the main applications of <tt>rf.js</tt> is correlating waveforms
from multiple antennas together and making interferometric maps. Here are
some examples of cross-correlation, 1-D interferometric maps, and 2d interferometric map using
some synthetic data.
<p>In this case, we consider 3 vertical strings of 4 antennas. Figure c3 shows the
graphs, generated by taking a white noise with a gaussian signal on top run
through an IIR filter bandpass filter. The time delays for each signal are
calculated according to a known plane wave angle. Figure c4 shows the cross-correlation between the first two graphs.
Figure c5 shows the average cross-correlation for a given elevation angle within a vertical tring. Figure c6 shows the entire array cross-correlation in terms of elevation and azimuth.
Finally, c7 shows the coherent waveform. It starts at the correct angle, but clicking on the 2D map will compute the coherent sum at that angle.
<table>
<tr>
<td rowspan=5>
<textarea id='js2' cols=80 rows=120>
// setup
JSROOT.gStyle.AutoStat=false;
JSROOT.gStyle.Palette = 87;
JSROOT.gStyle.fNumberContours=255;
var N = 512; //number of samples
var Nant = 12; //number of antennas
var tmin = -50; //minimum time for each waveform
var dt =0.5; //time step
var filter_b = [0.16718,0,-0.66872,0,1.00308,0,-0.66872,0,0.16718];
var filter_a = [1,0,-0.7821,0,0.67998,-0,-0,0.18268,-0,0.030119];
var noise = 5;
var dist = 5;
var signal_amp = 100;
var signal_width = 1;
var c = 0.3; //speed of light
//coordinates of antennas
var pt = dist*Math.sqrt(3)/2;
var xant = [0,0,0,0,dist,dist,dist,dist,pt,pt,pt,pt];
var yant = [0,0,0,0,0,0,0,0,pt,pt,pt,pt];
var zant = [0,dist,2*dist,3*dist,0,dist,2*dist,3*dist,0,dist,2*dist,3*dist];
//incoming direction
var phi = 30;
var theta = -10;
//done with settings
var cos_phi = Math.cos(phi*Math.PI/180);
var sin_phi = Math.sin(phi*Math.PI/180);
var cos_theta = Math.cos(theta*Math.PI/180);
var sin_theta = Math.sin(theta*Math.PI/180);
// direction vector
var k = [ cos_phi*cos_theta,sin_phi*cos_theta,sin_theta];
var gs = [];
var ts = RF.range(tmin, N,dt);
var ants = [];
for (var i = 0; i < Nant; i++)
{
// figure out the correct time at this antenna, t=0 at 0,0,0
var X = [xant[i],yant[i],zant[i]];
var t_signal = -RF.dotProduct(X,k)/c;
//start with some noise
var ys = RF.randomGaussian(N,0,noise);
//now add the signal
for (var j = 0; j < N; j++)
{
ys[j] += signal_amp * Math.exp( -Math.pow(ts[j]-t_signal,2)/signal_width);
}
var g = JSROOT.CreateTGraph(N, ts,ys);
g.InvertBit(JSROOT.BIT(18));
//now filter
RF.IIRFilter(g,filter_b, filter_a);
gs.push(g);
//needed for angle mapper
ants.push(RF.Antenna(xant[i],yant[i],zant[i]));
g.fLineColor=1+i;
g.fName='g'+i;
g.fTitle='graphs;ns;V';
}
var mg = JSROOT.CreateTMultiGraph.apply(0,gs);
mg.fTitle = "The graphs;ns;V";
JSROOT.draw('c3', mg,'al');
//great, now we have our examples! First let's draw a cross-correlation graph
var xcorr = RF.crossCorrelation(gs[0],gs[1]);
xcorr.fTitle = "Cross-Correlation 0 vs 1;ns;correlation";
JSROOT.draw('c4',xcorr,"l");
//setup elevation mapper for first 4 antennas
var mapper_elev = RF.ElevationMapper(zant.slice(0,4),c);
var map_elev = new RF.InterferometricMap(mapper_elev, 180,-90,90);
map_elev.setTitle("String 1 Elevation Map");
map_elev.compute(gs.slice(0,4));
console.log(map_elev.getMaxes());
JSROOT.draw('c5', map_elev.hist);
//set up angle mapper for all antennas
var mapper_ang = RF.AngleMapper(ants,c);
var map_ang = new RF.InterferometricMap(mapper_ang, 360,-180,180,180,-90,90,true,false);
map_ang.setTitle("Array Angle Map");
map_ang.compute(gs.slice(0,Nant));
console.log(map_ang.getMaxes());
JSROOT.draw('c6', map_ang.hist,"colz", function(painter) {
painter.ConfigureUserClickHandler(
function(info)
{
var binx = info.binx;
var biny = info.biny;
var clicked_h = info.obj;
var x = clicked_h.fXaxis.GetBinCenter(binx);
var y = clicked_h.fYaxis.GetBinCenter(biny);
JSROOT.cleanup('c7');
var coh = mapper_ang.coherentSum(gs,[x,y]);
coh.fTitle='Coherent sum at phi='+x+',theta='+y+';ns;sum';
JSROOT.draw('c7',coh,"l");
});
});
//now let's construct the coherent waveform at the known location
var coh = mapper_ang.coherentSum(gs,[phi,theta]);
coh.fTitle='Coherent sum at phi='+phi+',theta='+theta+';ns;sum';
JSROOT.draw('c7',coh,"l");
</textarea>
<input type="button" value="Run" onClick="runElement('js2');">
<input type="button" value="Clear" onClick="JSROOT.cleanup('c3'); JSROOT.cleanup('c4'); JSROOT.cleanup('c5'); JSROOT.cleanup('c6');JSROOT.cleanup('c7');">
</td>
<td>
c3
<div id="c3" >
</div>
</td>
</tr>
<tr>
<td>
c4
<div id="c4" >
</div>
</td>
</tr>
<tr>
<td>
c5
<div id="c5" >
</div>
</td>
</tr>
<tr>
<td>
c6
<div id="c6" >
</div>
</td>
</tr>
<tr>
<td>
c7
<div id="c7" >
</div>
</td>
</tr>
</table>
<hr>
<a id="spectrograms"></a><h2> Spectrograms </h2>
TODO
</body>
</html>