bash -lc cat > /mnt/data/generate_exp3_nec2.py <<'PY'
from pathlib import Path
RADIUS = 0.004 # 8 mm diameter
SEG = 21
DRIVEN_TAG = 2
DRIVEN_SEG = 11
def gw(tag, x, length):
# Element parallel to z-axis, boom along x-axis.
z1 = -length / 2
z2 = length / 2
return f"GW {tag:2d} {SEG:2d} {x: .4f} 0.0000 {z1: .4f} {x: .4f} 0.0000 {z2: .4f} {RADIUS:.4f}"
def make_nec(title, comments, elements, outpath):
lines = []
lines.append(f"CM {title}")
lines.append("CM NIE2226 Experiment 3 - 300 MHz Yagi-Uda antenna model for 4nec2")
lines.extend(["CM " + c for c in comments])
lines.append("CM Units: metres. Conductor diameter: 8 mm, radius: 0.004 m.")
lines.append("CM Elements are parallel to z-axis; boom/directive axis is +x.")
lines.append("CE")
for tag, name, x, length in elements:
lines.append(gw(tag, x, length) + f" ' {name}, L={length:.4f} m, x={x:.4f} m")
lines.append("GE 0")
lines.append("GN -1")
lines.append(f"EX 0 {DRIVEN_TAG} {DRIVEN_SEG} 0 1.0 0.0")
# Frequency sweep 250-350 MHz with 1 MHz step. Good for S11/gain sweep in 4nec2.
lines.append("FR 0 101 0 0 250.0 1.0")
lines.append("RP 0 181 1 1000 0.0 0.0 1.0 0.0")
lines.append("EN")
Path(outpath).write_text("\n".join(lines) + "\n", encoding="ascii")
Experiment 3A: optimized-ish 3-element Yagi with one director.
Driven length is shortened from the original model so the S11 dip is around 300 MHz, not 285 MHz.
elements_1dir = [
(1, "Reflector", -0.2000, 0.4740),
(2, "Driven element - centre fed", 0.0000, 0.4510),
(3, "Director 1", 0.1700, 0.4180),
]
comments_1dir = [
"File 1 of 2: 1-director / 3-element Yagi-Uda stage.",
"Starting point follows assignment guidance: add one 8 mm director in front of the driven element.",
"Tuned dimensions: reflector 0.474 m, driven 0.451 m, director 0.418 m.",
"Spacing: reflector-to-driven 0.200 m; driven-to-director 0.170 m.",
"Use 4nec2 frequency sweep to extract S11, realized gain, F/B ratio, and pattern at 300 MHz.",
]
make_nec(
"EXP3A 1-DIRECTOR 3-ELEMENT YAGI-UDA, TUNED NEAR 300 MHZ",
comments_1dir,
elements_1dir,
"/mnt/data/experiment3_A_1_director_yagi_300MHz.nec2",
)
Experiment 3B: 9-director Yagi. Gradually shorter directors, typical Yagi tuning strategy.
elements_9dir = [
(1, "Reflector", -0.2000, 0.4740),
(2, "Driven element - centre fed", 0.0000, 0.4510),
(3, "Director 1", 0.1600, 0.4180),
(4, "Director 2", 0.3300, 0.4100),
(5, "Director 3", 0.5000, 0.4040),
(6, "Director 4", 0.6800, 0.3990),
(7, "Director 5", 0.8600, 0.3940),
(8, "Director 6", 1.0400, 0.3900),
(9, "Director 7", 1.2200, 0.3860),
(10, "Director 8", 1.4000, 0.3820),
(11, "Director 9", 1.5800, 0.3780),
]
comments_9dir = [
"File 2 of 2: 9-director / 11-element Yagi-Uda optimization stage.",
"Reflector and driven element retain the tuned 300 MHz baseline from Experiment 2 correction.",
"Directors are progressively shortened to improve forward gain along +x.",
"Director positions are cumulative x coordinates from the driven element.",
"For final submission, run 4nec2 optimizer/sweeps and fine tune director lengths/spacings if needed.",
]
make_nec(
"EXP3B 9-DIRECTOR 11-ELEMENT YAGI-UDA, TUNED NEAR 300 MHZ",
comments_9dir,
elements_9dir,
"/mnt/data/experiment3_B_9_director_yagi_300MHz.nec2",
)
print("Generated:")
print("/mnt/data/experiment3_A_1_director_yagi_300MHz.nec2")
print("/mnt/data/experiment3_B_9_director_yagi_300MHz.nec2")
PY
python3 /mnt/data/generate_exp3_nec2.py
ls -l /mnt/data/experiment3_*_yagi_300MHz.nec2
Thought for 52s