You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

goalref_sample.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. '''
  2. ******************************************************************************
  3. * (c) 2015 Fraunhofer Institut Integrierte Schaltungen, Nuernberg
  4. * All Rights Reserved
  5. ******************************************************************************
  6. Represents one sample from the GoalRef frontend and provides accessors
  7. to each channel's data.
  8. @author: muellead
  9. '''
  10. import numpy
  11. class GoalrefSample:
  12. """!
  13. @brief
  14. """
  15. NUM_FREQUENCIES = 4
  16. NUM_CHANNELS = 21
  17. def __init__(self, sample, numAntennas = None, packetId=None):
  18. '''
  19. Creates a sample based on a numpy array constructed
  20. from raw received data.
  21. To use antenna oriented accessors the number of antennas
  22. must be given.
  23. '''
  24. self._sample = sample.reshape((self.NUM_FREQUENCIES,self.NUM_CHANNELS))
  25. self._numAntennas = numAntennas
  26. self._packetId = packetId
  27. def applyPermutation(self, channelPermutation):
  28. """
  29. Applies the given array as a channel permutation to this sample's values.
  30. The array must contain NUM_CHANNELS elements as this sample's data will
  31. otherwise be incomplete.
  32. """
  33. self._sample = self._sample[:,channelPermutation]
  34. def getRawData(self):
  35. return self._sample
  36. def getChannel(self, chan):
  37. '''
  38. Gets the sample data for all frequencies of the given channel number.
  39. Returns a numpy array of NUM_FREQ complex sample values.
  40. '''
  41. return numpy.array([self._sample[f][chan] for f in range(self.NUM_FREQUENCIES)])
  42. def getSampleVal(self, chan, freq):
  43. '''
  44. Gets a single sample value for the given channel and frequency.
  45. '''
  46. return self._sample[freq][chan]
  47. def getPacketId(self):
  48. '''
  49. Gets the sample id from the hardware.
  50. '''
  51. return self._packetId
  52. def getFrequencyMain(self, freq):
  53. '''
  54. Gets all main antenna sample values for the given frequency.
  55. '''
  56. if not self._numAntennas:
  57. raise Exception('Antenna count unknown')
  58. return self._sample[freq][1:self._numAntennas*2:2]
  59. def getFrequencyFrame(self, freq):
  60. '''
  61. Gets all frame antenna sample values for the given frequency.
  62. '''
  63. if not self._numAntennas:
  64. raise Exception('Antenna count unknown')
  65. return self._sample[freq][0:self._numAntennas*2:2]
  66. def getFrequency(self, freq):
  67. '''
  68. Gets all samples values (main and frame in raw channel order) for the given frequency.
  69. '''
  70. if not self._numAntennas:
  71. raise Exception('Antenna count unknown')
  72. return self._sample[freq][0:self._numAntennas*2]
  73. def printSample(self):
  74. print('Sample data:')
  75. print(self._sample)