defs.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import math
  2. import numpy as np
  3. class COMComponent:
  4. def __init__(self, epoch_size=100):
  5. self._epoch = epoch_size
  6. class Channel(COMComponent):
  7. """
  8. Communication base module containing all model structure.
  9. This model is just empty therefore just bypasses any input to output
  10. """
  11. def forward(self, values: np.ndarray) -> np.ndarray:
  12. """
  13. :param values: value generator, each iteration returns tuple of (amplitude, phase, frequency)
  14. :return: affected tuple of (amplitude, phase, frequency)
  15. """
  16. raise NotImplemented("Need to define forward function")
  17. class ModComponent(COMComponent):
  18. def __init__(self, alphabet_size, **kwargs):
  19. super().__init__(**kwargs)
  20. self.N = math.ceil(math.log2(alphabet_size))
  21. self.alphabet_size = alphabet_size
  22. class Modulator(ModComponent):
  23. def forward(self, binary: np.ndarray) -> np.ndarray:
  24. """
  25. :param binary: raw bytes as input (most be dtype=bool)
  26. :return: amplitude, phase, frequency
  27. """
  28. raise NotImplemented("Need to define forward function")
  29. class Demodulator(ModComponent):
  30. def forward(self, values: np.ndarray) -> np.ndarray:
  31. """
  32. :param values: value generator, each iteration returns tuple of (amplitude, phase, frequency)
  33. :return: binary resulting values (dtype=bool)
  34. """
  35. raise NotImplemented("Need to define forward function")