11 #ifndef INCLUDED_DIGITAL_LFSR_H
12 #define INCLUDED_DIGITAL_LFSR_H
82 uint32_t d_shift_register;
85 uint32_t d_shift_register_length;
87 static uint32_t popCount(uint32_t x)
89 uint32_t r = x - ((x >> 1) & 033333333333) - ((x >> 2) & 011111111111);
90 return ((r + (r >> 3)) & 030707070707) % 63;
94 lfsr(uint32_t
mask, uint32_t seed, uint32_t reg_len)
95 : d_shift_register(seed),
98 d_shift_register_length(reg_len)
101 throw std::invalid_argument(
"reg_len must be <= 31");
106 unsigned char output = d_shift_register & 1;
107 unsigned char newbit = popCount(d_shift_register & d_mask) % 2;
109 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
115 unsigned char output = d_shift_register & 1;
116 unsigned char newbit = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
118 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
124 unsigned char output = (popCount(d_shift_register & d_mask) % 2) ^ (input & 1);
125 unsigned char newbit = input & 1;
127 ((d_shift_register >> 1) | (newbit << d_shift_register_length));
134 void reset() { d_shift_register = d_seed; }
142 for (
int i = 0; i < num; i++) {
147 int mask()
const {
return d_mask; }
Fibonacci Linear Feedback Shift Register using specified polynomial mask.
Definition: lfsr.h:80
lfsr(uint32_t mask, uint32_t seed, uint32_t reg_len)
Definition: lfsr.h:94
void pre_shift(int num)
Definition: lfsr.h:140
void reset()
Definition: lfsr.h:134
int mask() const
Definition: lfsr.h:147
unsigned char next_bit_descramble(unsigned char input)
Definition: lfsr.h:122
unsigned char next_bit()
Definition: lfsr.h:104
unsigned char next_bit_scramble(unsigned char input)
Definition: lfsr.h:113
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29