Skip to content

Instantly share code, notes, and snippets.

@vrootic
Created August 6, 2014 13:10
Show Gist options
  • Save vrootic/0e1cdf95f20dee18d6e5 to your computer and use it in GitHub Desktop.
Save vrootic/0e1cdf95f20dee18d6e5 to your computer and use it in GitHub Desktop.
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