dsp: pre-compute polynome bit_length

since Python 2.6 has no .bit_length() method
This commit is contained in:
Roman Zeyde
2015-02-13 15:08:11 +02:00
parent 807c03a8e8
commit c0634a34d0

View File

@@ -114,9 +114,13 @@ class MODEM(object):
def prbs(reg, poly, bits):
''' Simple pseudo-random number generator. '''
mask = (1 << bits) - 1
size = 0 # effective register size (in bits)
while (poly >> size) > 1:
size += 1
while True:
yield reg & mask
reg = reg << 1
size = poly.bit_length() - 1
if reg >> size:
reg = reg ^ poly