-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatterns_matlab.js
More file actions
246 lines (207 loc) · 7.78 KB
/
Copy pathpatterns_matlab.js
File metadata and controls
246 lines (207 loc) · 7.78 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
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
/**
* This code defines functions to generate antenna patterns for different types of antennas and enables
* lookup of specific values within those patterns based on theta and phi angles.
*
* @param {number} thetares - The angular resolution in degrees for the elevation angle (θ) in the
* antenna pattern lookup tables. This parameter determines the granularity of the pattern data in the
* vertical direction.
* @param {number} phires - The angular resolution in degrees for the azimuth angle (φ) in the antenna
* pattern lookup tables. This parameter sets the granularity of the pattern data around the antenna in
* the horizontal direction and is used to calculate the number of azimuth divisions in the lookup tables.
* @returns {Function} Returns a function that allows you to generate and look up antenna pattern values
* based on specific theta and phi angles, depending on the selected antenna pattern type. The
* `getAntennaPatternValue` function calculates the antenna pattern for a given pattern type and retrieves
* values using `lookupAntennaPatternValue`.
*/
// **** Antenna pattern lookup tables *****
// fvert - vertical polarization
// fhoriz - horizontal polarization
// 'fvert' and 'fhoriz' represent the complex gain of the antenna at each phi and theta angle,
// and are normalized to a maximum absolute value of 1.
let thetaresolution = 5;
let phiresolution = 5;
// vertically polarized isotropic antenna
function isovert(thetares, phires) {
let patterns = [];
if (90 % thetares !== 0) {
//console.log("Error! Theta resolution must divide evenly into 90 degrees.");
return;
}
let thetadim = 180 / thetares + 1;
let phidim = 360 / phires + 1;
let fvert = Array(thetadim)
.fill()
.map(() => Array(phidim).fill(1)); // vertical polarization
patterns.push(fvert);
let fhoriz = Array(thetadim)
.fill()
.map(() => Array(phidim).fill(0)); // horizontal polarization
patterns.push(fhoriz);
// console.log(fvert);
// console.log(fhoriz);
return patterns;
}
// horizontally polarized isotropic antenna
function isohoriz(thetares, phires) {
let patterns = [];
if (90 % thetares !== 0) {
//console.log("Error! Theta resolution must divide evenly into 90 degrees.");
return;
}
let thetadim = 180 / thetares + 1;
let phidim = 360 / phires + 1;
let fvert = Array(thetadim)
.fill()
.map(() => Array(phidim).fill(0)); // vertical polarization
let fhoriz = Array(thetadim)
.fill()
.map(() => Array(phidim).fill(1)); // horizontal polarization
patterns.push(fvert);
patterns.push(fhoriz);
// console.log(fvert);
// console.log(fhoriz);
return patterns;
}
// vertically oriented half-wave dipole antenna
function halfwave(thetares, phires) {
let patterns = [];
if (90 % thetares !== 0) {
//console.log("Error! Theta resolution must divide evenly into 90 degrees.");
return;
}
let thetadim = 180 / thetares + 1;
let phidim = 360 / phires + 1;
let fvert = Array(thetadim)
.fill()
.map(() => Array(phidim).fill(0)); // vertical polarization
let fhoriz = fvert.slice(); // horizontal polarization
for (let k = 0; k < thetadim; k++) {
let theta = (Math.PI * thetares * k) / 180;
for (let m = 0; m < phidim; m++) {
let phi = (Math.PI * phires * m) / 180;
if (k === 0 || k === thetadim - 1) {
fvert[k][m] = 0;
} else {
fvert[k][m] =
Math.cos((Math.PI / 2) * Math.cos(theta)) / Math.sin(theta);
}
}
}
patterns.push(fvert);
patterns.push(fhoriz);
// console.log(fvert);
// console.log(fhoriz);
return patterns;
}
// vertically oriented small dipole antenna
function sloop(thetares, phires) {
let patterns = [];
if (90 / thetares !== Math.round(90 / thetares)) {
//console.log("Error! theta resolution must divide evenly into 90 degrees.");
return;
}
let thetadim = 180 / thetares + 1;
let phidim = 360 / phires + 1;
let fvert = [];
let fhoriz = [];
for (let i = 0; i < thetadim; i++) {
fvert.push(new Array(phidim).fill(0));
fhoriz.push(new Array(phidim).fill(0));
}
for (let k = 1; k <= thetadim; k++) {
let theta = (Math.PI * thetares * (k - 1)) / 180;
for (let m = 1; m <= phidim; m++) {
let phi = (Math.PI * phires * (m - 1)) / 180;
fvert[k - 1][m - 1] = Math.sin(theta);
}
}
patterns.push(fvert);
patterns.push(fhoriz);
// console.log(fvert);
// console.log(fhoriz);
return patterns;
}
// directional, vertically polarized antenna with specified horizontal and vertical beamwidth and sidelobe level
// Generates the pattern for a vertically polarized directional antenna with a flat main beam and uniform side lobe level.
function dirantv(thetares, phires, azbw, elbw, SLL) {
let patterns = [];
if (SLL > 0) {
//console.log("Error! SLL must be <= 0.");
return;
}
if (90 / thetares !== Math.round(90 / thetares)) {
//console.log("Error! theta resolution must divide evenly into 90 degrees.");
return;
}
const thetadim = 180 / thetares + 1;
const phidim = 360 / phires + 1;
const fvert = Array.from({ length: thetadim }, () =>
Array.from({ length: phidim }).fill(0)
);
const fhoriz = Array.from({ length: thetadim }, () =>
Array.from({ length: phidim }).fill(0)
);
for (let k = 1; k <= thetadim; k++) {
const theta = (Math.PI * thetares * (k - 1)) / 180;
for (let m = 1; m <= phidim; m++) {
const phi = (Math.PI * phires * (m - 1)) / 180;
// Main lobe centered at theta = 90°, phi = 90°
if (
Math.abs(theta - Math.PI / 2) - (Math.PI * thetares) / 180 <= (Math.PI * (elbw / 2)) / 180 &&
Math.abs(phi - Math.PI / 2) <= ((azbw / 2) * Math.PI) / 180
) {
fvert[k - 1][m - 1] = 1;
} else if (SLL !== -999) {
fvert[k - 1][m - 1] = 10 ** (SLL / 10);
}
}
}
patterns.push(fvert);
patterns.push(fhoriz);
// console.log(fvert);
// console.log(fhoriz);
return patterns;
}
// invokes the method for the selected antenna pattern and looks up the value for corresp phi and theta
function getAntennaPatternValue(theta, phi, pattern) {
let patterns;
switch (pattern) {
case "vertical_isotropic":
patterns = isovert(thetaresolution, phiresolution);
break;
case "horizontal_isotropic":
patterns = isohoriz(thetaresolution, phiresolution);
break;
case "halfwave":
patterns = halfwave(thetaresolution, phiresolution);
break;
case "sdipole":
patterns = sloop(thetaresolution, phiresolution);
break;
case "dirAnt_sideLobe":
patterns = dirantv(thetaresolution, phiresolution, 30, 30, -10);
break;
default:
patterns = isovert(thetaresolution, phiresolution);
}
return lookupAntennaPatternValue(theta, phi, patterns);
}
// looks up the antenna pattern value from the table
function lookupAntennaPatternValue(theta, phi, patterns) {
let fvert = patterns[0];
let fhoriz = patterns[1];
let theta_index = Math.round(Number(theta) / thetaresolution);
let phi_index = Math.round(Number(phi) / phiresolution);
// Clamp indices to valid range
theta_index = Math.max(0, Math.min(fvert.length - 1, theta_index));
phi_index = Math.max(0, Math.min(fvert[0].length - 1, phi_index));
let f_vert_val = fvert[theta_index][phi_index];
let f_horiz_val = fhoriz[theta_index][phi_index];
return [f_vert_val, f_horiz_val];
}
// method invocations
// isovert(thetaresolution, phiresolution);
// isohoriz(thetaresolution, phiresolution);
// halfwave(thetaresolution, phiresolution);
// sloop(thetaresolution, phiresolution);
// dirantv(thetaresolution, phiresolution, 20, 20, -1.5);