diff options
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/general/Makefile.am | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_f.cc | 84 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_f.h | 65 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_f.i | 37 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc | 77 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_pn_correlator_cc.h | 60 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_pn_correlator_cc.i | 32 | ||||
-rw-r--r-- | gnuradio-core/src/python/gnuradio/gr/Makefile.am | 2 | ||||
-rwxr-xr-x | gnuradio-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-x | gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py | 50 |
11 files changed, 445 insertions, 4 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 3856a319a..d72a5a10d 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 87368f81e..2c915b602 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 000000000..242734f3d --- /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 000000000..e3bf57c25 --- /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 000000000..7299f4141 --- /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 000000000..115b1a981 --- /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 000000000..de6704ad2 --- /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 000000000..a91ac2fe1 --- /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 3969a28fd..175b36b60 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 ceda6c832..e0243d24c 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 000000000..bc03d714a --- /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 () |