commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4840 - in gnuradio/branches/developers/jcorgan/channe


From: jcorgan
Subject: [Commit-gnuradio] r4840 - in gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src: lib/general python/gnuradio/gr
Date: Sun, 1 Apr 2007 21:07:58 -0600 (MDT)

Author: jcorgan
Date: 2007-04-01 21:07:57 -0600 (Sun, 01 Apr 2007)
New Revision: 4840

Added:
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
Removed:
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
Modified:
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/Makefile.am
   
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/general.i
Log:
Added gr_glfsr_source_f generating floats from -1.0 to 1.0.

Modified: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/Makefile.am
      2007-04-01 21:05:44 UTC (rev 4839)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/Makefile.am
      2007-04-02 03:07:57 UTC (rev 4840)
@@ -77,6 +77,7 @@
        gr_fxpt.cc                      \
        gr_framer_sink_1.cc             \
        gr_glfsr_source_b.cc            \
+       gr_glfsr_source_f.cc            \
        gr_head.cc                      \
        gr_interleave.cc                \
        gr_interleaved_short_to_complex.cc \
@@ -200,6 +201,7 @@
        gr_fxpt_nco.h                   \
        gr_fxpt_vco.h                   \
        gr_glfsr_source_b.h             \
+       gr_glfsr_source_f.h             \
        gr_head.h                       \
        gr_interleave.h                 \
        gr_interleaved_short_to_complex.h \
@@ -330,6 +332,7 @@
        gr_frequency_modulator_fc.i     \
        gr_framer_sink_1.i              \
        gr_glfsr_source_b.i             \
+       gr_glfsr_source_f.i             \
        gr_head.i                       \
        gr_interleave.i                 \
        gr_interleaved_short_to_complex.i \

Modified: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/general.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/general.i
        2007-04-01 21:05:44 UTC (rev 4839)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/general.i
        2007-04-02 03:07:57 UTC (rev 4840)
@@ -111,6 +111,7 @@
 #include <gr_feedforward_agc_cc.h>
 #include <gr_bin_statistics_f.h>
 #include <gr_glfsr_source_b.h>
+#include <gr_glfsr_source_f.h>
 %}
 
 %include "gr_nop.i"
@@ -202,3 +203,4 @@
 %include "gr_feedforward_agc_cc.i"
 %include "gr_bin_statistics_f.i"
 %include "gr_glfsr_source_b.i"
+%include "gr_glfsr_source_f.i"

Added: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
                             (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
     2007-04-02 03:07:57 UTC (rev 4840)
@@ -0,0 +1,84 @@
+/* -*- 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gr_glfsr_source_f.h>
+#include <gri_glfsr.h>
+#include <gr_io_signature.h>
+#include <stdexcept>
+
+gr_glfsr_source_f_sptr 
+gr_make_glfsr_source_f(int degree, bool repeat, int mask, int seed)
+{
+  return gr_glfsr_source_f_sptr(new gr_glfsr_source_f(degree, repeat, mask, 
seed));
+}
+
+gr_glfsr_source_f::gr_glfsr_source_f(int degree, bool repeat, int mask, int 
seed)
+  : gr_sync_block ("glfsr_source_f",
+                  gr_make_io_signature (0, 0, 0),
+                  gr_make_io_signature (1, 1, sizeof(float))),
+    d_repeat(repeat),
+    d_index(0)
+{
+  if (degree < 1 || degree > 32)
+    throw std::runtime_error("gr_glfsr_source_f: degree must be between 1 and 
32 inclusive");
+  d_length = (unsigned int)((1ULL << degree)-1);
+
+  if (mask == 0)
+    mask = gri_glfsr::glfsr_mask(degree);
+  d_glfsr = new gri_glfsr(mask, seed);
+}
+
+gr_glfsr_source_f::~gr_glfsr_source_f()
+{
+  delete d_glfsr;
+}
+
+int
+gr_glfsr_source_f::work(int noutput_items,
+                       gr_vector_const_void_star &input_items,
+                       gr_vector_void_star &output_items)
+{
+  float *out = (float *) output_items[0];
+  if ((d_index > d_length) && d_repeat == false)
+    return -1; /* once through the sequence */
+
+  int i;
+  for (i = 0; i < noutput_items; i++) {
+    out[i] = (float)d_glfsr->next_bit()*2.0-1.0;
+    d_index++;
+    if (d_index > d_length && d_repeat == false)
+      break;
+  }
+
+  return i;
+}
+
+int
+gr_glfsr_source_f::mask() const
+{
+  return d_glfsr->mask();
+}


