defs.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import math
  2. import numpy as np
  3. class Signal:
  4. @property
  5. def rect_x(self) -> np.ndarray:
  6. return self.rect[:, 0]
  7. @property
  8. def rect_y(self) -> np.ndarray:
  9. return self.rect[:, 1]
  10. @property
  11. def rect(self) -> np.ndarray:
  12. raise NotImplemented("Not implemented")
  13. def set_rect_xy(self, x_mat: np.ndarray, y_mat: np.ndarray):
  14. raise NotImplemented("Not implemented")
  15. def set_rect(self, mat: np.ndarray):
  16. raise NotImplemented("Not implemented")
  17. @property
  18. def apf(self):
  19. raise NotImplemented("Not implemented")
  20. class COMComponent:
  21. def __init__(self, epoch_size=100):
  22. self._epoch = epoch_size
  23. class Channel(COMComponent):
  24. """
  25. Communication base module containing all model structure.
  26. This model is just empty therefore just bypasses any input to output
  27. """
  28. def forward(self, values: Signal) -> Signal:
  29. """
  30. :param values: value generator, each iteration returns tuple of (amplitude, phase, frequency)
  31. :return: affected tuple of (amplitude, phase, frequency)
  32. """
  33. raise NotImplemented("Need to define forward function")
  34. class ModComponent(COMComponent):
  35. def __init__(self, alphabet_size, **kwargs):
  36. super().__init__(**kwargs)
  37. self.N = math.ceil(math.log2(alphabet_size))
  38. self.alphabet_size = alphabet_size
  39. class Modulator(ModComponent):
  40. def forward(self, binary: np.ndarray) -> Signal:
  41. """
  42. :param binary: raw bytes as input (most be dtype=bool)
  43. :return: amplitude, phase, frequency
  44. """
  45. raise NotImplemented("Need to define forward function")
  46. class Demodulator(ModComponent):
  47. def forward(self, values: Signal) -> np.ndarray:
  48. """
  49. :param values: value generator, each iteration returns tuple of (amplitude, phase, frequency)
  50. :return: binary resulting values (dtype=bool)
  51. """
  52. raise NotImplemented("Need to define forward function")