diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-08-12 22:36:39 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-08-12 22:36:39 -0400 |
commit | 719ebae8fb75635f1291e21b74af69cbdefe4837 (patch) | |
tree | e166f92baf4a1ff8940cadfea24e035aac41bd16 | |
parent | 78d149cd3d230ca9310401496e5770401aeb478c (diff) |
digital: converted correlator blocks to 3.7; everything to make qa_correlate_access_code work.
40 files changed, 1591 insertions, 1427 deletions
diff --git a/gr-digital/include/digital/CMakeLists.txt b/gr-digital/include/digital/CMakeLists.txt index b3c5efb28a..231c130034 100644 --- a/gr-digital/include/digital/CMakeLists.txt +++ b/gr-digital/include/digital/CMakeLists.txt @@ -76,7 +76,7 @@ add_custom_target(digital_generated_includes DEPENDS install(FILES ${digital_generated_includes} api.h -# impl_glfsr.h + glfsr.h # impl_mpsk_snr_est.h additive_scrambler_bb.h binary_slicer_fb.h @@ -87,9 +87,9 @@ install(FILES constellation.h constellation_receiver_cb.h constellation_decoder_cb.h -# correlate_access_code_bb.h -# correlate_access_code_tag_bb.h -# costas_loop_cc.h + correlate_access_code_bb.h + correlate_access_code_tag_bb.h + costas_loop_cc.h # crc32.h # descrambler_bb.h diff_decoder_bb.h @@ -97,8 +97,8 @@ install(FILES diff_phasor_cc.h # framer_sink_1.h fll_band_edge_cc.h -# glfsr_source_b.h -# glfsr_source_f.h + glfsr_source_b.h + glfsr_source_f.h # gmskmod_bc.h # lms_dd_equalizer_cc.h # kurtotic_equalizer_cc.h @@ -115,7 +115,7 @@ install(FILES # packet_sink.h pfb_clock_sync_ccf.h pfb_clock_sync_fff.h -# pn_correlator_cc.h + pn_correlator_cc.h # probe_density_b.h # probe_mpsk_snr_est_c.h # scrambler_bb.h diff --git a/gr-digital/include/digital/correlate_access_code_bb.h b/gr-digital/include/digital/correlate_access_code_bb.h new file mode 100644 index 0000000000..c2ef788a37 --- /dev/null +++ b/gr-digital/include/digital/correlate_access_code_bb.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,2011,2012 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 3, 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_DIGITAL_CORRELATE_ACCESS_CODE_BB_H +#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_H + +#include <digital/api.h> +#include <gr_sync_block.h> +#include <string> + +namespace gr { + namespace digital { + + /*! + * \brief Examine input for specified access code, one bit at a time. + * \ingroup sync_blk + * \ingroup digital + * + * input: stream of bits, 1 bit per input byte (data in LSB) + * output: stream of bits, 2 bits per output byte (data in LSB, flag in next higher bit) + * + * Each output byte contains two valid bits, the data bit, and the + * flag bit. The LSB (bit 0) is the data bit, and is the original + * input data, delayed 64 bits. Bit 1 is the flag bit and is 1 if + * the corresponding data bit is the first data bit following the + * access code. Otherwise the flag bit is 0. + */ + class DIGITAL_API correlate_access_code_bb : virtual public gr_sync_block + { + public: + // gr::digital::correlate_access_code_bb::sptr + typedef boost::shared_ptr<correlate_access_code_bb> sptr; + + /*! + * Make a correlate_access_code block. + * + * \param access_code is represented with 1 byte per bit, + * e.g., "010101010111000100" + * \param threshold maximum number of bits that may be wrong + */ + static sptr make(const std::string &access_code, int threshold); + + /*! + * Set a new access code. + * + * \param access_code is represented with 1 byte per bit, + * e.g., "010101010111000100" + */ + virtual bool set_access_code(const std::string &access_code) = 0; + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_H */ diff --git a/gr-digital/include/digital/correlate_access_code_tag_bb.h b/gr-digital/include/digital/correlate_access_code_tag_bb.h new file mode 100644 index 0000000000..0c51f3aead --- /dev/null +++ b/gr-digital/include/digital/correlate_access_code_tag_bb.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,2011,2012 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 3, 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_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_H +#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_H + +#include <digital/api.h> +#include <gr_sync_block.h> +#include <string> + +namespace gr { + namespace digital { + + /*! + * \brief Examine input for specified access code, one bit at a time. + * \ingroup sync_blk + * + * input: stream of bits, 1 bit per input byte (data in LSB) + * output: unaltered stream of bits (plus tags) + * + * This block annotates the input stream with tags. The tags have + * key name [tag_name], specified in the constructor. Used for + * searching an input data stream for preambles, etc. + */ + class DIGITAL_API correlate_access_code_tag_bb : virtual public gr_sync_block + { + public: + // gr::digital::correlate_access_code_tag_bb::sptr + typedef boost::shared_ptr<correlate_access_code_tag_bb> sptr; + + /*! + * \param access_code is represented with 1 byte per bit, + * e.g., "010101010111000100" + * \param threshold maximum number of bits that may be wrong + * \param tag_name key of the tag inserted into the tag stream + */ + static sptr make(const std::string &access_code, + int threshold, + const std::string &tag_name); + + /*! + * \param access_code is represented with 1 byte per bit, + * e.g., "010101010111000100" + */ + virtual bool set_access_code(const std::string &access_code) = 0; + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_H */ diff --git a/gr-digital/include/digital/costas_loop_cc.h b/gr-digital/include/digital/costas_loop_cc.h new file mode 100644 index 0000000000..bad6de9363 --- /dev/null +++ b/gr-digital/include/digital/costas_loop_cc.h @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2011,2012 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 3, 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_DIGITAL_COSTAS_LOOP_CC_H +#define INCLUDED_DIGITAL_COSTAS_LOOP_CC_H + +#include <digital/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace digital { + + /*! + * \brief A Costas loop carrier recovery module. + * \ingroup sync_blk + * \ingroup digital + * + * The Costas loop locks to the center frequency of a signal and + * downconverts it to baseband. The second (order=2) order loop + * is used for BPSK where the real part of the output signal is + * the baseband BPSK signal and the imaginary part is the error + * signal. When order=4, it can be used for quadrature + * modulations where both I and Q (real and imaginary) are + * outputted. + * + * More details can be found online: + * + * J. Feigin, "Practical Costas loop design: Designing a simple + * and inexpensive BPSK Costas loop carrier recovery circuit," RF + * signal processing, pp. 20-36, 2002. + * + * http://rfdesign.com/images/archive/0102Feigin20.pdf + * + * The Costas loop can have two output streams: + * stream 1 is the baseband I and Q; + * stream 2 is the normalized frequency of the loop + */ + class DIGITAL_API costas_loop_cc : virtual public gr_sync_block + { + public: + // gr::digital::costas_loop_cc::sptr + typedef boost::shared_ptr<costas_loop_cc> sptr; + + /*! + * Make a Costas loop carrier recovery block. + * + * \param loop_bw internal 2nd order loop bandwidth (~ 2pi/100) + * \param order the loop order, either 2, 4, or 8 + */ + static sptr make(float loop_bw, int order); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_COSTAS_LOOP_CC_H */ diff --git a/gr-digital/include/digital/glfsr.h b/gr-digital/include/digital/glfsr.h new file mode 100644 index 0000000000..211956e842 --- /dev/null +++ b/gr-digital/include/digital/glfsr.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012 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 3, 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_DIGITAL_GLFSR_H +#define INCLUDED_DIGITAL_GLFSR_H + +#include <digital/api.h> + +namespace gr { + namespace digital { + + /*! + * \brief Galois Linear Feedback Shift Register using specified polynomial mask + * \ingroup misc + * + * Generates a maximal length pseudo-random sequence of length 2^degree-1 + */ + + class DIGITAL_API glfsr + { + private: + int d_shift_register; + int d_mask; + + public: + glfsr(int mask, int seed) { d_shift_register = seed; d_mask = mask; } + ~glfsr(); + + static int glfsr_mask(int degree); + + unsigned char next_bit() + { + unsigned char bit = d_shift_register & 1; + d_shift_register >>= 1; + if(bit) + d_shift_register ^= d_mask; + return bit; + } + + int mask() const { return d_mask; } + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_GLFSR_H */ diff --git a/gr-digital/include/digital/glfsr_source_b.h b/gr-digital/include/digital/glfsr_source_b.h new file mode 100644 index 0000000000..8edabc836f --- /dev/null +++ b/gr-digital/include/digital/glfsr_source_b.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012 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 3, 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_B_H +#define INCLUDED_GR_GLFSR_SOURCE_B_H + +#include <digital/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace digital { + + /*! + * \brief Galois LFSR pseudo-random source + * \ingroup source_blk + * + * \param degree Degree of shift register must be in [1, 32]. If mask + * is 0, the degree determines a default mask (see + * digital_impl_glfsr.cc for the mapping). + * \param repeat Set to repeat sequence. + * \param mask Allows a user-defined bit mask for indexes of the shift + * register to feed back. + * \param seed Initial setting for values in shift register. + */ + class DIGITAL_API glfsr_source_b : virtual public gr_sync_block + { + public: + // gr::digital::glfsr_source_b::sptr + typedef boost::shared_ptr<glfsr_source_b> sptr; + + static sptr make(int degree, bool repeat=true, + int mask=0, int seed=1); + + virtual unsigned int period() const = 0; + virtual int mask() const = 0; + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_GLFSR_SOURCE_B_H */ diff --git a/gr-digital/include/digital/glfsr_source_f.h b/gr-digital/include/digital/glfsr_source_f.h new file mode 100644 index 0000000000..6209805e69 --- /dev/null +++ b/gr-digital/include/digital/glfsr_source_f.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012 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 3, 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 <digital/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace digital { + + /*! + * \brief Galois LFSR pseudo-random source generating float outputs -1.0 - 1.0. + * \ingroup source_blk + * + * \param degree Degree of shift register must be in [1, 32]. If mask + * is 0, the degree determines a default mask (see + * digital_impl_glfsr.cc for the mapping). + * \param repeat Set to repeat sequence. + * \param mask Allows a user-defined bit mask for indexes of the shift + * register to feed back. + * \param seed Initial setting for values in shift register. + */ + class DIGITAL_API glfsr_source_f : virtual public gr_sync_block + { + public: + // gr::digital::glfsr_source_f::sptr + typedef boost::shared_ptr<glfsr_source_f> sptr; + + static sptr make(int degree, bool repeat=true, + int mask=0, int seed=1); + + virtual unsigned int period() const = 0; + virtual int mask() const = 0; + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_GLFSR_SOURCE_F_H */ diff --git a/gr-digital/include/digital/pn_correlator_cc.h b/gr-digital/include/digital/pn_correlator_cc.h new file mode 100644 index 0000000000..bb881fe5b7 --- /dev/null +++ b/gr-digital/include/digital/pn_correlator_cc.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012 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 3, 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 <digital/api.h> +#include <gr_sync_decimator.h> + +namespace gr { + namespace digital { + + /*! + * \brief PN code sequential search correlator + * + * \ingroup sync_blk + * + * Receives complex baseband signal, outputs complex correlation + * against reference PN code, one sample per PN code period. The + * PN sequence is generated using a GLFSR. + */ + class DIGITAL_API pn_correlator_cc : virtual public gr_sync_decimator + { + public: + // gr::digital::pn_correlator_cc::sptr + typedef boost::shared_ptr<pn_correlator_cc> sptr; + + /*! + * \brief Make PN code sequential search correlator block. + * + * \param degree Degree of shift register must be in [1, 32]. If mask + * is 0, the degree determines a default mask (see + * digital_impl_glfsr.cc for the mapping). + * \param repeat Set to repeat sequence. + * \param mask Allows a user-defined bit mask for indexes of the shift + * register to feed back. + * \param seed Initial setting for values in shift register. + */ + static sptr make(int degree, int mask=0, int seed=1); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PN_CORRELATOR_CC_H */ diff --git a/gr-digital/include/digital_correlate_access_code_bb.h b/gr-digital/include/digital_correlate_access_code_bb.h deleted file mode 100644 index 8095dd4090..0000000000 --- a/gr-digital/include/digital_correlate_access_code_bb.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005,2006,2011 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 3, 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_DIGITAL_CORRELATE_ACCESS_CODE_BB_H -#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_H - -#include <digital_api.h> -#include <gr_sync_block.h> -#include <string> - -class digital_correlate_access_code_bb; -typedef boost::shared_ptr<digital_correlate_access_code_bb> digital_correlate_access_code_bb_sptr; - -/*! - * \param access_code is represented with 1 byte per bit, e.g., "010101010111000100" - * \param threshold maximum number of bits that may be wrong - */ -DIGITAL_API digital_correlate_access_code_bb_sptr -digital_make_correlate_access_code_bb (const std::string &access_code, int threshold); - -/*! - * \brief Examine input for specified access code, one bit at a time. - * \ingroup sync_blk - * \ingroup digital - * - * input: stream of bits, 1 bit per input byte (data in LSB) - * output: stream of bits, 2 bits per output byte (data in LSB, flag in next higher bit) - * - * Each output byte contains two valid bits, the data bit, and the - * flag bit. The LSB (bit 0) is the data bit, and is the original - * input data, delayed 64 bits. Bit 1 is the - * flag bit and is 1 if the corresponding data bit is the first data - * bit following the access code. Otherwise the flag bit is 0. - */ -class DIGITAL_API digital_correlate_access_code_bb : public gr_sync_block -{ - friend DIGITAL_API digital_correlate_access_code_bb_sptr - digital_make_correlate_access_code_bb (const std::string &access_code, int threshold); - private: - unsigned long long d_access_code; // access code to locate start of packet - // access code is left justified in the word - unsigned long long d_data_reg; // used to look for access_code - unsigned long long d_flag_reg; // keep track of decisions - unsigned long long d_flag_bit; // mask containing 1 bit which is location of new flag - unsigned long long d_mask; // masks access_code bits (top N bits are set where - // N is the number of bits in the access code) - unsigned int d_threshold; // how many bits may be wrong in sync vector - - protected: - digital_correlate_access_code_bb(const std::string &access_code, int threshold); - - public: - ~digital_correlate_access_code_bb(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - - /*! - * \param access_code is represented with 1 byte per bit, e.g., "010101010111000100" - */ - bool set_access_code (const std::string &access_code); -}; - -#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_H */ diff --git a/gr-digital/include/digital_correlate_access_code_tag_bb.h b/gr-digital/include/digital_correlate_access_code_tag_bb.h deleted file mode 100644 index b4a12108f4..0000000000 --- a/gr-digital/include/digital_correlate_access_code_tag_bb.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005,2006,2011,2012 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 3, 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_digital_correlate_access_code_tag_bb_H -#define INCLUDED_digital_correlate_access_code_tag_bb_H - -#include <digital_api.h> -#include <gr_sync_block.h> -#include <string> - -class digital_correlate_access_code_tag_bb; -typedef boost::shared_ptr<digital_correlate_access_code_tag_bb> digital_correlate_access_code_tag_bb_sptr; - -/*! - * \param access_code is represented with 1 byte per bit, e.g., "010101010111000100" - * \param threshold maximum number of bits that may be wrong - * \param tag_name key of the tag inserted into the tag stream - */ -DIGITAL_API digital_correlate_access_code_tag_bb_sptr -digital_make_correlate_access_code_tag_bb(const std::string &access_code, - int threshold, - const std::string &tag_name); - -/*! - * \brief Examine input for specified access code, one bit at a time. - * \ingroup sync_blk - * - * input: stream of bits, 1 bit per input byte (data in LSB) - * output: unaltered stream of bits (plus tags) - * - * This block annotates the input stream with tags. The tags have key - * name [tag_name], specified in the constructor. Used for searching - * an input data stream for preambles, etc. - */ -class DIGITAL_API digital_correlate_access_code_tag_bb : public gr_sync_block -{ - friend DIGITAL_API digital_correlate_access_code_tag_bb_sptr - digital_make_correlate_access_code_tag_bb(const std::string &access_code, - int threshold, - const std::string &tag_name); - private: - unsigned long long d_access_code; // access code to locate start of packet - // access code is left justified in the word - unsigned long long d_data_reg; // used to look for access_code - unsigned long long d_mask; // masks access_code bits (top N bits are set where - // N is the number of bits in the access code) - unsigned int d_threshold; // how many bits may be wrong in sync vector - unsigned int d_len; // the length of the access code - - pmt::pmt_t d_key, d_me; //d_key is the tag name, d_me is the block name + unique ID - - protected: - digital_correlate_access_code_tag_bb(const std::string &access_code, - int threshold, - const std::string &tag_name); - - public: - ~digital_correlate_access_code_tag_bb(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - /*! - * \param access_code is represented with 1 byte per bit, e.g., "010101010111000100" - */ - bool set_access_code(const std::string &access_code); -}; - -#endif /* INCLUDED_digital_correlate_access_code_tag_bb_H */ diff --git a/gr-digital/include/digital_costas_loop_cc.h b/gr-digital/include/digital_costas_loop_cc.h deleted file mode 100644 index 4aab22fb45..0000000000 --- a/gr-digital/include/digital_costas_loop_cc.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2011 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 3, 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_DIGITAL_COSTAS_LOOP_CC_H -#define INCLUDED_DIGITAL_COSTAS_LOOP_CC_H - -#include <gr_sync_block.h> -#include <gri_control_loop.h> -#include <stdexcept> -#include <fstream> - - -/*! - * \brief A Costas loop carrier recovery module. - * \ingroup sync_blk - * \ingroup digital - * - * The Costas loop locks to the center frequency of a signal and - * downconverts it to baseband. The second (order=2) order loop is - * used for BPSK where the real part of the output signal is the - * baseband BPSK signal and the imaginary part is the error - * signal. When order=4, it can be used for quadrature modulations - * where both I and Q (real and imaginary) are outputted. - * - * More details can be found online: - * - * J. Feigin, "Practical Costas loop design: Designing a simple and - * inexpensive BPSK Costas loop carrier recovery circuit," RF signal - * processing, pp. 20-36, 2002. - * - * http://rfdesign.com/images/archive/0102Feigin20.pdf - * - * \param loop_bw internal 2nd order loop bandwidth (~ 2pi/100) - * \param order the loop order, either 2, 4, or 8 - */ - -#include <digital_api.h> - -class digital_costas_loop_cc; -typedef boost::shared_ptr<digital_costas_loop_cc> digital_costas_loop_cc_sptr; - - -DIGITAL_API digital_costas_loop_cc_sptr -digital_make_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument); - - -/*! - * \brief Carrier tracking PLL for QPSK - * \ingroup sync_blk - * input: complex; output: complex - * <br>The Costas loop can have two output streams: - * stream 1 is the baseband I and Q; - * stream 2 is the normalized frequency of the loop - * - * \p order must be 2, 4, or 8. - */ -class DIGITAL_API digital_costas_loop_cc : public gr_sync_block, public gri_control_loop -{ - friend DIGITAL_API digital_costas_loop_cc_sptr - digital_make_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument); - - int d_order; - - digital_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument); - - /*! \brief the phase detector circuit for 8th-order PSK loops - * \param sample complex sample - * \return the phase error - */ - float phase_detector_8(gr_complex sample) const; // for 8PSK - - /*! \brief the phase detector circuit for fourth-order loops - * \param sample complex sample - * \return the phase error - */ - float phase_detector_4(gr_complex sample) const; // for QPSK - - /*! \brief the phase detector circuit for second-order loops - * \param sample a complex sample - * \return the phase error - */ - float phase_detector_2(gr_complex sample) const; // for BPSK - - - float (digital_costas_loop_cc::*d_phase_detector)(gr_complex sample) const; - -public: - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif diff --git a/gr-digital/include/digital_glfsr_source_b.h b/gr-digital/include/digital_glfsr_source_b.h deleted file mode 100644 index 151e5a296c..0000000000 --- a/gr-digital/include/digital_glfsr_source_b.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2012 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 3, 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_B_H -#define INCLUDED_GR_GLFSR_SOURCE_B_H - -#include <digital_api.h> -#include <gr_sync_block.h> - -class digital_impl_glfsr; - -class digital_glfsr_source_b; -typedef boost::shared_ptr<digital_glfsr_source_b> digital_glfsr_source_b_sptr; - -DIGITAL_API digital_glfsr_source_b_sptr -digital_make_glfsr_source_b(int degree, bool repeat=true, - int mask=0, int seed=1); - -/*! - * \brief Galois LFSR pseudo-random source - * \ingroup source_blk - * - * \param degree Degree of shift register must be in [1, 32]. If mask - * is 0, the degree determines a default mask (see - * digital_impl_glfsr.cc for the mapping). - * \param repeat Set to repeat sequence. - * \param mask Allows a user-defined bit mask for indexes of the shift - * register to feed back. - * \param seed Initial setting for values in shift register. - */ -class DIGITAL_API digital_glfsr_source_b : public gr_sync_block -{ - private: - friend DIGITAL_API digital_glfsr_source_b_sptr - digital_make_glfsr_source_b(int degree, bool repeat, - int mask, int seed); - - digital_impl_glfsr *d_glfsr; - - bool d_repeat; - unsigned int d_index; - unsigned int d_length; - - digital_glfsr_source_b(int degree, bool repeat, - int mask, int seed); - - public: - - ~digital_glfsr_source_b(); - - 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_B_H */ diff --git a/gr-digital/include/digital_glfsr_source_f.h b/gr-digital/include/digital_glfsr_source_f.h deleted file mode 100644 index fb5b064e4f..0000000000 --- a/gr-digital/include/digital_glfsr_source_f.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2012 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 3, 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 <digital_api.h> -#include <gr_sync_block.h> - -class digital_impl_glfsr; - -class digital_glfsr_source_f; -typedef boost::shared_ptr<digital_glfsr_source_f> digital_glfsr_source_f_sptr; - -DIGITAL_API digital_glfsr_source_f_sptr -digital_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_blk - * - * \param degree Degree of shift register must be in [1, 32]. If mask - * is 0, the degree determines a default mask (see - * digital_impl_glfsr.cc for the mapping). - * \param repeat Set to repeat sequence. - * \param mask Allows a user-defined bit mask for indexes of the shift - * register to feed back. - * \param seed Initial setting for values in shift register. - */ -class DIGITAL_API digital_glfsr_source_f : public gr_sync_block -{ - private: - friend DIGITAL_API digital_glfsr_source_f_sptr - digital_make_glfsr_source_f(int degree, bool repeat, - int mask, int seed); - - digital_impl_glfsr *d_glfsr; - - bool d_repeat; - unsigned int d_index; - unsigned int d_length; - - digital_glfsr_source_f(int degree, bool repeat, - int mask, int seed); - - public: - - ~digital_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/gr-digital/include/digital_pn_correlator_cc.h b/gr-digital/include/digital_pn_correlator_cc.h deleted file mode 100644 index 407cc1e67b..0000000000 --- a/gr-digital/include/digital_pn_correlator_cc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2012 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 3, 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 <digital_api.h> -#include <gr_sync_decimator.h> -#include <digital_impl_glfsr.h> - -class digital_pn_correlator_cc; -typedef boost::shared_ptr<digital_pn_correlator_cc> digital_pn_correlator_cc_sptr; - -DIGITAL_API digital_pn_correlator_cc_sptr -digital_make_pn_correlator_cc(int degree, int mask=0, int seed=1); -/*! - * \brief PN code sequential search correlator - * - * \ingroup sync_blk - * - * Receives complex baseband signal, outputs complex correlation - * against reference PN code, one sample per PN code period. The PN - * sequence is generated using a GLFSR. - * - * \param degree Degree of shift register must be in [1, 32]. If mask - * is 0, the degree determines a default mask (see - * digital_impl_glfsr.cc for the mapping). - * \param repeat Set to repeat sequence. - * \param mask Allows a user-defined bit mask for indexes of the shift - * register to feed back. - * \param seed Initial setting for values in shift register. - */ -class DIGITAL_API digital_pn_correlator_cc : public gr_sync_decimator -{ - friend DIGITAL_API digital_pn_correlator_cc_sptr - digital_make_pn_correlator_cc(int degree, int mask, int seed); - - int d_len; - float d_pn; - digital_impl_glfsr *d_reference; - - protected: - digital_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); - - ~digital_pn_correlator_cc(); -}; - -#endif /* INCLUDED_GR_PN_CORRELATOR_CC_H */ diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt index 936e82842f..441ec50e3f 100644 --- a/gr-digital/lib/CMakeLists.txt +++ b/gr-digital/lib/CMakeLists.txt @@ -104,7 +104,7 @@ expand_cc(chunks_to_symbols_XX_impl bf bc sf sc if ic) list(APPEND digital_sources ${generated_sources} constellation.cc - #impl_glfsr.cc + glfsr.cc #impl_mpsk_snr_est.cc additive_scrambler_bb_impl.cc binary_slicer_fb_impl.cc @@ -113,9 +113,9 @@ list(APPEND digital_sources cma_equalizer_cc_impl.cc constellation_receiver_cb_impl.cc constellation_decoder_cb_impl.cc - #correlate_access_code_bb_impl.cc - #correlate_access_code_tag_bb_impl.cc - #costas_loop_cc_impl.cc + correlate_access_code_bb_impl.cc + correlate_access_code_tag_bb_impl.cc + costas_loop_cc_impl.cc #cpmmod_bc_impl.cc #crc32_impl.cc #descrambler_bb_impl.cc @@ -124,8 +124,8 @@ list(APPEND digital_sources diff_phasor_cc_impl.cc fll_band_edge_cc_impl.cc #framer_sink_1_impl.cc - #glfsr_source_b_impl.cc - #glfsr_source_f_impl.cc + glfsr_source_b_impl.cc + glfsr_source_f_impl.cc #gmskmod_bc_impl.cc #lms_dd_equalizer_cc_impl.cc #kurtotic_equalizer_cc_impl.cc @@ -141,7 +141,7 @@ list(APPEND digital_sources #packet_sink_impl.cc pfb_clock_sync_ccf_impl.cc pfb_clock_sync_fff_impl.cc - #pn_correlator_cc_impl.cc + pn_correlator_cc_impl.cc #probe_density_b_impl.cc #probe_mpsk_snr_est_c_impl.cc #scrambler_bb_impl.cc diff --git a/gr-digital/lib/correlate_access_code_bb_impl.cc b/gr-digital/lib/correlate_access_code_bb_impl.cc new file mode 100644 index 0000000000..4e1131afda --- /dev/null +++ b/gr-digital/lib/correlate_access_code_bb_impl.cc @@ -0,0 +1,133 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010-2012 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 3, 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 "correlate_access_code_bb_impl.h" +#include <gr_io_signature.h> +#include <gr_count_bits.h> +#include <stdexcept> +#include <cstdio> + +namespace gr { + namespace digital { + +#define VERBOSE 0 + + correlate_access_code_bb::sptr + correlate_access_code_bb::make(const std::string &access_code, int threshold) + { + return gnuradio::get_initial_sptr + (new correlate_access_code_bb_impl(access_code, threshold)); + } + + correlate_access_code_bb_impl::correlate_access_code_bb_impl( + const std::string &access_code, int threshold) + : gr_sync_block("correlate_access_code_bb", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(char))), + d_data_reg(0), d_flag_reg(0), d_flag_bit(0), d_mask(0), + d_threshold(threshold) + { + if(!set_access_code(access_code)) { + throw std::out_of_range ("access_code is > 64 bits"); + } + } + + correlate_access_code_bb_impl::~correlate_access_code_bb_impl() + { + } + + bool + correlate_access_code_bb_impl::set_access_code( + const std::string &access_code) + { + unsigned len = access_code.length(); // # of bytes in string + if(len > 64) + return false; + + // set len top bits to 1. + d_mask = ((~0ULL) >> (64 - len)) << (64 - len); + + d_flag_bit = 1LL << (64 - len); // Where we or-in new flag values. + // new data always goes in 0x0000000000000001 + d_access_code = 0; + for(unsigned i=0; i < 64; i++){ + d_access_code <<= 1; + if(i < len) + d_access_code |= access_code[i] & 1; // look at LSB only + } + + return true; + } + + int + correlate_access_code_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const unsigned char *in = (const unsigned char*)input_items[0]; + unsigned char *out = (unsigned char*)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + // compute output value + unsigned int t = 0; + + t |= ((d_data_reg >> 63) & 0x1) << 0; + t |= ((d_flag_reg >> 63) & 0x1) << 1; // flag bit + out[i] = t; + + // compute hamming distance between desired access code and current data + unsigned long long wrong_bits = 0; + unsigned int nwrong = d_threshold+1; + int new_flag = 0; + + wrong_bits = (d_data_reg ^ d_access_code) & d_mask; + nwrong = gr_count_bits64(wrong_bits); + + // test for access code with up to threshold errors + new_flag = (nwrong <= d_threshold); + +#if VERBOSE + if(new_flag) { + fprintf(stderr, "access code found: %llx\n", d_access_code); + } + else { + fprintf(stderr, "%llx ==> %llx\n", d_access_code, d_data_reg); + } +#endif + + // shift in new data and new flag + d_data_reg = (d_data_reg << 1) | (in[i] & 0x1); + d_flag_reg = (d_flag_reg << 1); + if(new_flag) { + d_flag_reg |= d_flag_bit; + } + } + + return noutput_items; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/lib/correlate_access_code_bb_impl.h b/gr-digital/lib/correlate_access_code_bb_impl.h new file mode 100644 index 0000000000..ad44b36400 --- /dev/null +++ b/gr-digital/lib/correlate_access_code_bb_impl.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,2011,2012 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 3, 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_DIGITAL_CORRELATE_ACCESS_CODE_BB_IMPL_H +#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_IMPL_H + +#include <digital/correlate_access_code_bb.h> + +namespace gr { + namespace digital { + + class correlate_access_code_bb_impl : + public correlate_access_code_bb + { + private: + unsigned long long d_access_code; // access code to locate start of packet + // access code is left justified in the word + unsigned long long d_data_reg; // used to look for access_code + unsigned long long d_flag_reg; // keep track of decisions + unsigned long long d_flag_bit; // mask containing 1 bit which is location of new flag + unsigned long long d_mask; // masks access_code bits (top N bits are set where + // N is the number of bits in the access code) + unsigned int d_threshold; // how many bits may be wrong in sync vector + + public: + correlate_access_code_bb_impl(const std::string &access_code, + int threshold); + ~correlate_access_code_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool set_access_code(const std::string &access_code); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_BB_IMPL_H */ diff --git a/gr-digital/lib/correlate_access_code_tag_bb_impl.cc b/gr-digital/lib/correlate_access_code_tag_bb_impl.cc new file mode 100644 index 0000000000..d375daf95c --- /dev/null +++ b/gr-digital/lib/correlate_access_code_tag_bb_impl.cc @@ -0,0 +1,136 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010-2012 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 3, 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 "correlate_access_code_tag_bb_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> +#include <gr_count_bits.h> +#include <cstdio> +#include <iostream> + +namespace gr { + namespace digital { + +#define VERBOSE 0 + + correlate_access_code_tag_bb::sptr + correlate_access_code_tag_bb::make(const std::string &access_code, + int threshold, + const std::string &tag_name) + { + return gnuradio::get_initial_sptr + (new correlate_access_code_tag_bb_impl(access_code, + threshold, tag_name)); + } + + + correlate_access_code_tag_bb_impl::correlate_access_code_tag_bb_impl( + const std::string &access_code, int threshold, const std::string &tag_name) + : gr_sync_block("correlate_access_code_tag_bb", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(char))), + d_data_reg(0), d_mask(0), + d_threshold(threshold), d_len(0) + { + if(!set_access_code(access_code)) { + throw std::out_of_range ("access_code is > 64 bits"); + } + + std::stringstream str; + str << name() << unique_id(); + d_me = pmt::pmt_string_to_symbol(str.str()); + d_key = pmt::pmt_string_to_symbol(tag_name); + } + + correlate_access_code_tag_bb_impl::~correlate_access_code_tag_bb_impl() + { + } + + bool + correlate_access_code_tag_bb_impl::set_access_code( + const std::string &access_code) + { + d_len = access_code.length(); // # of bytes in string + if(d_len > 64) + return false; + + // set len top bits to 1. + d_mask = ((~0ULL) >> (64 - d_len)) << (64 - d_len); + + d_access_code = 0; + for(unsigned i=0; i < 64; i++){ + d_access_code <<= 1; + if(i < d_len) + d_access_code |= access_code[i] & 1; // look at LSB only + } + + return true; + } + + int + correlate_access_code_tag_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const unsigned char *in = (const unsigned char*)input_items[0]; + unsigned char *out = (unsigned char*)output_items[0]; + + uint64_t abs_out_sample_cnt = nitems_written(0); + + for(int i = 0; i < noutput_items; i++) { + out[i] = in[i]; + + // compute hamming distance between desired access code and current data + unsigned long long wrong_bits = 0; + unsigned int nwrong = d_threshold+1; + int new_flag = 0; + + wrong_bits = (d_data_reg ^ d_access_code) & d_mask; + nwrong = gr_count_bits64(wrong_bits); + + // test for access code with up to threshold errors + new_flag = (nwrong <= d_threshold); + + // shift in new data and new flag + d_data_reg = (d_data_reg << 1) | (in[i] & 0x1); + if(new_flag) { + if(VERBOSE) + std::cerr << "writing tag at sample " << abs_out_sample_cnt + i << std::endl; + add_item_tag(0, //stream ID + abs_out_sample_cnt + i - 64 + d_len, //sample + d_key, //frame info + pmt::pmt_t(), //data (unused) + d_me //block src id + ); + } + } + + return noutput_items; + } + + } /* namespace digital */ +} /* namespace gr */ + diff --git a/gr-digital/lib/correlate_access_code_tag_bb_impl.h b/gr-digital/lib/correlate_access_code_tag_bb_impl.h new file mode 100644 index 0000000000..17a016fc9c --- /dev/null +++ b/gr-digital/lib/correlate_access_code_tag_bb_impl.h @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,2011,2012 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 3, 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_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_IMPL_H +#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_IMPL_H + +#include <digital/correlate_access_code_tag_bb.h> + +namespace gr { + namespace digital { + + class correlate_access_code_tag_bb_impl : + public correlate_access_code_tag_bb + { + private: + unsigned long long d_access_code; // access code to locate start of packet + // access code is left justified in the word + unsigned long long d_data_reg; // used to look for access_code + unsigned long long d_mask; // masks access_code bits (top N bits are set where + // N is the number of bits in the access code) + unsigned int d_threshold; // how many bits may be wrong in sync vector + unsigned int d_len; // the length of the access code + + pmt::pmt_t d_key, d_me; //d_key is the tag name, d_me is the block name + unique ID + + public: + correlate_access_code_tag_bb_impl(const std::string &access_code, + int threshold, + const std::string &tag_name); + ~correlate_access_code_tag_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool set_access_code(const std::string &access_code); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_BB_IMPL_H */ diff --git a/gr-digital/lib/costas_loop_cc_impl.cc b/gr-digital/lib/costas_loop_cc_impl.cc new file mode 100644 index 0000000000..5afabf4294 --- /dev/null +++ b/gr-digital/lib/costas_loop_cc_impl.cc @@ -0,0 +1,161 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2010-2012 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 3, 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 "costas_loop_cc_impl.h" +#include <gr_io_signature.h> +#include <gr_expj.h> +#include <gr_sincos.h> +#include <gr_math.h> + +namespace gr { + namespace digital { + + costas_loop_cc::sptr + costas_loop_cc::make(float loop_bw, int order) + { + return gnuradio::get_initial_sptr + (new costas_loop_cc_impl(loop_bw, order)); + } + + costas_loop_cc_impl::costas_loop_cc_impl(float loop_bw, int order) + : gr_sync_block("costas_loop_cc", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature2(1, 2, sizeof(gr_complex), sizeof(float))), + gri_control_loop(loop_bw, 1.0, -1.0), + d_order(order), d_phase_detector(NULL) + { + // Set up the phase detector to use based on the constellation order + switch(d_order) { + case 2: + d_phase_detector = &costas_loop_cc_impl::phase_detector_2; + break; + + case 4: + d_phase_detector = &costas_loop_cc_impl::phase_detector_4; + break; + + case 8: + d_phase_detector = &costas_loop_cc_impl::phase_detector_8; + break; + + default: + throw std::invalid_argument("order must be 2, 4, or 8"); + break; + } + } + + costas_loop_cc_impl::~costas_loop_cc_impl() + { + } + + float + costas_loop_cc_impl::phase_detector_8(gr_complex sample) const + { + /* This technique splits the 8PSK constellation into 2 squashed + QPSK constellations, one when I is larger than Q and one + where Q is larger than I. The error is then calculated + proportionally to these squashed constellations by the const + K = sqrt(2)-1. + + The signal magnitude must be > 1 or K will incorrectly bias + the error value. + + Ref: Z. Huang, Z. Yi, M. Zhang, K. Wang, "8PSK demodulation for + new generation DVB-S2", IEEE Proc. Int. Conf. Communications, + Circuits and Systems, Vol. 2, pp. 1447 - 1450, 2004. + */ + + float K = (sqrt(2.0) - 1); + if(fabsf(sample.real()) >= fabsf(sample.imag())) { + return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() - + (sample.imag()>0 ? 1.0 : -1.0) * sample.real() * K); + } + else { + return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() * K - + (sample.imag()>0 ? 1.0 : -1.0) * sample.real()); + } + } + + float + costas_loop_cc_impl::phase_detector_4(gr_complex sample) const + { + return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() - + (sample.imag()>0 ? 1.0 : -1.0) * sample.real()); + } + + float + costas_loop_cc_impl::phase_detector_2(gr_complex sample) const + { + return (sample.real()*sample.imag()); + } + + int + costas_loop_cc_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *iptr = (gr_complex *) input_items[0]; + gr_complex *optr = (gr_complex *) output_items[0]; + float *foptr = (float *) output_items[1]; + + bool write_foptr = output_items.size() >= 2; + + float error; + gr_complex nco_out; + + if(write_foptr) { + for(int i = 0; i < noutput_items; i++) { + nco_out = gr_expj(-d_phase); + optr[i] = iptr[i] * nco_out; + + error = (*this.*d_phase_detector)(optr[i]); + error = gr_branchless_clip(error, 1.0); + + advance_loop(error); + phase_wrap(); + frequency_limit(); + + foptr[i] = d_freq; + } + } + else { + for(int i = 0; i < noutput_items; i++) { + nco_out = gr_expj(-d_phase); + optr[i] = iptr[i] * nco_out; + + error = (*this.*d_phase_detector)(optr[i]); + error = gr_branchless_clip(error, 1.0); + + advance_loop(error); + phase_wrap(); + frequency_limit(); + } + } + return noutput_items; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/lib/costas_loop_cc_impl.h b/gr-digital/lib/costas_loop_cc_impl.h new file mode 100644 index 0000000000..9310368b4d --- /dev/null +++ b/gr-digital/lib/costas_loop_cc_impl.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2011,2012 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 3, 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_DIGITAL_COSTAS_LOOP_CC_IMPL_H +#define INCLUDED_DIGITAL_COSTAS_LOOP_CC_IMPL_H + +#include <digital/costas_loop_cc.h> +#include <gri_control_loop.h> + +namespace gr { + namespace digital { + + class costas_loop_cc_impl : public costas_loop_cc, gri_control_loop + { + private: + int d_order; + + /*! \brief the phase detector circuit for 8th-order PSK loops + * \param sample complex sample + * \return the phase error + */ + float phase_detector_8(gr_complex sample) const; // for 8PSK + + /*! \brief the phase detector circuit for fourth-order loops + * \param sample complex sample + * \return the phase error + */ + float phase_detector_4(gr_complex sample) const; // for QPSK + + /*! \brief the phase detector circuit for second-order loops + * \param sample a complex sample + * \return the phase error + */ + float phase_detector_2(gr_complex sample) const; // for BPSK + + float (costas_loop_cc_impl::*d_phase_detector)(gr_complex sample) const; + + public: + costas_loop_cc_impl(float loop_bw, int order); + ~costas_loop_cc_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_COSTAS_LOOP_CC_IMPL_H */ diff --git a/gr-digital/lib/digital_correlate_access_code_bb.cc b/gr-digital/lib/digital_correlate_access_code_bb.cc deleted file mode 100644 index f21b57d92c..0000000000 --- a/gr-digital/lib/digital_correlate_access_code_bb.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2006,2010,2011 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 3, 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 <digital_correlate_access_code_bb.h> -#include <gr_io_signature.h> -#include <stdexcept> -#include <gr_count_bits.h> -#include <cstdio> - - -#define VERBOSE 0 - - -digital_correlate_access_code_bb_sptr -digital_make_correlate_access_code_bb (const std::string &access_code, int threshold) -{ - return gnuradio::get_initial_sptr(new digital_correlate_access_code_bb - (access_code, threshold)); -} - - -digital_correlate_access_code_bb::digital_correlate_access_code_bb ( - const std::string &access_code, int threshold) - : gr_sync_block ("correlate_access_code_bb", - gr_make_io_signature (1, 1, sizeof(char)), - gr_make_io_signature (1, 1, sizeof(char))), - d_data_reg(0), d_flag_reg(0), d_flag_bit(0), d_mask(0), - d_threshold(threshold) - -{ - if (!set_access_code(access_code)){ - fprintf(stderr, "digital_correlate_access_code_bb: access_code is > 64 bits\n"); - throw std::out_of_range ("access_code is > 64 bits"); - } -} - -digital_correlate_access_code_bb::~digital_correlate_access_code_bb () -{ -} - -bool -digital_correlate_access_code_bb::set_access_code( - const std::string &access_code) -{ - unsigned len = access_code.length(); // # of bytes in string - if (len > 64) - return false; - - // set len top bits to 1. - d_mask = ((~0ULL) >> (64 - len)) << (64 - len); - - d_flag_bit = 1LL << (64 - len); // Where we or-in new flag values. - // new data always goes in 0x0000000000000001 - d_access_code = 0; - for (unsigned i=0; i < 64; i++){ - d_access_code <<= 1; - if (i < len) - d_access_code |= access_code[i] & 1; // look at LSB only - } - - return true; -} - -int -digital_correlate_access_code_bb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - - for (int i = 0; i < noutput_items; i++){ - - // compute output value - unsigned int t = 0; - - t |= ((d_data_reg >> 63) & 0x1) << 0; - t |= ((d_flag_reg >> 63) & 0x1) << 1; // flag bit - out[i] = t; - - // compute hamming distance between desired access code and current data - unsigned long long wrong_bits = 0; - unsigned int nwrong = d_threshold+1; - int new_flag = 0; - - wrong_bits = (d_data_reg ^ d_access_code) & d_mask; - nwrong = gr_count_bits64(wrong_bits); - - // test for access code with up to threshold errors - new_flag = (nwrong <= d_threshold); - -#if VERBOSE - if(new_flag) { - fprintf(stderr, "access code found: %llx\n", d_access_code); - } - else { - fprintf(stderr, "%llx ==> %llx\n", d_access_code, d_data_reg); - } -#endif - - // shift in new data and new flag - d_data_reg = (d_data_reg << 1) | (in[i] & 0x1); - d_flag_reg = (d_flag_reg << 1); - if (new_flag) { - d_flag_reg |= d_flag_bit; - } - } - - return noutput_items; -} - diff --git a/gr-digital/lib/digital_correlate_access_code_tag_bb.cc b/gr-digital/lib/digital_correlate_access_code_tag_bb.cc deleted file mode 100644 index 95f06534e3..0000000000 --- a/gr-digital/lib/digital_correlate_access_code_tag_bb.cc +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2006,2010-2012 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 3, 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 <digital_correlate_access_code_tag_bb.h> -#include <gr_io_signature.h> -#include <stdexcept> -#include <gr_count_bits.h> -#include <cstdio> -#include <iostream> - -#define VERBOSE 0 - - -digital_correlate_access_code_tag_bb_sptr -digital_make_correlate_access_code_tag_bb (const std::string &access_code, - int threshold, - const std::string &tag_name) -{ - return gnuradio::get_initial_sptr(new digital_correlate_access_code_tag_bb - (access_code, threshold, tag_name)); -} - - -digital_correlate_access_code_tag_bb::digital_correlate_access_code_tag_bb ( - const std::string &access_code, int threshold, const std::string &tag_name) - : gr_sync_block ("correlate_access_code_tag_bb", - gr_make_io_signature (1, 1, sizeof(char)), - gr_make_io_signature (1, 1, sizeof(char))), - d_data_reg(0), d_mask(0), - d_threshold(threshold), d_len(0) -{ - if (!set_access_code(access_code)) { - fprintf(stderr, "digital_correlate_access_code_tag_bb: access_code is > 64 bits\n"); - throw std::out_of_range ("access_code is > 64 bits"); - } - - std::stringstream str; - str << name() << unique_id(); - d_me = pmt::pmt_string_to_symbol(str.str()); - d_key = pmt::pmt_string_to_symbol(tag_name); -} - -digital_correlate_access_code_tag_bb::~digital_correlate_access_code_tag_bb () -{ -} - -bool -digital_correlate_access_code_tag_bb::set_access_code( - const std::string &access_code) -{ - d_len = access_code.length(); // # of bytes in string - if (d_len > 64) - return false; - - // set len top bits to 1. - d_mask = ((~0ULL) >> (64 - d_len)) << (64 - d_len); - - d_access_code = 0; - for (unsigned i=0; i < 64; i++){ - d_access_code <<= 1; - if (i < d_len) - d_access_code |= access_code[i] & 1; // look at LSB only - } - - return true; -} - -int -digital_correlate_access_code_tag_bb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - - uint64_t abs_out_sample_cnt = nitems_written(0); - - for (int i = 0; i < noutput_items; i++){ - - out[i] = in[i]; - - // compute hamming distance between desired access code and current data - unsigned long long wrong_bits = 0; - unsigned int nwrong = d_threshold+1; - int new_flag = 0; - - wrong_bits = (d_data_reg ^ d_access_code) & d_mask; - nwrong = gr_count_bits64(wrong_bits); - - // test for access code with up to threshold errors - new_flag = (nwrong <= d_threshold); - - // shift in new data and new flag - d_data_reg = (d_data_reg << 1) | (in[i] & 0x1); - if (new_flag) { - if(VERBOSE) std::cout << "writing tag at sample " << abs_out_sample_cnt + i << std::endl; - add_item_tag(0, //stream ID - abs_out_sample_cnt + i - 64 + d_len, //sample - d_key, //frame info - pmt::pmt_t(), //data (unused) - d_me //block src id - ); - } - } - - return noutput_items; -} - diff --git a/gr-digital/lib/digital_costas_loop_cc.cc b/gr-digital/lib/digital_costas_loop_cc.cc deleted file mode 100644 index 370dc7e5c1..0000000000 --- a/gr-digital/lib/digital_costas_loop_cc.cc +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2010,2011 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 3, 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 <digital_costas_loop_cc.h> -#include <gr_io_signature.h> -#include <gr_expj.h> -#include <gr_sincos.h> -#include <gr_math.h> - -digital_costas_loop_cc_sptr -digital_make_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument) -{ - return gnuradio::get_initial_sptr(new digital_costas_loop_cc - (loop_bw, order)); -} - -digital_costas_loop_cc::digital_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument) - : gr_sync_block ("costas_loop_cc", - gr_make_io_signature (1, 1, sizeof (gr_complex)), - gr_make_io_signature2 (1, 2, sizeof (gr_complex), sizeof(float))), - gri_control_loop(loop_bw, 1.0, -1.0), - d_order(order), d_phase_detector(NULL) -{ - // Set up the phase detector to use based on the constellation order - switch(d_order) { - case 2: - d_phase_detector = &digital_costas_loop_cc::phase_detector_2; - break; - - case 4: - d_phase_detector = &digital_costas_loop_cc::phase_detector_4; - break; - - case 8: - d_phase_detector = &digital_costas_loop_cc::phase_detector_8; - break; - - default: - throw std::invalid_argument("order must be 2, 4, or 8"); - break; - } -} - -float -digital_costas_loop_cc::phase_detector_8(gr_complex sample) const -{ - /* This technique splits the 8PSK constellation into 2 squashed - QPSK constellations, one when I is larger than Q and one where - Q is larger than I. The error is then calculated proportionally - to these squashed constellations by the const K = sqrt(2)-1. - - The signal magnitude must be > 1 or K will incorrectly bias - the error value. - - Ref: Z. Huang, Z. Yi, M. Zhang, K. Wang, "8PSK demodulation for - new generation DVB-S2", IEEE Proc. Int. Conf. Communications, - Circuits and Systems, Vol. 2, pp. 1447 - 1450, 2004. - */ - - float K = (sqrt(2.0) - 1); - if(fabsf(sample.real()) >= fabsf(sample.imag())) { - return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() - - (sample.imag()>0 ? 1.0 : -1.0) * sample.real() * K); - } - else { - return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() * K - - (sample.imag()>0 ? 1.0 : -1.0) * sample.real()); - } -} - -float -digital_costas_loop_cc::phase_detector_4(gr_complex sample) const -{ - - return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() - - (sample.imag()>0 ? 1.0 : -1.0) * sample.real()); -} - -float -digital_costas_loop_cc::phase_detector_2(gr_complex sample) const -{ - return (sample.real()*sample.imag()); -} - -int -digital_costas_loop_cc::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const gr_complex *iptr = (gr_complex *) input_items[0]; - gr_complex *optr = (gr_complex *) output_items[0]; - float *foptr = (float *) output_items[1]; - - bool write_foptr = output_items.size() >= 2; - - float error; - gr_complex nco_out; - - if (write_foptr) { - - for (int i = 0; i < noutput_items; i++){ - nco_out = gr_expj(-d_phase); - optr[i] = iptr[i] * nco_out; - - error = (*this.*d_phase_detector)(optr[i]); - error = gr_branchless_clip(error, 1.0); - - advance_loop(error); - phase_wrap(); - frequency_limit(); - - foptr[i] = d_freq; - } - } else { - for (int i = 0; i < noutput_items; i++){ - nco_out = gr_expj(-d_phase); - optr[i] = iptr[i] * nco_out; - - error = (*this.*d_phase_detector)(optr[i]); - error = gr_branchless_clip(error, 1.0); - - advance_loop(error); - phase_wrap(); - frequency_limit(); - } - } - return noutput_items; -} diff --git a/gr-digital/lib/digital_glfsr_source_b.cc b/gr-digital/lib/digital_glfsr_source_b.cc deleted file mode 100644 index 63a5ffdb0a..0000000000 --- a/gr-digital/lib/digital_glfsr_source_b.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2010,2012 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 3, 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 <digital_glfsr_source_b.h> -#include <digital_impl_glfsr.h> -#include <gr_io_signature.h> -#include <stdexcept> - -digital_glfsr_source_b_sptr -digital_make_glfsr_source_b(int degree, bool repeat, int mask, int seed) -{ - return gnuradio::get_initial_sptr(new digital_glfsr_source_b - (degree, repeat, mask, seed)); -} - -digital_glfsr_source_b::digital_glfsr_source_b(int degree, bool repeat, - int mask, int seed) - : gr_sync_block ("glfsr_source_b", - gr_make_io_signature (0, 0, 0), - gr_make_io_signature (1, 1, sizeof(unsigned char))), - d_repeat(repeat), - d_index(0) -{ - if (degree < 1 || degree > 32) - throw std::runtime_error("digital_glfsr_source_b: degree must be between 1 and 32 inclusive"); - d_length = (unsigned int)((1ULL << degree)-1); - - if (mask == 0) - mask = digital_impl_glfsr::glfsr_mask(degree); - d_glfsr = new digital_impl_glfsr(mask, seed); -} - -digital_glfsr_source_b::~digital_glfsr_source_b() -{ - delete d_glfsr; -} - -int -digital_glfsr_source_b::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - char *out = (char *) 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] = d_glfsr->next_bit(); - d_index++; - if (d_index > d_length && d_repeat == false) - break; - } - - return i; -} - -int -digital_glfsr_source_b::mask() const -{ - return d_glfsr->mask(); -} diff --git a/gr-digital/lib/digital_glfsr_source_f.cc b/gr-digital/lib/digital_glfsr_source_f.cc deleted file mode 100644 index 6ae84d5679..0000000000 --- a/gr-digital/lib/digital_glfsr_source_f.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2010,2012 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 3, 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 <digital_glfsr_source_f.h> -#include <digital_impl_glfsr.h> -#include <gr_io_signature.h> -#include <stdexcept> - -digital_glfsr_source_f_sptr -digital_make_glfsr_source_f(int degree, bool repeat, int mask, int seed) -{ - return gnuradio::get_initial_sptr(new digital_glfsr_source_f - (degree, repeat, mask, seed)); -} - -digital_glfsr_source_f::digital_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("digital_glfsr_source_f: degree must be between 1 and 32 inclusive"); - d_length = (unsigned int)((1ULL << degree)-1); - - if (mask == 0) - mask = digital_impl_glfsr::glfsr_mask(degree); - d_glfsr = new digital_impl_glfsr(mask, seed); -} - -digital_glfsr_source_f::~digital_glfsr_source_f() -{ - delete d_glfsr; -} - -int -digital_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 -digital_glfsr_source_f::mask() const -{ - return d_glfsr->mask(); -} diff --git a/gr-digital/lib/digital_impl_glfsr.cc b/gr-digital/lib/digital_impl_glfsr.cc deleted file mode 100644 index 342980e535..0000000000 --- a/gr-digital/lib/digital_impl_glfsr.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2012 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 3, 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 <digital_impl_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 digital_impl_glfsr::glfsr_mask(int degree) -{ - if (degree < 1 || degree > 32) - throw std::runtime_error("digital_impl_glfsr::glfsr_mask(): degree must be between 1 and 32 inclusive"); - return s_polynomial_masks[degree]; -} diff --git a/gr-digital/lib/digital_pn_correlator_cc.cc b/gr-digital/lib/digital_pn_correlator_cc.cc deleted file mode 100644 index 52e06bc2ad..0000000000 --- a/gr-digital/lib/digital_pn_correlator_cc.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2010,2012 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 3, 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 <digital_pn_correlator_cc.h> -#include <gr_io_signature.h> - -digital_pn_correlator_cc_sptr -digital_make_pn_correlator_cc(int degree, int mask, int seed) -{ - return gnuradio::get_initial_sptr(new digital_pn_correlator_cc - (degree, mask, seed)); -} - -digital_pn_correlator_cc::digital_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 = digital_impl_glfsr::glfsr_mask(degree); - d_reference = new digital_impl_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; -} - -digital_pn_correlator_cc::~digital_pn_correlator_cc() -{ - delete d_reference; -} - -int -digital_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/gr-digital/lib/glfsr.cc b/gr-digital/lib/glfsr.cc new file mode 100644 index 0000000000..5c9d22af88 --- /dev/null +++ b/gr-digital/lib/glfsr.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012 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 3, 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 <digital/glfsr.h> +#include <stdexcept> + +namespace gr { + namespace digital { + + 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 + }; + + glfsr::~glfsr() + { + } + + int glfsr::glfsr_mask(int degree) + { + if(degree < 1 || degree > 32) + throw std::runtime_error("glfsr::glfsr_mask(): degree must be between 1 and 32 inclusive"); + return s_polynomial_masks[degree]; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/lib/glfsr_source_b_impl.cc b/gr-digital/lib/glfsr_source_b_impl.cc new file mode 100644 index 0000000000..e4171d80e7 --- /dev/null +++ b/gr-digital/lib/glfsr_source_b_impl.cc @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2012 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 3, 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 "glfsr_source_b_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> + +namespace gr { + namespace digital { + + glfsr_source_b::sptr + glfsr_source_b::make(int degree, bool repeat, int mask, int seed) + { + return gnuradio::get_initial_sptr + (new glfsr_source_b_impl(degree, repeat, mask, seed)); + } + + glfsr_source_b_impl::glfsr_source_b_impl(int degree, bool repeat, + int mask, int seed) + : gr_sync_block("glfsr_source_b", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, sizeof(unsigned char))), + d_repeat(repeat), d_index(0) + { + if(degree < 1 || degree > 32) + throw std::runtime_error("glfsr_source_b_impl: degree must be between 1 and 32 inclusive"); + d_length = (unsigned int)((1ULL << degree)-1); + + if(mask == 0) + mask = glfsr::glfsr_mask(degree); + d_glfsr = new glfsr(mask, seed); + } + + glfsr_source_b_impl::~glfsr_source_b_impl() + { + delete d_glfsr; + } + + int + glfsr_source_b_impl::mask() const + { + return d_glfsr->mask(); + } + + int + glfsr_source_b_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + char *out = (char*)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] = d_glfsr->next_bit(); + d_index++; + if(d_index > d_length && d_repeat == false) + break; + } + + return i; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/swig/digital_pn_correlator_cc.i b/gr-digital/lib/glfsr_source_b_impl.h index 11ccf12c2f..f52cfa0f20 100644 --- a/gr-digital/swig/digital_pn_correlator_cc.i +++ b/gr-digital/lib/glfsr_source_b_impl.h @@ -20,13 +20,38 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(digital,pn_correlator_cc) +#ifndef INCLUDED_GR_GLFSR_SOURCE_B_IMPL_H +#define INCLUDED_GR_GLFSR_SOURCE_B_IMPL_H -digital_pn_correlator_cc_sptr -digital_make_pn_correlator_cc(int degree, int mask=0, int seed=1); +#include <digital/glfsr_source_b.h> +#include <digital/glfsr.h> -class digital_pn_correlator_cc : public gr_sync_decimator -{ - protected: - digital_pn_correlator_cc(); -}; +namespace gr { + namespace digital { + + class glfsr_source_b_impl : public glfsr_source_b + { + private: + glfsr *d_glfsr; + + bool d_repeat; + unsigned int d_index; + unsigned int d_length; + + public: + glfsr_source_b_impl(int degree, bool repeat=true, + int mask=0, int seed=1); + ~glfsr_source_b_impl(); + + 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; + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_GLFSR_SOURCE_B_IMPL_H */ diff --git a/gr-digital/lib/glfsr_source_f_impl.cc b/gr-digital/lib/glfsr_source_f_impl.cc new file mode 100644 index 0000000000..1e0ee2d85e --- /dev/null +++ b/gr-digital/lib/glfsr_source_f_impl.cc @@ -0,0 +1,90 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2012 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 3, 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 "glfsr_source_f_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> + +namespace gr { + namespace digital { + + glfsr_source_f::sptr + glfsr_source_f::make(int degree, bool repeat, int mask, int seed) + { + return gnuradio::get_initial_sptr + (new glfsr_source_f_impl(degree, repeat, mask, seed)); + } + + glfsr_source_f_impl::glfsr_source_f_impl(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("glfsr_source_f_impl: degree must be between 1 and 32 inclusive"); + d_length = (unsigned int)((1ULL << degree)-1); + + if(mask == 0) + mask = glfsr::glfsr_mask(degree); + d_glfsr = new glfsr(mask, seed); + } + + glfsr_source_f_impl::~glfsr_source_f_impl() + { + delete d_glfsr; + } + + int + glfsr_source_f_impl::mask() const + { + return d_glfsr->mask(); + } + + int + glfsr_source_f_impl::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; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/include/digital_impl_glfsr.h b/gr-digital/lib/glfsr_source_f_impl.h index 3aadf7cf2f..4168016097 100644 --- a/gr-digital/include/digital_impl_glfsr.h +++ b/gr-digital/lib/glfsr_source_f_impl.h @@ -20,38 +20,38 @@ * Boston, MA 02110-1301, USA. */ -#ifndef INCLUDED_DIGITAL_IMPL_GLFSR_H -#define INCLUDED_DIGITAL_IMPL_GLFSR_H +#ifndef INCLUDED_GR_GLFSR_SOURCE_F_IMPL_H +#define INCLUDED_GR_GLFSR_SOURCE_F_IMPL_H -#include <digital_api.h> +#include <digital/glfsr_source_f.h> +#include <digital/glfsr.h> -/*! - * \brief Galois Linear Feedback Shift Register using specified polynomial mask - * \ingroup misc - * - * Generates a maximal length pseudo-random sequence of length 2^degree-1 - */ +namespace gr { + namespace digital { + + class glfsr_source_f_impl : public glfsr_source_f + { + private: + glfsr *d_glfsr; -class DIGITAL_API digital_impl_glfsr -{ - private: - int d_shift_register; - int d_mask; + bool d_repeat; + unsigned int d_index; + unsigned int d_length; - public: + public: + glfsr_source_f_impl(int degree, bool repeat=true, + int mask=0, int seed=1); + ~glfsr_source_f_impl(); - digital_impl_glfsr(int mask, int seed) { d_shift_register = seed; d_mask = mask; } - static int glfsr_mask(int degree); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); - unsigned char next_bit() { - unsigned char bit = d_shift_register & 1; - d_shift_register >>= 1; - if (bit) - d_shift_register ^= d_mask; - return bit; - } + unsigned int period() const { return d_length; } + int mask() const; + }; - int mask() const { return d_mask; } -}; + } /* namespace digital */ +} /* namespace gr */ -#endif /* INCLUDED_DIGITAL_IMPL_GLFSR_H */ +#endif /* INCLUDED_GR_GLFSR_SOURCE_F_IMPL_H */ diff --git a/gr-digital/lib/pn_correlator_cc_impl.cc b/gr-digital/lib/pn_correlator_cc_impl.cc new file mode 100644 index 0000000000..da0bdbefe9 --- /dev/null +++ b/gr-digital/lib/pn_correlator_cc_impl.cc @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2012 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 3, 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 "pn_correlator_cc_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace digital { + + pn_correlator_cc::sptr + pn_correlator_cc::make(int degree, int mask, int seed) + { + return gnuradio::get_initial_sptr + (new pn_correlator_cc_impl(degree, mask, seed)); + } + + pn_correlator_cc_impl::pn_correlator_cc_impl(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 = glfsr::glfsr_mask(degree); + d_reference = new 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; + } + + pn_correlator_cc_impl::~pn_correlator_cc_impl() + { + delete d_reference; + } + + int + pn_correlator_cc_impl::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; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/swig/digital_glfsr_source_b.i b/gr-digital/lib/pn_correlator_cc_impl.h index b1c487209e..bea9a30505 100644 --- a/gr-digital/swig/digital_glfsr_source_b.i +++ b/gr-digital/lib/pn_correlator_cc_impl.h @@ -20,16 +20,32 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(digital,glfsr_source_b); +#ifndef INCLUDED_GR_PN_CORRELATOR_CC_IMPL_H +#define INCLUDED_GR_PN_CORRELATOR_CC_IMPL_H -digital_glfsr_source_b_sptr -digital_make_glfsr_source_b(int degree, bool repeat=true, - int mask=0, int seed=1) - throw (std::runtime_error); +#include <digital/pn_correlator_cc.h> +#include <digital/glfsr.h> -class digital_glfsr_source_b : public gr_sync_block -{ -public: - unsigned int period() const; - int mask() const; -}; +namespace gr { + namespace digital { + + class pn_correlator_cc_impl : public pn_correlator_cc + { + private: + int d_len; + float d_pn; + glfsr *d_reference; + + public: + pn_correlator_cc_impl(int degree, int mask=0, int seed=1); + ~pn_correlator_cc_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PN_CORRELATOR_CC_IMPL_H */ diff --git a/gr-digital/python/qa_correlate_access_code.py b/gr-digital/python/qa_correlate_access_code.py index 96246dcfb9..5a5f2209f7 100755 --- a/gr-digital/python/qa_correlate_access_code.py +++ b/gr-digital/python/qa_correlate_access_code.py @@ -52,13 +52,13 @@ class test_correlate_access_code(gr_unittest.TestCase): # 0 0 0 1 0 0 0 1 src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7 expected_result = pad + (1, 0, 1, 1, 3, 1, 0, 1, 1, 2) + (0,) * 6 - src = gr.vector_source_b (src_data) + src = gr.vector_source_b(src_data) op = digital.correlate_access_code_bb("1011", 0) - dst = gr.vector_sink_b () - self.tb.connect (src, op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (expected_result, result_data) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) def test_002(self): @@ -69,13 +69,13 @@ class test_correlate_access_code(gr_unittest.TestCase): #print access_code src_data = code + (1, 0, 1, 1) + pad expected_result = pad + code + (3, 0, 1, 1) - src = gr.vector_source_b (src_data) + src = gr.vector_source_b(src_data) op = digital.correlate_access_code_bb(access_code, 0) - dst = gr.vector_sink_b () - self.tb.connect (src, op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (expected_result, result_data) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) def test_003(self): code = tuple(string_to_1_0_list(default_access_code)) @@ -85,14 +85,13 @@ class test_correlate_access_code(gr_unittest.TestCase): #print access_code src_data = code + (1, 0, 1, 1) + pad expected_result = code + (1, 0, 1, 1) + pad - src = gr.vector_source_b (src_data) + src = gr.vector_source_b(src_data) op = digital.correlate_access_code_tag_bb(access_code, 0, "test") - dst = gr.vector_sink_b () - self.tb.connect (src, op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (expected_result, result_data) - + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) if __name__ == '__main__': gr_unittest.run(test_correlate_access_code, "test_correlate_access_code.xml") diff --git a/gr-digital/python/qa_glfsr_source.py b/gr-digital/python/qa_glfsr_source.py index 7d02037335..c5adab3023 100755 --- a/gr-digital/python/qa_glfsr_source.py +++ b/gr-digital/python/qa_glfsr_source.py @@ -25,10 +25,10 @@ import digital_swig as digital class test_glfsr_source(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_000_make_b(self): diff --git a/gr-digital/swig/digital_costas_loop_cc.i b/gr-digital/swig/digital_costas_loop_cc.i deleted file mode 100644 index ab09200a0a..0000000000 --- a/gr-digital/swig/digital_costas_loop_cc.i +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005,2006,2011 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 3, 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(digital,costas_loop_cc); - -digital_costas_loop_cc_sptr -digital_make_costas_loop_cc (float loop_bw, int order - ) throw (std::invalid_argument); - -class digital_costas_loop_cc : public gr_sync_block, public gri_control_loop -{ - private: - digital_costas_loop_cc (float loop_bw, int order); -}; diff --git a/gr-digital/swig/digital_glfsr_source_f.i b/gr-digital/swig/digital_glfsr_source_f.i deleted file mode 100644 index 4d94d8cd49..0000000000 --- a/gr-digital/swig/digital_glfsr_source_f.i +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2012 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 3, 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(digital,glfsr_source_f); - -digital_glfsr_source_f_sptr -digital_make_glfsr_source_f(int degree, bool repeat=true, - int mask=0, int seed=1) - throw (std::runtime_error); - -class digital_glfsr_source_f : public gr_sync_block -{ -public: - unsigned int period() const; - int mask() const; -}; diff --git a/gr-digital/swig/digital_swig.i b/gr-digital/swig/digital_swig.i index e4049f0a11..3598c58683 100644 --- a/gr-digital/swig/digital_swig.i +++ b/gr-digital/swig/digital_swig.i @@ -43,69 +43,87 @@ %{ #include "digital/additive_scrambler_bb.h" #include "digital/binary_slicer_fb.h" +#include "digital/chunks_to_symbols_bf.h" +#include "digital/chunks_to_symbols_bc.h" +#include "digital/chunks_to_symbols_sf.h" +#include "digital/chunks_to_symbols_sc.h" +#include "digital/chunks_to_symbols_if.h" +#include "digital/chunks_to_symbols_ic.h" #include "digital/clock_recovery_mm_cc.h" #include "digital/clock_recovery_mm_ff.h" #include "digital/cma_equalizer_cc.h" #include "digital/constellation.h" #include "digital/constellation_receiver_cb.h" #include "digital/constellation_decoder_cb.h" +#include "digital/correlate_access_code_bb.h" +#include "digital/correlate_access_code_tag_bb.h" +#include "digital/costas_loop_cc.h" #include "digital/diff_decoder_bb.h" #include "digital/diff_encoder_bb.h" #include "digital/diff_phasor_cc.h" -#include "digital/chunks_to_symbols_bf.h" -#include "digital/chunks_to_symbols_bc.h" -#include "digital/chunks_to_symbols_sf.h" -#include "digital/chunks_to_symbols_sc.h" -#include "digital/chunks_to_symbols_if.h" -#include "digital/chunks_to_symbols_ic.h" -#include "digital/map_bb.h" #include "digital/fll_band_edge_cc.h" +#include "digital/glfsr_source_b.h" +#include "digital/glfsr_source_f.h" +#include "digital/map_bb.h" #include "digital/pfb_clock_sync_ccf.h" #include "digital/pfb_clock_sync_fff.h" +#include "digital/pn_correlator_cc.h" %} %include "digital/additive_scrambler_bb.h" %include "digital/binary_slicer_fb.h" +%include "digital/chunks_to_symbols_bf.h" +%include "digital/chunks_to_symbols_bc.h" +%include "digital/chunks_to_symbols_sf.h" +%include "digital/chunks_to_symbols_sc.h" +%include "digital/chunks_to_symbols_if.h" +%include "digital/chunks_to_symbols_ic.h" %include "digital/clock_recovery_mm_cc.h" %include "digital/clock_recovery_mm_ff.h" %include "digital/cma_equalizer_cc.h" %include "digital/constellation.h" %include "digital/constellation_receiver_cb.h" %include "digital/constellation_decoder_cb.h" +%include "digital/correlate_access_code_bb.h" +%include "digital/correlate_access_code_tag_bb.h" +%include "digital/costas_loop_cc.h" %include "digital/diff_decoder_bb.h" %include "digital/diff_encoder_bb.h" %include "digital/diff_phasor_cc.h" -%include "digital/chunks_to_symbols_bf.h" -%include "digital/chunks_to_symbols_bc.h" -%include "digital/chunks_to_symbols_sf.h" -%include "digital/chunks_to_symbols_sc.h" -%include "digital/chunks_to_symbols_if.h" -%include "digital/chunks_to_symbols_ic.h" -%include "digital/map_bb.h" %include "digital/fll_band_edge_cc.h" +%include "digital/glfsr_source_b.h" +%include "digital/glfsr_source_f.h" +%include "digital/map_bb.h" %include "digital/pfb_clock_sync_ccf.h" %include "digital/pfb_clock_sync_fff.h" +%include "digital/pn_correlator_cc.h" GR_SWIG_BLOCK_MAGIC2(digital, additive_scrambler_bb); GR_SWIG_BLOCK_MAGIC2(digital, binary_slicer_fb); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_bf); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_bc); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_sf); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_sc); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_if); +GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_ic); GR_SWIG_BLOCK_MAGIC2(digital, clock_recovery_mm_cc); GR_SWIG_BLOCK_MAGIC2(digital, clock_recovery_mm_ff); GR_SWIG_BLOCK_MAGIC2(digital, cma_equalizer_cc); GR_SWIG_BLOCK_MAGIC2(digital, constellation_receiver_cb); GR_SWIG_BLOCK_MAGIC2(digital, constellation_decoder_cb); +GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_bb); +GR_SWIG_BLOCK_MAGIC2(digital, correlate_access_code_tag_bb); +GR_SWIG_BLOCK_MAGIC2(digital, costas_loop_cc); GR_SWIG_BLOCK_MAGIC2(digital, diff_decoder_bb); GR_SWIG_BLOCK_MAGIC2(digital, diff_encoder_bb); GR_SWIG_BLOCK_MAGIC2(digital, diff_phasor_cc); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_bf); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_bc); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_sf); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_sc); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_if); -GR_SWIG_BLOCK_MAGIC2(digital, chunks_to_symbols_ic); -GR_SWIG_BLOCK_MAGIC2(digital, map_bb); GR_SWIG_BLOCK_MAGIC2(digital, fll_band_edge_cc); +GR_SWIG_BLOCK_MAGIC2(digital, glfsr_source_b); +GR_SWIG_BLOCK_MAGIC2(digital, glfsr_source_f); +GR_SWIG_BLOCK_MAGIC2(digital, map_bb); GR_SWIG_BLOCK_MAGIC2(digital, pfb_clock_sync_ccf); GR_SWIG_BLOCK_MAGIC2(digital, pfb_clock_sync_fff); +GR_SWIG_BLOCK_MAGIC2(digital, pn_correlator_cc); // Properly package up constellation objects %include "constellation.i" |