def print_result(x, f, accepted): log_base, log_length = x base_height = np.exp(log_base) length = np.exp(log_length) if accepted: print("Optimium base_height=%fm, h=%fm, impedance=%s Ohms" % \ (base_height, length, monopole.impedance(freq, base_height, length))) else: print("Local_minimum=%fm, h=%fm, impedance=%s Ohms" % \ (base_height, length, monopole.impedance(freq, base_height, length)))
def target(x): global freq, target_impedance base_height = np.exp(x[0]) # Make it positive length = np.exp(x[1]) # Make it positive if (length > 10.0): return 100 try: z = monopole.impedance(freq, base_height, length) return reflection_coefficient(z, z0=target_impedance) except RuntimeError as re: return 100
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)
# 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=%fm, h=%fm, impedance=%s Ohms" % \ (base_height, length, monopole.impedance(freq, base_height, length))
# # Plot of reflection coefficient vs antenna length for a fixed base height. # import monopole import numpy as np import pylab as plt from antenna_util import reflection_coefficient lengths = np.linspace(0.2, 5.0, 270) reflections = [] z0 = 50 for l in lengths: freq = 134.5 z = monopole.impedance(freq, base=0.5, length=l) reflections.append(reflection_coefficient(z, z0)) plt.plot(lengths, reflections) plt.xlabel("Antenna length (m)") plt.ylabel("Reflection coefficient") plt.title("Reflection coefficient vs length (base_height=0.5m)") plt.grid(True) plt.show() plt.savefig("reflection_coefficient.png")
# 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=%fm, h=%fm, impedance=%s Ohms" % \ (base_height, length, monopole.impedance(freq, base_height, length))
# # 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)))