summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/general/gri_lfsr.h
diff options
context:
space:
mode:
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2008-09-12 02:54:22 +0000
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2008-09-12 02:54:22 +0000
commitc4763fb9f73df6832a015d84111cd2573a7b9bc6 (patch)
treee2691291da9297b8ecb43b22e98ddbb972592ac8 /gnuradio-core/src/lib/general/gri_lfsr.h
parent26e4afc44d2d0e77c2f6c41dff43555b3c9166e6 (diff)
Merged -r9556:9560 from jcorgan/scr into trunk. Adds gr.scrambler_bb and gr.descrambler_bb, using updated gri_lfsr.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9561 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib/general/gri_lfsr.h')
-rw-r--r--gnuradio-core/src/lib/general/gri_lfsr.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/gnuradio-core/src/lib/general/gri_lfsr.h b/gnuradio-core/src/lib/general/gri_lfsr.h
index 29873698c1..b6eee76793 100644
--- a/gnuradio-core/src/lib/general/gri_lfsr.h
+++ b/gnuradio-core/src/lib/general/gri_lfsr.h
@@ -58,15 +58,29 @@
*
*
*
- * next_bit() - performs once cycle of the lfsr,
- * generating the new high order bit from the mask
- * and returning the low order bit which has been
- * shifted out of the register.
+ * next_bit() - Standard LFSR operation
+ *
+ * Perform one cycle of the LFSR. The output bit is taken from
+ * the shift register LSB. The shift register MSB is assigned from
+ * the modulo 2 sum of the masked shift register.
+ *
+ * next_bit_scramble(unsigned char input) - Scramble an input stream
+ *
+ * Perform one cycle of the LFSR. The output bit is taken from
+ * the shift register LSB. The shift register MSB is assigned from
+ * the modulo 2 sum of the masked shift register and the input LSB.
+ *
+ * next_bit_descramble(unsigned char input) - Descramble an input stream
*
+ * Perform one cycle of the LFSR. The output bit is taken from
+ * the modulo-2 sum of the masked shift register and the input LSB.
+ * The shift register MSB is assigned from the LSB of the input.
+ *
+ * See http://en.wikipedia.org/wiki/Scrambler for operation of these
+ * last two functions (see multiplicative scrambler.)
*
*/
-
class gri_lfsr
{
private:
@@ -92,12 +106,27 @@ class gri_lfsr
}
unsigned char next_bit() {
- unsigned char bit = d_shift_register & 1;
+ unsigned char output = d_shift_register & 1;
unsigned char newbit = popCount( d_shift_register & d_mask )%2;
d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
- return bit;
+ return output;
+ }
+
+ unsigned char next_bit_scramble(unsigned char input) {
+ unsigned char output = d_shift_register & 1;
+ unsigned char newbit = (popCount( d_shift_register & d_mask )%2)^(input & 1);
+ d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
+ return output;
+ }
+
+ unsigned char next_bit_descramble(unsigned char input) {
+ unsigned char output = (popCount( d_shift_register & d_mask )%2)^(input & 1);
+ unsigned char newbit = input & 1;
+ d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
+ return output;
}
+
/*!
* Rotate the register through x number of bits
* where we are just throwing away the results to get queued up correctly