11 #ifndef INCLUDED_DIGITAL_LFSR_H
12 #define INCLUDED_DIGITAL_LFSR_H
81 uint32_t d_shift_register;
84 uint32_t d_shift_register_length;
86 static uint32_t popCount(uint32_t x)
88 uint32_t r = x - ((x >> 1) & 033333333333) - ((x >> 2) & 011111111111);
89 return ((r + (r >> 3)) & 030707070707) % 63;
93 lfsr(uint32_t
mask, uint32_t seed, uint32_t reg_len)
94 : d_shift_register(seed),
97 d_shift_register_length(reg_len)
100 throw std::invalid_argument(
"reg_len must be <= 31");
105 unsigned char output = d_shift_register & 1;
106 unsigned char newbit = popCount(d_shift_register & d_mask) % 2;
108 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
114 unsigned char output = d_shift_register & 1;
115 unsigned char newbit = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
117 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
123 unsigned char output = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
124 unsigned char newbit = input & 1;
126 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
133 void reset() { d_shift_register = d_seed; }
141 for (
int i = 0; i < num; i++) {
146 int mask()
const {
return d_mask; }
Fibonacci Linear Feedback Shift Register using specified polynomial mask.
Definition: lfsr.h:79
lfsr(uint32_t mask, uint32_t seed, uint32_t reg_len)
Definition: lfsr.h:93
void pre_shift(int num)
Definition: lfsr.h:139
void reset()
Definition: lfsr.h:133
int mask() const
Definition: lfsr.h:146
unsigned char next_bit_descramble(unsigned char input)
Definition: lfsr.h:121
unsigned char next_bit()
Definition: lfsr.h:103
unsigned char next_bit_scramble(unsigned char input)
Definition: lfsr.h:112
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29