Property changes on: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
                              (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
      2007-04-02 03:07:57 UTC (rev 4840)
@@ -0,0 +1,65 @@
+/* -*- 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.
+ */
+
+#ifndef INCLUDED_GR_GLFSR_SOURCE_F_H
+#define INCLUDED_GR_GLFSR_SOURCE_F_H
+
+#include <gr_sync_block.h>
+
+class gri_glfsr;
+
+class gr_glfsr_source_f;
+typedef boost::shared_ptr<gr_glfsr_source_f> gr_glfsr_source_f_sptr;
+
+gr_glfsr_source_f_sptr gr_make_glfsr_source_f(int degree, bool repeat=true, 
int mask=0, int seed=1);
+
+/*!
+ * \brief Galois LFSR pseudo-random source generating float outputs -1.0 - 1.0
+ * \ingroup source
+ */
+class gr_glfsr_source_f : public gr_sync_block 
+{
+ private:
+  friend gr_glfsr_source_f_sptr
+  gr_make_glfsr_source_f(int degree, bool repeat, int mask, int seed);
+  
+  gri_glfsr *d_glfsr;
+
+  bool d_repeat;
+  unsigned int d_index;
+  unsigned int d_length;
+  
+  gr_glfsr_source_f(int degree, bool repeat, int mask, int seed);
+
+ public:
+
+  ~gr_glfsr_source_f();
+
+  int work(int noutput_items,
+          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_F_H */


Property changes on: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
                              (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
      2007-04-02 03:07:57 UTC (rev 4840)
@@ -0,0 +1,37 @@
+/* -*- 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.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,glfsr_source_f);
+
+gr_glfsr_source_f_sptr 
+gr_make_glfsr_source_f(int degree, bool repeat=true, int mask=0, int seed=1)
+  throw (std::runtime_error);
+
+class gr_glfsr_source_f : public gr_sync_block 
+{
+protected:
+  gr_glfsr_source_f(int degree, bool repeat, int mask, int seed);
+
+public:
+  unsigned int period() const;
+  int mask() const;
+};


Property changes on: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
 (from rev 4837, 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py)
===================================================================
--- 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
                                (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
        2007-04-02 03:07:57 UTC (rev 4840)
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# 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.
+# 
+
+from gnuradio import gr, gr_unittest
+
+class test_glfsr_source(gr_unittest.TestCase):
+
+    def setUp (self):
+        self.fg = gr.flow_graph ()
+
+    def tearDown (self):
+        self.fg = None
+
+    def test_000_make_b(self):
+        src = gr.glfsr_source_b(16)
+        self.assertEquals(src.mask(), 0x8016)
+        self.assertEquals(src.period(), 2**16-1)
+
+    def test_001_degree_b(self):
+        self.assertRaises(RuntimeError,
+                          lambda: gr.glfsr_source_b(0))
+        self.assertRaises(RuntimeError,
+                          lambda: gr.glfsr_source_b(33))
+        
+    def test_002_correlation_b(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 test_003_make_f(self):
+        src = gr.glfsr_source_f(16)
+        self.assertEquals(src.mask(), 0x8016)
+        self.assertEquals(src.period(), 2**16-1)
+
+    def test_004_degree_f(self):
+        self.assertRaises(RuntimeError,
+                          lambda: gr.glfsr_source_f(0))
+        self.assertRaises(RuntimeError,
+                          lambda: gr.glfsr_source_f(33))
+        
+    def test_005_correlation_f(self):
+        for degree in range(1,11):                # Higher degrees take too 
long to correlate
+            src = gr.glfsr_source_f(degree, False)
+            dst = gr.vector_sink_f()
+            self.fg.connect(src, 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
+    for lag in range(l):
+        for i in range(l):
+            R[lag] += data[i]*data[i-lag]
+    return R
+
+if __name__ == '__main__':
+    gr_unittest.main ()

Deleted: 
gnuradio/branches/developers/jcorgan/channel/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py





reply via email to

[Prev in Thread] Current Thread [Next in Thread]