From bae47cc41eda30e96de5e6d640f467760ae05c23 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 3 Apr 2007 20:11:05 +0000 Subject: Merged r4767:4859 from developer branch jcorgan/channel, passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4860 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/general/Makefile.am | 6 ++ gnuradio-core/src/lib/general/general.i | 4 ++ gnuradio-core/src/lib/general/gr_glfsr_source_f.cc | 84 ++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_glfsr_source_f.h | 65 +++++++++++++++++ gnuradio-core/src/lib/general/gr_glfsr_source_f.i | 37 ++++++++++ .../src/lib/general/gr_pn_correlator_cc.cc | 77 ++++++++++++++++++++ .../src/lib/general/gr_pn_correlator_cc.h | 60 ++++++++++++++++ .../src/lib/general/gr_pn_correlator_cc.i | 32 +++++++++ 8 files changed, 365 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_glfsr_source_f.cc create mode 100644 gnuradio-core/src/lib/general/gr_glfsr_source_f.h create mode 100644 gnuradio-core/src/lib/general/gr_glfsr_source_f.i create mode 100644 gnuradio-core/src/lib/general/gr_pn_correlator_cc.cc create mode 100644 gnuradio-core/src/lib/general/gr_pn_correlator_cc.h create mode 100644 gnuradio-core/src/lib/general/gr_pn_correlator_cc.i (limited to 'gnuradio-core/src/lib') 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 #include #include +#include #include #include #include @@ -111,6 +112,7 @@ #include #include #include +#include %} %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 +#endif + +#include +#include +#include +#include + +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 + +class gri_glfsr; + +class gr_glfsr_source_f; +typedef boost::shared_ptr 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 +#include + +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 +#include + +class gr_pn_correlator_cc; +typedef boost::shared_ptr 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(); +}; -- cgit