gold.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Thrifty 作者: swkrueger 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号