Sunday, August 2, 2020

PRBS using linear feedback shift register implemented in Python

#! /usr/bin/env python3

def prbs_gen(msg, bitwidth, poly, seed, pam_mode):
    print(msg, 'poly=', poly, 'seed=', seed, ':')
    mask = ~((~0)<<bitwidth);
    lfsr = seed
    period = 0
    bit = 0

    while period < 32:
        for x in range(pam_mode+1):
            bit <<= 1
            bit |= cal_parity(mask&(poly&lfsr))
            lfsr = mask & ( (lfsr <<1) | (bit&1) )

        if pam_mode == 1 :
            bit &= 0x3
            gray_code_dict = {0:0, 1:1, 2:3, 3:2}
            bit = gray_code_dict[bit];
        else:
            bit &=0x1

        if period%4 == 0:
            print(' ', end='')

        print(bit, end='')
        period += 1
    print('\n')
    return period


def cal_parity(value):
    value ^= (value>>16)
    value ^= (value>>8)
    value ^= (value>>4)
    value &= 0xf
    return (0x6996>>value)&0x1

#below are example unction calls for some prbs types:
prbs_gen('LT136/LT162 prbs13Q 0', 13, 0x1803, 0x1aa0, 1);
prbs_gen('LT136/LT162 prbs13Q 1', 13, 0x1046, 0x105c, 1);
prbs_gen('LT136/LT162 prbs13Q 2', 13, 0x108a, 0x0689, 1);
prbs_gen('LT136/LT162 prbs13Q 3', 13, 0x1112, 0x0822, 1);
prbs_gen('LT93 prbs11 0', 11, 0x630, 0x3f5, 0);
prbs_gen('LT93 prbs11 1', 11, 0x530, 0x513, 0);
prbs_gen('LT93 prbs11 2', 11, 0x4a8, 0x5a7, 0);
prbs_gen('LT93 prbs11 3', 11, 0x468, 0x36f, 0);
prbs_gen('LT72 prbs11 0', 11, 0x503, 0x36f, 0);

C Programming

Header Files and Includes https://cplusplus.com/forum/articles/10627/ https://stackoverflow.com/questions/2762568/c-c-include-header-file-or...