Last active
November 13, 2022 20:19
-
-
Save Btremaine/d2f861947fe3f49053116e7a679252e9 to your computer and use it in GitHub Desktop.
PRBS code in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TremaineConsultingGroup | |
# Brian Tremaine | |
# prbs.py | |
# August 11, 2021 | |
# Prototype PRBS generator | |
# | |
# PRBS15 = x^15 + x^14 + 1 Wikipeda | |
# .--->X--------------------------------------------------------> | |
# | | | | |
# bit | | | | |
# <----- D D D D D D D D D D D D D D D <-- | |
# | |
# bit15 <------------------------------- bit1 | |
# | |
# PRBS7 = x^7 + x^6 + 1 | |
# | |
# .--->X------------------------> | |
# | | | | |
# bit | | | | |
# <------ D D D D D D D <--| | |
# | |
# bit7 <--------------- bit1 | |
from scipy import signal | |
import matplotlib.pyplot as plt | |
""" ============ main ====================================== | |
""" | |
if __name__ == '__main__': | |
bit= list() | |
start = 1; | |
lfsr = start; | |
i= 1 | |
while True: | |
fb= ((lfsr>>14) ^ (lfsr>>13) & 1) | |
lfsr = ((lfsr<<1) + fb) & (2**15-1) | |
bit.append(fb) | |
print (i, lfsr, fb, bin(lfsr) ) | |
if lfsr==start : | |
print('repeat pattern length', i) | |
break; | |
i = i+1 | |
bit = [float(i) for i in bit] | |
for i in range(2**15-1): | |
bit[i]= 2*(bit[i] - 0.5) | |
plt.plot(bit); plt.title('PRBS') | |
plt.show() | |
u = signal.correlate(bit,bit) | |
plt.plot(u); plt.title('PRBS corr') | |
plt.show() | |
print("done!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment