mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
(semi-)revert ab20db4
: Antenna encapsulates a digitizer
Antenna should not encapsulate a Digitizer in this way. Maybe it can be added later, but I see mostly complexiy in that design.
This commit is contained in:
parent
10d91519bf
commit
d04dfac64e
1 changed files with 5 additions and 35 deletions
|
@ -1,7 +1,6 @@
|
|||
from functools import partial
|
||||
|
||||
from .location import Location
|
||||
from ..sampling import Digitizer
|
||||
|
||||
class Antenna(Location):
|
||||
"""
|
||||
|
@ -12,56 +11,27 @@ class Antenna(Location):
|
|||
Optionally uses digitizer to transform the signal
|
||||
when receiving.
|
||||
"""
|
||||
def __init__(self, x, digitizer=None):
|
||||
def __init__(self, x):
|
||||
super().__init__(x)
|
||||
|
||||
self.digitizer = digitizer
|
||||
|
||||
def __repr__(self):
|
||||
return "Antenna({}, {})".format(repr(self.x), repr(self.x))
|
||||
|
||||
def _digitise_partial(self, signal: callable, *args, digitise=True, **kwargs) -> callable:
|
||||
"""
|
||||
A wrapper around functools.partial to support optionally
|
||||
digitising the returned signal.
|
||||
"""
|
||||
if self.digitizer and digitise:
|
||||
signal = self.digitizer.digitise(signal)
|
||||
|
||||
return partial(signal, *args, **kwargs)
|
||||
|
||||
|
||||
def emit(self, signal: callable, digitise=False) -> callable:
|
||||
def emit(self, signal: callable) -> callable:
|
||||
"""
|
||||
Return a function that emits a signal from the antenna's location
|
||||
"""
|
||||
return self._digitise_partial(signal, x_0=self.x, digitise=digitise)
|
||||
return partial(signal, x_0=self.x)
|
||||
|
||||
def recv(self, signal: callable, digitise=True) -> callable:
|
||||
def recv(self, signal: callable) -> callable:
|
||||
"""
|
||||
Return a function that traces the signal as a function of time
|
||||
at the antenna's location
|
||||
"""
|
||||
return self._digitise_partial(signal, x_f=self.x, digitise=digitise)
|
||||
return partial(signal, x_f=self.x)
|
||||
|
||||
receive = recv
|
||||
|
||||
# math
|
||||
def __add__(self, other):
|
||||
if isinstance(other, Location):
|
||||
other = other.x
|
||||
|
||||
return self.__class__(self.x + other, self.digitizer)
|
||||
|
||||
def __sub__(self, other):
|
||||
if isinstance(other, Location):
|
||||
other = other.x
|
||||
|
||||
return self.__class__(self.x - other, self.digitizer)
|
||||
|
||||
def __mul__(self, other):
|
||||
return self.__class__(self.x * other, self.digitizer)
|
||||
|
||||
class Receiver(Antenna):
|
||||
"""
|
||||
An antenna which main purpose is to trace a signal over time.
|
||||
|
|
Loading…
Reference in a new issue