-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathantenna_factor.py
More file actions
56 lines (45 loc) · 1.77 KB
/
antenna_factor.py
File metadata and controls
56 lines (45 loc) · 1.77 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
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import pi
import math
# Physics config
c = 343 # speed of sound
f = 40000 # frequency
wavelength = c / f # wavelength
period = 1 / f #
# Array config
pitch = 5 * 0.001 # distance between emission point
kerf = 0.1 * 0.001 # distance between two adjacent elements
n = 8 # number of elements
phase_shift = 2*pi * 360/36/6 # phase shift between two adjacent elements
array_width = (n - 1) * (pitch + kerf)
# Simulation config
radius = 0.5 # radius at which antenna factors are calculated
maxAngle = 180 # maximum angle at which antenna factors are calculated
resolution = 0.1 # resolution of sim in degrees
def genAmpMap():
thetas = [np.deg2rad(i) for i in np.arange(0, maxAngle, resolution)]
points = [[radius*np.cos(theta), radius*np.sin(theta)] for theta in thetas]
ampMap = np.array([[0, 0] for i in range(len(points))], dtype=float)
for i in range(len(points)):
amplitude = 0
x = points[i][0]
y = points[i][1]
for k in range(n):
elementx = k*(pitch+kerf) - array_width/2
r = np.sqrt((x - elementx)**2 + (y)**2)
phase = 2 * pi * (r / wavelength) + phase_shift * k
amplitude += np.sin(phase)
ampMap[i] = [np.rad2deg(thetas[i]), abs(amplitude)]
return ampMap
ampMap = genAmpMap()
# Create line plot of points in ampMap
plt.plot(ampMap[:,0], ampMap[:,1])
plt.xlabel('Angle (degrees)')
plt.ylabel('Amplitude')
plt.title(f'Phased Array Simulation (phase shift = {math.degrees(phase_shift):.2f}°)')
plt.show()
# Create lineplot of the same, but polar coordinates
# plt.polar(np.deg2rad(ampMap[:,0]), ampMap[:,1])
# plt.title(f'Phased Array Simulation (phase shift = {math.degrees(phase_shift):.2f}°)')
# plt.show()