[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9492 - gnuradio/trunk/gnuradio-core/src/lib/general
From: |
eb |
Subject: |
[Commit-gnuradio] r9492 - gnuradio/trunk/gnuradio-core/src/lib/general |
Date: |
Wed, 3 Sep 2008 10:12:07 -0600 (MDT) |
Author: eb
Date: 2008-09-03 10:12:06 -0600 (Wed, 03 Sep 2008)
New Revision: 9492
Added:
gnuradio/trunk/gnuradio-core/src/lib/general/gri_lfsr.h
gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.h
Modified:
gnuradio/trunk/gnuradio-core/src/lib/general/Makefile.am
gnuradio/trunk/gnuradio-core/src/lib/general/qa_general.cc
Log:
Fibonacci Linear Feedback Shift Register
Modified: gnuradio/trunk/gnuradio-core/src/lib/general/Makefile.am
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/Makefile.am 2008-09-03
15:36:34 UTC (rev 9491)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/Makefile.am 2008-09-03
16:12:06 UTC (rev 9492)
@@ -176,7 +176,8 @@
qa_gr_fxpt.cc \
qa_gr_fxpt_nco.cc \
qa_gr_fxpt_vco.cc \
- qa_gr_math.cc
+ qa_gr_math.cc \
+ qa_gri_lfsr.cc
grinclude_HEADERS = \
gr_agc_cc.h \
Added: gnuradio/trunk/gnuradio-core/src/lib/general/gri_lfsr.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gri_lfsr.h
(rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gri_lfsr.h 2008-09-03
16:12:06 UTC (rev 9492)
@@ -0,0 +1,104 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GRI_LFSR_H
+#define INCLUDED_GRI_LFSR_H
+
+#include <stdexcept>
+#include <stdint.h>
+
+/*!
+ * \brief Fibonacci Linear Feedback Shift Register using specified polynomial
mask
+ * \ingroup math
+ *
+ * Generates a maximal length pseudo-random sequence of length 2^degree-1
+ *
+ * Constructor: gri_lfsr(int mask, int seed, int reg_len);
+ *
+ * mask - polynomial coefficients representing the locations
+ * of feedback taps from a shift register which are xor'ed
+ * together to form the new high order bit.
+ *
+ * Some common masks might be:
+ * x^4 + x^3 + x^0 = 0x19
+ * x^5 + x^3 + x^0 = 0x29
+ * x^6 + x^5 + x^0 = 0x61
+ *
+ * seed - the initialization vector placed into the register
+ * durring initialization. Low order bit corresponds
+ * to x^0 coefficient -- the first to be shifted as output.
+ *
+ * reg_len - specifies the length of the feedback shift register
+ * to be used. Durring each iteration, the register
+ * is rightshifted one and the new bit is placed in bit reg_len.
+ * reg_len should generally be at least order(mask) + 1
+ *
+ *
+ * see http://en.wikipedia.org/wiki/Linear_feedback_shift_register
+ * for more explanation.
+ *
+ *
+ *
+ * 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.
+ *
+ *
+ */
+
+
+class gri_lfsr
+{
+ private:
+ uint32_t d_shift_register;
+ uint32_t d_mask;
+ uint32_t d_shift_register_length; // less than 32
+
+ static uint32_t
+ popCount(uint32_t x)
+ {
+ uint32_t r = x - ((x >> 1) & 033333333333)
+ - ((x >> 2) & 011111111111);
+ return ((r + (r >> 3)) & 030707070707) % 63;
+ }
+
+ public:
+
+ gri_lfsr(uint32_t mask, uint32_t seed, uint32_t reg_len)
+ : d_shift_register(seed), d_mask(mask), d_shift_register_length(reg_len)
+ {
+ if (reg_len > 31)
+ throw std::invalid_argument("reg_len must be <= 31");
+ }
+
+ unsigned char next_bit() {
+ unsigned char bit = 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;
+ }
+
+ int mask() const { return d_mask; }
+};
+
+#endif /* INCLUDED_GRI_LFSR_H */
Property changes on: gnuradio/trunk/gnuradio-core/src/lib/general/gri_lfsr.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: gnuradio/trunk/gnuradio-core/src/lib/general/qa_general.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/qa_general.cc 2008-09-03
15:36:34 UTC (rev 9491)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/qa_general.cc 2008-09-03
16:12:06 UTC (rev 9492)
@@ -32,6 +32,7 @@
#include <qa_gr_fxpt_nco.h>
#include <qa_gr_fxpt_vco.h>
#include <qa_gr_math.h>
+#include <qa_gri_lfsr.h>
CppUnit::TestSuite *
qa_general::suite ()
@@ -44,6 +45,7 @@
s->addTest (qa_gr_fxpt_nco::suite ());
s->addTest (qa_gr_fxpt_vco::suite ());
s->addTest (qa_gr_math::suite ());
+ s->addTest (qa_gri_lfsr::suite ());
return s;
}
Added: gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
(rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.cc 2008-09-03
16:12:06 UTC (rev 9492)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gri_lfsr.h>
+#include <qa_gri_lfsr.h>
+#include <cppunit/TestAssert.h>
+#include <stdio.h>
+
+void
+qa_gri_lfsr::test_lfsr ()
+{
+ int mask = 0x19;
+ int seed = 0x01;
+ int length = 5;
+
+ gri_lfsr lfsr1(mask,seed,length);
+ gri_lfsr lfsr2(mask,seed,length);
+
+ unsigned char expected[] = {1, 0, 1, 1, 0, 1, 0, 1, 0, 0};
+
+ for(unsigned int i=0; i<31; i++){
+ lfsr1.next_bit();
+ }
+
+ // test that after one lfsr cycle we still match out uncycled lfsr
+ for (unsigned int i = 0; i < 41; i++) {
+ CPPUNIT_ASSERT_EQUAL((int) lfsr1.next_bit(), (int) lfsr2.next_bit());
+ }
+
+ // test the known correct values at the given shift offset
+ for(unsigned int i=0; i<10; i++){
+ CPPUNIT_ASSERT_EQUAL((int) lfsr1.next_bit(), (int) expected[i]);
+ }
+
+ // test for register length too long
+ CPPUNIT_ASSERT_THROW(gri_lfsr(mask, seed, 32), std::invalid_argument);
+}
+
Property changes on: gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added: gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.h
(rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.h 2008-09-03
16:12:06 UTC (rev 9492)
@@ -0,0 +1,38 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef _QA_GRI_LFSR_H_
+#define _QA_GRI_LFSR_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_gri_lfsr : public CppUnit::TestCase {
+
+ CPPUNIT_TEST_SUITE(qa_gri_lfsr);
+ CPPUNIT_TEST(test_lfsr);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ void test_lfsr();
+};
+
+#endif /* _QA_GRI_LFSR_H_ */
Property changes on: gnuradio/trunk/gnuradio-core/src/lib/general/qa_gri_lfsr.h
___________________________________________________________________
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9492 - gnuradio/trunk/gnuradio-core/src/lib/general,
eb <=