-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreqshifttest.html
173 lines (115 loc) · 5.35 KB
/
freqshifttest.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
<html>
<head>
<meta charset="UTF-8">
<title>Birdcage Builder v0.0.3</title>
<!-- scripts must be included in reverse order of call stack for scope visibility -->
<script src="debug.js"></script>
<script src="helpers.js"></script>
<script src="BCLegs.js"></script>
<script src="BCEndRings.js"></script>
<script src="BirdcageBuilder.js"></script>
<script src="BBGuiHandler.js"></script>
<!-- <script src="../../plotly/v1.58.5/plotly-latest.min.js"></script> -->
<script src="https://cdn.plot.ly/plotly-2.31.1.min.js" charset="utf-8"></script>
<!-- Birdcage Builder -->
<!-- v0.0.2 GUI Test only -->
<!-- Doug Brantner 4/17/2023 -->
<!-- NYU Langone Health CAI2R -->
<!-- cai2r.net -->
</head>
<body>
<h1>Birdcage Builder</h1>
v0.0.3<br>
<br>
<h2>Capacitor vs. Frequency Shift Example</h2>
Demonstrate usage of Open BirdcageBuilder code & extension possibilities.<br>
(Click "View Source" in your browser or check the <a href="https://github.com/dbnyu/OpenBirdcageBuilder/blob/main/freqshifttest.html">Github source code</a> for this page)<br>
<br>
Also demonstrate plotting results with <a href="https://plotly.com/javascript/">Plotly.js</a><br>
<!-- TODO - could redo form for inputs ie. center freq & shift bandwidth, etc.<br> -->
<!-- Placeholder for Plot -->
<div id="plotly_capVsFreq" style="width:100%;max-width:700px"></div>
<br>
<form>
Click "Go!" to Plot<br>
<button type="submit" onclick="freq_cap_plot(); return false">Go!</button>
</form>
<!-- <script defer="defer"> -->
<script>
/* Plot Capacitor vs. Frequency for a certain bandwidth
* (ie. for unstable magnet with respect to temperature)
*/
/* See BirdcageBuilder javascript imports above in <head> of this file */
DEBUG_ENABLE = true; // bool; enable or disable debug output
DEBUG_ID = 'debug1'; // DOM field ID for debug output
DEBUG_OUTPUT = "CONSOLE"; // set to "CONSOLE", "DOM", or "BOTH" (DOM is not recommended in a loop)
console.log(DEBUG_ID);
var ctr_freq = 21.25e6; // center frequency (Hz)
var drift_bw = 10e3; // bandwidth around center freq to plot
var N_points = 100; // number of points to plot
var freq_start = ctr_freq - drift_bw;
var freq_end = ctr_freq + drift_bw;
function linspace(start, end, N) {
/* Return an array of N values from start to end (inclusive).
start must be less than end.
TODO - one with a guaranteed center value would be nice
*/
// TODO this is off by one... (only goes up to N-1 so doesn't include 'end')
// TODO - move to helpers.js once this is fixed
var step = (end - start) / N;
var out = new Array(N);
for (var i = 0; i < N; i++) {
out[i] = start + i*step;
}
return out;
}
function freq_cap_plot() {
/* Demonstrate Open BirdcageBuilder code usage */
/* This example loops over many frequency values & resulting capacitor values */
var freqs = linspace(freq_start, freq_end, N_points); // frequencies to plot
var caps = new Array(N_points); // output for capacitor values
// Set up BirdcageBuilder object (see BirdcageBuider.js)
bb = new BirdcageBuilder(12, ctr_freq, 3.8e-2, 100e-2, 'lowpass');
// Set up Rectangular Legs object (see BCLegs.js)
// Note - this object is already stored in the above BirdcageBuilder object & just needs to be initialized
// Alternatively, call set_legs_tube() for tubular legs
bb.legs.set_legs_rect(10e-2, 0.6e-2);
// Set up End Rings
// Like the legs, this object is already created & stored in the main BirdcageBuilder object
// and just needs to be initialized here
bb.endrings.set_endrings_rect(0.6e-2);
// User must call this function to set endring mutual inductance, after setting up endrings:
bb.endrings.calc_er_mutual_inductance(bb.legs);
// Now the capacitor can be calculated & converted to picoFarads
// (shown here for completeness; but moved down to the loop & run multiple times in this example)
//var cap = 1e12 * bb.calc_capacitor()
// Loop over frequencies & calculate capacitor value at each frequency
// inductances/legs/endrings should be independent of frequency; so shouldn't need to recompute inductances
for (var i = 0; i < N_points; i++) {
bb.freq = freqs[i];
caps[i] = 1e12 * bb.calc_capacitor();
}
// Set up data for plotting (see plotly library documentation & examples)
var data = [{x: freqs,
y: caps,
mode: "lines+markers",
}];
var layout = {xaxis: {title: "Frequency (Hz)"},
yaxis: {title: "Capacitor (pF)"},
title: "Capacitor vs. Frequency Drift",
};
Plotly.newPlot("plotly_capVsFreq", data, layout);
}
</script>
<hr>
<h2>Debug</h2>
<form>
<button type="submit" onclick="debug_clear(); return false">Clear Debug</button>
</form>
<p id="debug1"></p>
<!-- TODO - add 'clear' button -->
<hr>
<h2>References</h2>
1. <a href="https://plotly.com/javascript/">Plotly.js</a><br>
</body>
</html>