2022-09-26 17:18:07 +02:00
|
|
|
"""
|
|
|
|
Library for this simulation
|
|
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from earsim import Antenna
|
|
|
|
|
2022-11-10 15:08:00 +01:00
|
|
|
def sine_beacon(f, t, t0=0, amplitude=1, baseline=0):
|
|
|
|
return amplitude * np.sin(2*np.pi*f*(t-t0)) + baseline
|
2022-09-26 17:18:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
def distance(x1, x2):
|
|
|
|
"""
|
|
|
|
Calculate the Euclidean distance between two locations x1 and x2
|
|
|
|
"""
|
|
|
|
|
|
|
|
assert type(x1) in [Antenna]
|
|
|
|
x1 = np.array([x1.x, x1.y, x1.z])
|
|
|
|
|
|
|
|
assert type(x2) in [Antenna]
|
|
|
|
x2 = np.array([x2.x, x2.y, x2.z])
|
|
|
|
|
|
|
|
return np.sqrt( np.sum( (x1-x2)**2 ) )
|
|
|
|
|
2022-11-10 15:08:00 +01:00
|
|
|
def beacon_from(tx, rx, f, t=0, t0=0, c_light=3e8, radiate_rsq=True, amplitude=1,**kwargs):
|
|
|
|
dist = distance(tx,rx)
|
2022-09-26 17:18:07 +02:00
|
|
|
t0 = t0 + dist/c_light
|
|
|
|
|
2022-11-10 15:08:00 +01:00
|
|
|
if radiate_rsq:
|
|
|
|
amplitude *= 1/(dist**2)
|
|
|
|
|
|
|
|
return sine_beacon(f, t, t0=t0, amplitude=amplitude,**kwargs)
|