Created
August 6, 2014 13:10
-
-
Save vrootic/0e1cdf95f20dee18d6e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def packed_bytes_to_iq(self, bytes): | |
''' Convenience function to unpack array of bytes to Python list/array | |
of complex numbers and normalize range. Called automatically by read_samples() | |
''' | |
if has_numpy: | |
# use NumPy array | |
iq = np.empty(len(bytes)//2, 'complex') | |
iq.real, iq.imag = bytes[::2], bytes[1::2] | |
iq /= (255/2) | |
iq -= (1 + 1j) | |
else: | |
# use normal list | |
iq = [complex(i/(255/2) - 1, q/(255/2) - 1) for i, q in izip(bytes[::2], bytes[1::2])] | |
return iq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment