def gold(bits, idx):
"""Generate the idx-th Gold code of length 2^bits - 1.
Parameters
----------
bits : int
Length of LFSR. The length of the gold code will be
:math:`2^{\\mathtt{bits}} - 1`.
idx : int
Index of the code to generate within the set of gold codes, where
:math:`0 \\le \\mathtt{idx} < 2^{\\mathtt{bits}} + 1`.
"""
bits = int(bits)
if bits not in TAPS:
raise ValueError('Preferred pairs for %d bits unknown.' % bits)
seed = np.ones(bits, dtype=bool)
seq1 = lfsr(TAPS[bits][0], seed)
seq2 = lfsr(TAPS[bits][1], seed)
if idx == 0:
return seq1
elif idx == 1:
return seq2
else:
return np.logical_xor(seq1, np.roll(seq2, -idx + 2))
评论列表
文章目录