-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathoptimized.py
More file actions
30 lines (25 loc) · 919 Bytes
/
optimized.py
File metadata and controls
30 lines (25 loc) · 919 Bytes
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
#
# Automatically tune antenna
#
import monopole
import scipy.optimize
import numpy as np
from antenna_util import reflection_coefficient
# A function that will be minimized when the impedance is 50 Ohms
# We convert the height and antenna length to positive
# numbers using exp. because otherwise the antenna will lie
# below ground and cause an error in simulation.
def target(x):
global freq
base_height = np.exp(x[0]) # Make it positive
length = np.exp(x[1]) # Make it positive
z = monopole.impedance(freq, base_height, length)
return reflection_coefficient(z, z0=50.0)
# Starting value
freq = 134.5
x0 = [-2.0, 0.0]
# Carry out the minimization
log_base, log_length = scipy.optimize.fmin(target, x0)
base_height = np.exp(log_base)
length = np.exp(log_length)
print("Optimium base_height={}m, h={}m, impedance={} Ohms".format(base_height, length, monopole.impedance(freq, base_height, length)))