-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoppler.js
More file actions
47 lines (41 loc) · 1.52 KB
/
Copy pathDoppler.js
File metadata and controls
47 lines (41 loc) · 1.52 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
/* Doppler frequency shift
*
* radial velocity v_r = v*cos(theta)
* one-way: f_d = v_r/c * f = v_r/lambda
* two-way (radar): f_d = 2*v_r/c * f
*
* References: Skolnik, Introduction to Radar Systems 3e; Richards,
* Fundamentals of Radar Signal Processing 2e.
*/
var C_LIGHT = 299792458;
var btn = document.getElementById("btn");
btn.addEventListener('click', function() {
var f = parseFloat(document.getElementById("f").value); // GHz
var v = parseFloat(document.getElementById("v").value); // m/s
var th = parseFloat(document.getElementById("th").value); // deg
var mode = document.getElementById("mode").value;
clearError();
if (isNaN(f) || isNaN(v) || f <= 0) {
showError('Enter a positive frequency and a speed.');
return;
}
if (isNaN(th)) th = 0;
var fHz = f * 1e9;
var lam = C_LIGHT / fHz;
var vr = v * Math.cos(th * Math.PI / 180);
var factor = (mode === 'two') ? 2 : 1;
var fd = factor * vr / C_LIGHT * fHz;
document.getElementById("fd").textContent = engFmt(fd, 'Hz');
document.getElementById("frac").textContent = (fd / fHz).toExponential(3);
document.getElementById("vr").textContent = vr.toFixed(3) + ' m/s' + (v !== vr ? ' (v·cosθ)' : '');
document.getElementById("lam").textContent = engFmt(lam, 'm');
if (window.drawDiagram) window.drawDiagram();
});
function showError(msg) {
var el = document.getElementById('error');
if (el) el.textContent = msg;
}
function clearError() {
var el = document.getElementById('error');
if (el) el.textContent = '';
}