summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/general/Makefile.am6
-rw-r--r--gnuradio-core/src/lib/general/general.i4
-rw-r--r--gnuradio-core/src/lib/general/gr_glfsr_source_f.cc84
-rw-r--r--gnuradio-core/src/lib/general/gr_glfsr_source_f.h65
-rw-r--r--gnuradio-core/src/lib/general/gr_glfsr_source_f.i37
-rw-r--r--gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc77
-rw-r--r--gnuradio-core/src/lib/general/gr_pn_correlator_cc.h60
-rw-r--r--gnuradio-core/src/lib/general/gr_pn_correlator_cc.i32
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/Makefile.am2
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py (renamed from gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py)32
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py50
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_rx.py53
-rw-r--r--gnuradio-examples/python/hier/sounder/sounder_tx.py46
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_rx.py108
-rwxr-xr-xgnuradio-examples/python/hier/sounder/usrp_sounder_tx.py66
-rw-r--r--gnuradio-examples/python/hier/sounder/usrp_source.py4
16 files changed, 607 insertions, 119 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am
index 3856a319af..d72a5a10d7 100644
--- a/gnuradio-core/src/lib/general/Makefile.am
+++ b/gnuradio-core/src/lib/general/Makefile.am
@@ -77,6 +77,7 @@ libgeneral_la_SOURCES = \
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 \
@@ -99,6 +100,7 @@ libgeneral_la_SOURCES = \
gr_pll_carriertracking_cc.cc \
gr_pll_freqdet_cf.cc \
gr_pll_refout_cc.cc \
+ gr_pn_correlator_cc.cc \
gr_prefix.cc \
gr_prefs.cc \
gr_probe_avg_mag_sqrd_c.cc \
@@ -200,6 +202,7 @@ grinclude_HEADERS = \
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 \
@@ -224,6 +227,7 @@ grinclude_HEADERS = \
gr_pll_carriertracking_cc.h \
gr_pll_freqdet_cf.h \
gr_pll_refout_cc.h \
+ gr_pn_correlator_cc.h \
gr_prefix.h \
gr_prefs.h \
gr_probe_avg_mag_sqrd_c.h \
@@ -330,6 +334,7 @@ swiginclude_HEADERS = \
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 \
@@ -350,6 +355,7 @@ swiginclude_HEADERS = \
gr_pll_carriertracking_cc.i \
gr_pll_freqdet_cf.i \
gr_pll_refout_cc.i \
+ gr_pn_correlator_cc.i \
gr_prefix.i \
gr_prefs.i \
gr_probe_avg_mag_sqrd_c.i \
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index 87368f81e3..2c915b602d 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -85,6 +85,7 @@
#include <gr_pll_freqdet_cf.h>
#include <gr_pll_refout_cc.h>
#include <gr_pll_carriertracking_cc.h>
+#include <gr_pn_correlator_cc.h>
#include <gr_probe_avg_mag_sqrd_c.h>
#include <gr_probe_avg_mag_sqrd_f.h>
#include <gr_probe_signal_f.h>
@@ -111,6 +112,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"
@@ -176,6 +178,7 @@
%include "gr_pll_freqdet_cf.i"
%include "gr_pll_refout_cc.i"
%include "gr_pll_carriertracking_cc.i"
+%include "gr_pn_correlator_cc.i"
%include "gr_probe_avg_mag_sqrd_c.i"
%include "gr_probe_avg_mag_sqrd_f.i"
%include "gr_probe_signal_f.i"
@@ -202,3 +205,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"
diff --git a/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc b/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
new file mode 100644
index 0000000000..242734f3df
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_glfsr_source_f.cc
@@ -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();
+}
diff --git a/gnuradio-core/src/lib/general/gr_glfsr_source_f.h b/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
new file mode 100644
index 0000000000..e3bf57c25e
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_glfsr_source_f.h
@@ -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 */
diff --git a/gnuradio-core/src/lib/general/gr_glfsr_source_f.i b/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
new file mode 100644
index 0000000000..7299f4141c
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_glfsr_source_f.i
@@ -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;
+};
diff --git a/gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc
new file mode 100644
index 0000000000..115b1a981a
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc
@@ -0,0 +1,77 @@
+/* -*- 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_pn_correlator_cc.h>
+#include <gr_io_signature.h>
+
+gr_pn_correlator_cc_sptr
+gr_make_pn_correlator_cc(int degree, int mask, int seed)
+{
+ return gr_pn_correlator_cc_sptr (new gr_pn_correlator_cc(degree, mask, seed));
+}
+
+gr_pn_correlator_cc::gr_pn_correlator_cc(int degree, int mask, int seed)
+ : gr_sync_decimator ("pn_correlator_cc",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)),
+ (unsigned int)((1ULL << degree)-1)) // PN code length
+{
+ d_len = (unsigned int)((1ULL << degree)-1);
+ if (mask == 0)
+ mask = gri_glfsr::glfsr_mask(degree);
+ d_reference = new gri_glfsr(mask, seed);
+ for (int i = 0; i < d_len; i++) // initialize to last value in sequence
+ d_pn = 2.0*d_reference->next_bit()-1.0;
+}
+
+gr_pn_correlator_cc::~gr_pn_correlator_cc()
+{
+ delete d_reference;
+}
+
+int
+gr_pn_correlator_cc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const gr_complex *in = (const gr_complex *) input_items[0];
+ gr_complex *out = (gr_complex *) output_items[0];
+ gr_complex sum;
+
+ for (int i = 0; i < noutput_items; i++) {
+ sum = 0.0;
+
+ for (int j = 0; j < d_len; j++) {
+ if (j != 0) // retard PN generator one sample per period
+ d_pn = 2.0*d_reference->next_bit()-1.0; // no conditionals
+ sum += *in++ * d_pn;
+ }
+
+ *out++ = sum*gr_complex(1.0/d_len, 0.0);
+ }
+
+ return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_pn_correlator_cc.h b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.h
new file mode 100644
index 0000000000..de6704ad2b
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.h
@@ -0,0 +1,60 @@
+/* -*- 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_PN_CORRELATOR_CC_H
+#define INCLUDED_GR_PN_CORRELATOR_CC_H
+
+#include <gr_sync_decimator.h>
+#include <gri_glfsr.h>
+
+class gr_pn_correlator_cc;
+typedef boost::shared_ptr<gr_pn_correlator_cc> gr_pn_correlator_cc_sptr;
+
+gr_pn_correlator_cc_sptr
+gr_make_pn_correlator_cc(int degree, int mask=0, int seed=1);
+/*!
+ * \brief PN code sequential search correlator
+ *
+ * Receives complex baseband signal, outputs complex correlation against
+ * reference PN code, one sample per PN code period
+ */
+
+class gr_pn_correlator_cc : public gr_sync_decimator
+{
+ friend gr_pn_correlator_cc_sptr gr_make_pn_correlator_cc(int degree, int mask, int seed);
+
+ int d_len;
+ float d_pn;
+ gri_glfsr *d_reference;
+
+ protected:
+ gr_pn_correlator_cc(int degree, int mask, int seed);
+
+ public:
+ virtual int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ ~gr_pn_correlator_cc();
+};
+
+#endif /* INCLUDED_GR_PN_CORRELATOR_CC_H */
diff --git a/gnuradio-core/src/lib/general/gr_pn_correlator_cc.i b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.i
new file mode 100644
index 0000000000..a91ac2fe18
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_pn_correlator_cc.i
@@ -0,0 +1,32 @@
+/* -*- 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,pn_correlator_cc)
+
+gr_pn_correlator_cc_sptr
+gr_make_pn_correlator_cc(int degree, int mask=0, int seed=1);
+
+class gr_pn_correlator_cc : public gr_sync_decimator
+{
+ protected:
+ gr_pn_correlator_cc();
+};
diff --git a/gnuradio-core/src/python/gnuradio/gr/Makefile.am b/gnuradio-core/src/python/gnuradio/gr/Makefile.am
index 3969a28fd1..175b36b605 100644
--- a/gnuradio-core/src/python/gnuradio/gr/Makefile.am
+++ b/gnuradio-core/src/python/gnuradio/gr/Makefile.am
@@ -63,6 +63,7 @@ noinst_PYTHON = \
qa_fractional_interpolator.py \
qa_frequency_modulator.py \
qa_fsk_stuff.py \
+ qa_glfsr_source.py \
qa_goertzel.py \
qa_head.py \
qa_hier_block2.py \
@@ -81,6 +82,7 @@ noinst_PYTHON = \
qa_pll_carriertracking.py \
qa_pll_freqdet.py \
qa_pll_refout.py \
+ qa_pn_correlator_cc.py \
qa_rational_resampler.py \
qa_sig_source.py \
qa_single_pole_iir.py \
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py b/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
index ceda6c8321..e0243d24c2 100755
--- a/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source_b.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py
@@ -22,7 +22,7 @@
from gnuradio import gr, gr_unittest
-class test_glfsr_source_b(gr_unittest.TestCase):
+class test_glfsr_source(gr_unittest.TestCase):
def setUp (self):
self.fg = gr.flow_graph ()
@@ -30,18 +30,18 @@ class test_glfsr_source_b(gr_unittest.TestCase):
def tearDown (self):
self.fg = None
- def test_000_make(self):
+ 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(self):
+ 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(self):
+ 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)
@@ -55,6 +55,30 @@ class test_glfsr_source_b(gr_unittest.TestCase):
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
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py b/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py
new file mode 100755
index 0000000000..bc03d714a7
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py
@@ -0,0 +1,50 @@
+#!/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_pn_correlator_cc(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.fg = gr.flow_graph ()
+
+ def tearDown(self):
+ self.fg = None
+
+ def test_000_make(self):
+ c = gr.pn_correlator_cc(10)
+
+ def test_001_correlate(self):
+ degree = 10
+ length = 2**degree-1
+ src = gr.glfsr_source_f(degree)
+ head = gr.head(gr.sizeof_float, length*length)
+ f2c = gr.float_to_complex()
+ corr = gr.pn_correlator_cc(degree)
+ dst = gr.vector_sink_c()
+ self.fg.connect(src, head, f2c, corr, dst)
+ self.fg.run()
+ data = dst.data()
+ self.assertEqual(data[-1], (1.0+0j))
+
+if __name__ == '__main__':
+ gr_unittest.main ()
diff --git a/gnuradio-examples/python/hier/sounder/sounder_rx.py b/gnuradio-examples/python/hier/sounder/sounder_rx.py
index 6c8154baf4..336e604a3d 100644
--- a/gnuradio-examples/python/hier/sounder/sounder_rx.py
+++ b/gnuradio-examples/python/hier/sounder/sounder_rx.py
@@ -28,51 +28,28 @@ n2s = eng_notation.num_to_str
class sounder_rx(gr.hier_block2):
"""
- Creates a top-level channel sounder block with the given parameters.
+ Creates a channel sounder receiver block with the given parameters.
"""
- def __init__(self, subdev_spec, freq, cal, verbose, max_delay, chip_rate, gain):
+ def __init__(self, chip_rate, degree, verbose):
# Call hierarchical block constructor
# Top-level blocks have no inputs or outputs
gr.hier_block2.__init__(self,
- "sounder_rx", # Block typename
- gr.io_signature(0,0,0), # Input signature
- gr.io_signature(0,0,0)) # Output signature
- self._freq = freq
- self._cal = cal
- self._verbose = verbose
- self._max_delay = max_delay
-
- self._u = usrp_source_c(0, subdev_spec, gain, chip_rate, self._freq, self._cal, verbose)
- self.define_component("usrp", self._u)
-
- self._chip_rate = self._u._if_rate
- self._resolution = 1.0/self._chip_rate
+ "sounder_rx", # Block typename
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
- min_chips = int(math.ceil(2.0*self._max_delay * self._chip_rate))
- degree = int(math.ceil(math.log(min_chips)/math.log(2)))
- self._length = 2**degree-1
- self._seq_per_sec = self._chip_rate/self._length
- self._tap = 0.0001
+ self._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
+ self._length = 2**self._degree-1
+ self._rep_rate = self._chip_rate/float(self._length)
if self._verbose:
- print "Actual chip rate is", n2s(self._chip_rate), "chips/sec"
- print "Resolution is", n2s(self._resolution), "sec"
- print "Using specified maximum delay spread of", self._max_delay, "sec"
- print "Mininum sequence length needed is", n2s(min_chips), "chips"
- print "Using PN sequence of degree", degree, "length", self._length
- print "Sequences per second is", self._seq_per_sec
- print "IIR tap is", self._tap
+ print "Using PN sequence of degree", self._degree, "length", self._length
+ print "Sequence repetition rate is", n2s(self._rep_rate), "per sec"
- self.define_component("s2v", gr.stream_to_vector(gr.sizeof_gr_complex, self._length))
- self.define_component("fft", gr.fft_vcc(self._length, True, ())) # No window needed
- self.define_component("avg", gr.single_pole_iir_filter_cc(self._tap, self._length))
- self.define_component("keep", gr.keep_one_in_n(gr.sizeof_gr_complex*self._length, int(self._seq_per_sec)))
- self.define_component("sink", gr.file_sink(gr.sizeof_gr_complex*self._length, "FFT.dat"))
-
- self.connect("usrp", 0, "s2v", 0)
- self.connect("s2v", 0, "fft", 0)
- self.connect("fft", 0, "avg", 0)
- self.connect("avg", 0, "keep", 0)
- self.connect("keep", 0, "sink", 0)
+ self.define_component("corr", gr.pn_correlator_cc(self._degree))
+ self.connect("self", 0, "corr", 0)
+ self.connect("corr", 0, "self", 0)
diff --git a/gnuradio-examples/python/hier/sounder/sounder_tx.py b/gnuradio-examples/python/hier/sounder/sounder_tx.py
index e6a3e84f85..7d91f36e16 100644
--- a/gnuradio-examples/python/hier/sounder/sounder_tx.py
+++ b/gnuradio-examples/python/hier/sounder/sounder_tx.py
@@ -21,50 +21,26 @@
#
from gnuradio import gr, usrp, eng_notation
-from usrp_sink import usrp_sink_c
import math
n2s = eng_notation.num_to_str
class sounder_tx(gr.hier_block2):
"""
- Creates a top-level channel sounder block with the given parameters.
+ Creates a channel sounder generator with the given parameters.
"""
- def __init__(self, subdev_spec, freq, cal, verbose, max_delay, chip_rate, amplitude):
-
- # Call hierarchical block constructor
- # Top-level blocks have no inputs or outputs
+ def __init__(self, degree, chip_rate, verbose):
gr.hier_block2.__init__(self,
- "sounder_tx", # Block typename
- gr.io_signature(0,0,0), # Input signature
- gr.io_signature(0,0,0)) # Output signature
- self._freq = freq
- self._cal = cal
- self._verbose = verbose
- self._max_delay = max_delay
-
- self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, verbose)
- self._chip_rate = self._u._if_rate
- self._resolution = 1.0/self._chip_rate
+ "sounder_tx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
- min_chips = int(math.ceil(2.0*self._max_delay * self._chip_rate))
- degree = int(math.ceil(math.log(min_chips)/math.log(2)))
+ self._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
self._length = 2**degree-1
-
- self._glfsr = gr.glfsr_source_b(degree)
- self._mapper = gr.chunks_to_symbols_bc((-amplitude+0j, amplitude+0j), 1)
- if self._verbose:
- print "Actual chip rate is", n2s(self._chip_rate), "chips/sec"
- print "Resolution is", n2s(self._resolution), "sec"
- print "Using specified maximum delay spread of", self._max_delay, "sec"
- print "Mininum sequence length needed is", n2s(min_chips), "chips"
- print "Using PN sequence of degree", degree, "length", self._length
- print "Output amplitude is", amplitude
-
- self.define_component("glfsr", self._glfsr)
- self.define_component("mapper", self._mapper)
- self.define_component("usrp", self._u)
- self.connect("glfsr", 0, "mapper", 0)
- self.connect("mapper", 0, "usrp", 0)
+ # Connect PN source to block output
+ self.define_component("glfsr", gr.glfsr_source_f(degree))
+ self.connect("glfsr", 0, "self", 0)
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
index dd8007cbbe..72ebeccfa6 100755
--- a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py
@@ -23,47 +23,85 @@
from gnuradio import gr, eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
+from usrp_source import usrp_source_c
from sounder_rx import sounder_rx
-def main():
- parser = OptionParser(option_class=eng_option)
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_rx(gr.hier_block2):
+ def __init__(self, options):
+ gr.hier_block2.__init__(self, "usrp_sounder_rx",
+ gr.io_signature(0,0,0),
+ gr.io_signature(0,0,0))
+
+ self._options = options
+ self._u = usrp_source_c(0,
+ self._options.rx_subdev_spec,
+ self._options.gain,
+ self._options.chip_rate,
+ self._options.freq,
+ self._options.cal,
+ self._options.verbose)
+ self._options.chip_rate = self._u._if_rate
+ self._length = 2**self._options.degree-1
+ self._receiver = sounder_rx(self._options.chip_rate,
+ self._options.degree,
+ self._options.verbose)
+
+ samples = 100 * self._length**2
- # Receive path options
- parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
- help="select USRP Rx side A or B (default=first found)")
- parser.add_option("-f", "--freq", type="eng_float", default=0.0,
- help="set center frequency (default=%default)")
- parser.add_option("-c", "--cal", type="eng_float", default=0.0,
- help="set frequency calibration offset (default=%default)")
- parser.add_option("-v", "--verbose", action="store_true", default=False,
- help="print extra debugging info")
- parser.add_option("-d", "--max-delay", type="eng_float", default=10e-6,
- help="set maximum delay spread (default=%default)")
- parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
- help="set sounder chip rate (default=%default)")
- parser.add_option("-g", "--gain", type="eng_float", default=None,
- help="set output amplitude (default=%default)")
- (options, args) = parser.parse_args()
+ self.define_component("usrp", self._u)
+ self.define_component("head", gr.head(gr.sizeof_gr_complex, samples))
+ self.define_component("rx", self._receiver)
+ self.define_component("c2m", gr.complex_to_mag())
+ self.define_component("s2v", gr.stream_to_vector(gr.sizeof_float, self._length))
+ self.define_component("lpf", gr.single_pole_iir_filter_ff(self._options.alpha, self._length))
+ self.define_component("v2s", gr.vector_to_stream(gr.sizeof_float, self._length))
+ self.define_component("sink", gr.file_sink(gr.sizeof_float, "impulse.dat"))
- if len(args) != 0:
- parser.print_help()
- sys.exit(1)
+ self.connect("usrp", 0, "head", 0)
+ self.connect("head", 0, "rx", 0)
+ self.connect("rx", 0, "c2m", 0)
+ self.connect("c2m", 0, "s2v", 0)
+ self.connect("s2v", 0, "lpf", 0)
+ self.connect("lpf", 0, "v2s", 0)
+ self.connect("v2s", 0, "sink", 0)
+
+ if self._options.verbose:
+ print "Chip rate is", n2s(self._options.chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._options.chip_rate), "sec"
+ print "Using PN code of degree", self._options.degree
+
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B (default=first found)")
+ parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+ help="set center frequency (default=%default)")
+ parser.add_option("-c", "--cal", type="eng_float", default=0.0,
+ help="set frequency calibration offset (default=%default)")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="print extra debugging info")
+ parser.add_option("-d", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, default=%default)")
+ parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
+ help="set sounder chip rate (default=%default)")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set receiver gain (default=%default)")
+ parser.add_option("", "--alpha", type="eng_float", default=1.0,
+ help="set smoothing constant (default=%default)")
+ (options, args) = parser.parse_args()
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
- # Create an instance of a hierarchical block
- top_block = sounder_rx(options.rx_subdev_spec, options.freq, options.cal,
- options.verbose, options.max_delay, options.chip_rate,
- options.gain)
-
- # Create an instance of a runtime, passing it the top block
- # to process
- runtime = gr.runtime(top_block)
+ top_block = usrp_sounder_rx(options)
+ runtime = gr.runtime(top_block)
- try:
- # Run forever
- runtime.run()
- except KeyboardInterrupt:
- # Ctrl-C exits
- pass
+ try:
+ runtime.run()
+ except KeyboardInterrupt:
+ pass
if __name__ == '__main__':
main ()
diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
index c96313c67a..00146146ce 100755
--- a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py
@@ -23,8 +23,49 @@
from gnuradio import gr, eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
+from usrp_sink import usrp_sink_c
from sounder_tx import sounder_tx
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_tx(gr.hier_block2):
+ def __init__(self, subdev_spec, freq, cal, verbose, degree, chip_rate, amplitude):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.hier_block2.__init__(self,
+ "usrp_sounder_tx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(0,0,0)) # Output signature
+
+ self._freq = freq
+ self._cal = cal
+ self._verbose = verbose
+ self._degree = degree
+ self._length = 2**degree-1
+ self._amplitude = amplitude
+
+ self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, self._verbose)
+ self.define_component("usrp", self._u)
+ self._chip_rate = self._u._if_rate
+ self._max_time = float(self._length)/self._chip_rate
+ self.define_component("pn", sounder_tx(self._degree, self._chip_rate, self._verbose))
+ self.define_component("gain", gr.multiply_const_ff(amplitude));
+ self.define_component("f2c", gr.float_to_complex())
+
+ if self._verbose:
+ print "Chip rate is", n2s(self._chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._chip_rate), "sec"
+ print "Using PN code of degree", self._degree, "length", 2**self._degree-1
+ print "Maximum measurable impulse response is", n2s(self._max_time), "sec"
+ print "Output amplitude is", amplitude
+
+ # Ultimately this will be
+ # self.connect("pn gain f2c usrp")
+ self.connect("pn", 0, "gain", 0)
+ self.connect("gain", 0, "f2c", 0)
+ self.connect("f2c", 0, "usrp", 0)
+
def main():
parser = OptionParser(option_class=eng_option)
@@ -37,22 +78,35 @@ def main():
help="set frequency calibration offset (default=%default)")
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="print extra debugging info")
- parser.add_option("-d", "--max-delay", type="eng_float", default=10e-6,
- help="set maximum delay spread (default=%default)")
+ parser.add_option("-d", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, default=%default)")
parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
help="set sounder chip rate (default=%default)")
- parser.add_option("-g", "--amplitude", type="eng_float", default=32000.0,
+ parser.add_option("-g", "--amplitude", type="eng_float", default=8000.0,
help="set output amplitude (default=%default)")
+ parser.add_option("", "--real-time", action="store_true", default=False,
+ help="Attempt to enable real-time scheduling")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
sys.exit(1)
+ if not options.real_time:
+ realtime = False
+ else:
+ # Attempt to enable realtime scheduling
+ r = gr.enable_realtime_scheduling()
+ if r == gr.RT_OK:
+ realtime = True
+ else:
+ realtime = False
+ print "Note: failed to enable realtime scheduling"
+
# Create an instance of a hierarchical block
- top_block = sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
- options.verbose, options.max_delay, options.chip_rate,
- options.amplitude)
+ top_block = usrp_sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
+ options.verbose, options.degree, options.chip_rate,
+ options.amplitude)
# Create an instance of a runtime, passing it the top block
# to process
diff --git a/gnuradio-examples/python/hier/sounder/usrp_source.py b/gnuradio-examples/python/hier/sounder/usrp_source.py
index 16949998b8..0ba9e61611 100644
--- a/gnuradio-examples/python/hier/sounder/usrp_source.py
+++ b/gnuradio-examples/python/hier/sounder/usrp_source.py
@@ -93,7 +93,9 @@ class usrp_source_c(gr.hier_block2):
gain = (g[0]+g[1])/2.0
self._gain = gain
self._subdev.set_gain(self._gain)
-
+ if self._verbose:
+ print "USRP gain set to", self._gain
+
def set_calibration(self, calibration):
self._cal = calibration
if self._verbose: