[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4612 - in gnuradio/branches/developers/jcorgan/glfsr/
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r4612 - in gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src: lib/general python/gnuradio/gr |
Date: |
Fri, 23 Feb 2007 11:16:16 -0700 (MST) |
Author: jcorgan
Date: 2007-02-23 11:16:16 -0700 (Fri, 23 Feb 2007)
New Revision: 4612
Added:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.cc
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/Makefile.am
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.h
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.i
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.h
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
Log:
Implementation of Galois LFSR source block.
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/Makefile.am
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/Makefile.am
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/Makefile.am
2007-02-23 18:16:16 UTC (rev 4612)
@@ -136,6 +136,7 @@
gri_float_to_char.cc \
gri_float_to_short.cc \
gri_float_to_uchar.cc \
+ gri_glfsr.cc \
gri_interleaved_short_to_complex.cc \
gri_short_to_float.cc \
gri_uchar_to_float.cc \
@@ -266,6 +267,7 @@
gri_float_to_char.h \
gri_float_to_short.h \
gri_float_to_uchar.h \
+ gri_glfsr.h \
gri_interleaved_short_to_complex.h \
gri_lfsr_15_1_0.h \
gri_lfsr_32k.h \
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc
2007-02-23 18:16:16 UTC (rev 4612)
@@ -43,10 +43,12 @@
d_repeat(repeat),
d_index(0)
{
- if (degree < 1 || degree > 31)
- throw std::out_of_range("gr_glfsr_source_b: degree must be between 1 and
31 inclusive");
+ if (degree < 1 || degree > 32)
+ throw std::runtime_error("gr_glfsr_source_b: degree must be between 1 and
32 inclusive");
d_length = (int)(1ULL << degree)-1;
+ if (mask == 0)
+ mask = gri_glfsr::glfsr_mask(degree);
d_glfsr = new gri_glfsr(mask, seed);
}
@@ -74,3 +76,9 @@
return i;
}
+
+int
+gr_glfsr_source_b::mask() const
+{
+ return d_glfsr->mask();
+}
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.h
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.h
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.h
2007-02-23 18:16:16 UTC (rev 4612)
@@ -58,6 +58,8 @@
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
+ unsigned int period() const { return d_length; }
+ int mask() const;
};
#endif /* INCLUDED_GR_GLFSR_SOURCE_B_H */
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.i
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.i
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gr_glfsr_source_b.i
2007-02-23 18:16:16 UTC (rev 4612)
@@ -22,10 +22,16 @@
GR_SWIG_BLOCK_MAGIC(gr,glfsr_source_b);
-gr_glfsr_source_b_sptr gr_make_glfsr_source_b(int degree, bool repeat=true,
int mask=0, int seed=1);
+gr_glfsr_source_b_sptr
+gr_make_glfsr_source_b(int degree, bool repeat=true, int mask=0, int seed=1)
+ throw (std::runtime_error);
class gr_glfsr_source_b : public gr_sync_block
{
- protected:
+protected:
gr_glfsr_source_b(int degree, bool repeat, int mask, int seed);
+
+public:
+ unsigned int period() const;
+ int mask() const;
};
Added:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.cc
(rev 0)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.cc
2007-02-23 18:16:16 UTC (rev 4612)
@@ -0,0 +1,67 @@
+/* -*- 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 2, 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_glfsr.h>
+#include <stdexcept>
+
+static int s_polynomial_masks[] = {
+ 0x00000000,
+ 0x00000001, // x^1 + 1
+ 0x00000003, // x^2 + x^1 + 1
+ 0x00000005, // x^3 + x^1 + 1
+ 0x00000009, // x^4 + x^1 + 1
+ 0x00000012, // x^5 + x^2 + 1
+ 0x00000021, // x^6 + x^1 + 1
+ 0x00000041, // x^7 + x^1 + 1
+ 0x0000008E, // x^8 + x^4 + x^3 + x^2 + 1
+ 0x00000108, // x^9 + x^4 + 1
+ 0x00000204, // x^10 + x^4 + 1
+ 0x00000402, // x^11 + x^2 + 1
+ 0x00000829, // x^12 + x^6 + x^4 + x^1 + 1
+ 0x0000100D, // x^13 + x^4 + x^3 + x^1 + 1
+ 0x00002015, // x^14 + x^5 + x^3 + x^1 + 1
+ 0x00004001, // x^15 + x^1 + 1
+ 0x00008016, // x^16 + x^5 + x^3 + x^2 + 1
+ 0x00010004, // x^17 + x^3 + 1
+ 0x00020013, // x^18 + x^5 + x^2 + x^1 + 1
+ 0x00040013, // x^19 + x^5 + x^2 + x^1 + 1
+ 0x00080004, // x^20 + x^3 + 1
+ 0x00100002, // x^21 + x^2 + 1
+ 0x00200001, // x^22 + x^1 + 1
+ 0x00400010, // x^23 + x^5 + 1
+ 0x0080000D, // x^24 + x^4 + x^3 + x^1 + 1
+ 0x01000004, // x^25 + x^3 + 1
+ 0x02000023, // x^26 + x^6 + x^2 + x^1 + 1
+ 0x04000013, // x^27 + x^5 + x^2 + x^1 + 1
+ 0x08000004, // x^28 + x^3 + 1
+ 0x10000002, // x^29 + x^2 + 1
+ 0x20000029, // x^30 + x^4 + x^1 + 1
+ 0x40000004, // x^31 + x^3 + 1
+ 0x80000057 // x^32 + x^7 + x^5 + x^3 + x^2 + x^1 + 1
+};
+
+int gri_glfsr::glfsr_mask(int degree)
+{
+ if (degree < 1 || degree > 32)
+ throw std::runtime_error("gri_glfsr::glfsr_mask(): degree must be between
1 and 32 inclusive");
+ return s_polynomial_masks[degree];
+}
Property changes on:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.h
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.h
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/lib/general/gri_glfsr.h
2007-02-23 18:16:16 UTC (rev 4612)
@@ -38,6 +38,7 @@
public:
gri_glfsr(int mask, int seed) { d_shift_register = seed; d_mask = mask; }
+ static int glfsr_mask(int degree);
unsigned char next_bit() {
unsigned char bit = d_shift_register & 1;
@@ -46,6 +47,8 @@
d_shift_register ^= d_mask;
return bit;
}
+
+ int mask() const { return d_mask; }
};
#endif /* INCLUDED_GRI_GLFSR_H */
Modified:
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
===================================================================
---
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
2007-02-23 16:54:07 UTC (rev 4611)
+++
gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
2007-02-23 18:16:16 UTC (rev 4612)
@@ -30,19 +30,31 @@
def tearDown (self):
self.fg = None
- def test_glfsr_source_b(self):
- src = gr.glfsr_source_b(10, False, 0x204) # x^10+x^3+1, length
2^10-1
- b2f = gr.chunks_to_symbols_bf((-1.0,1.0), 1)
- dst = gr.vector_sink_f()
- self.fg.connect(src, b2f, dst)
- self.fg.run()
+ def test_000_make(self):
+ src = gr.glfsr_source_b(16)
+ self.assertEquals(src.mask(), 0x8016)
+ self.assertEquals(src.period(), 2**16-1)
- actual_result = dst.data()
- R = auto_correlate(actual_result)
- self.assertEqual(R[0], float(len(R))) # Auto-correlation
peak at origin
- for i in range(len(R)-1):
- self.assertEqual(R[i+1], -1.0) # Auto-correlation
minimum everywhere else
+ def test_001_degree(self):
+ self.assertRaises(RuntimeError,
+ lambda: gr.glfsr_source_b(0))
+ self.assertRaises(RuntimeError,
+ lambda: gr.glfsr_source_b(33))
+
+ def test_002_correlation(self):
+ for degree in range(1,11): # Higher degrees take too
long to correlate
+ src = gr.glfsr_source_b(degree, False)
+ b2f = gr.chunks_to_symbols_bf((-1.0,1.0), 1)
+ dst = gr.vector_sink_f()
+ self.fg.connect(src, b2f, dst)
+ self.fg.run()
+ actual_result = dst.data()
+ R = auto_correlate(actual_result)
+ self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at
origin
+ for i in range(len(R)-1):
+ self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum
everywhere else
+
def auto_correlate(data):
l = len(data)
R = [0,]*l
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4612 - in gnuradio/branches/developers/jcorgan/glfsr/gnuradio-core/src: lib/general python/gnuradio/gr,
jcorgan <=