Last active
August 22, 2021 19:55
-
-
Save Btremaine/c3a48e0baab539e0cb562635f0e6ecc6 to your computer and use it in GitHub Desktop.
prbs C code Example 1
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
// replicated from wikipeda, https://en.wikipedia.org/wiki/Pseudorandom_binary_sequence | |
// Example of PRBS7 | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
int main(int argc, char* argv[]) { | |
uint8_t start = 0x02; | |
uint8_t a = start; | |
int i; | |
for (i = 1;; i++) { | |
int newbit = (((a >> 6) ^ (a >> 5)) & 1); | |
a = ((a << 1) | newbit) & 0x7f; | |
printf("%x\n", a); | |
if (a == start) { | |
printf("repetition period is %d\n", i); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment