23 #ifndef INCLUDED_DIGITAL_LFSR_H 24 #define INCLUDED_DIGITAL_LFSR_H 93 uint32_t d_shift_register;
96 uint32_t d_shift_register_length;
98 static uint32_t popCount(uint32_t x)
100 uint32_t r = x - ((x >> 1) & 033333333333) - ((x >> 2) & 011111111111);
101 return ((r + (r >> 3)) & 030707070707) % 63;
105 lfsr(uint32_t
mask, uint32_t seed, uint32_t reg_len)
106 : d_shift_register(seed),
109 d_shift_register_length(reg_len)
112 throw std::invalid_argument(
"reg_len must be <= 31");
117 unsigned char output = d_shift_register & 1;
118 unsigned char newbit = popCount(d_shift_register & d_mask) % 2;
120 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
126 unsigned char output = d_shift_register & 1;
127 unsigned char newbit = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
129 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
135 unsigned char output = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
136 unsigned char newbit = input & 1;
138 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
145 void reset() { d_shift_register = d_seed; }
153 for (
int i = 0; i < num; i++) {
158 int mask()
const {
return d_mask; }
unsigned char next_bit_descramble(unsigned char input)
Definition: lfsr.h:133
unsigned char next_bit_scramble(unsigned char input)
Definition: lfsr.h:124
unsigned char next_bit()
Definition: lfsr.h:115
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
void pre_shift(int num)
Definition: lfsr.h:151
lfsr(uint32_t mask, uint32_t seed, uint32_t reg_len)
Definition: lfsr.h:105
void reset()
Definition: lfsr.h:145
Fibonacci Linear Feedback Shift Register using specified polynomial mask.
Definition: lfsr.h:90
int mask() const
Definition: lfsr.h:158