diff options
author | jcorgan | 2007-02-23 18:27:17 +0000 |
---|---|---|
committer | jcorgan | 2007-02-23 18:27:17 +0000 |
commit | a39870d9fc9c4c7b6b8f9ae5de3286c5362470f7 (patch) | |
tree | ac9f03f08947bd8eeceb3f8fd613954eac520a5e /gnuradio-core/src/lib/general | |
parent | 2a9030866bfe832e6d3593b6cef9495509aba8bc (diff) | |
download | gnuradio-a39870d9fc9c4c7b6b8f9ae5de3286c5362470f7.tar.gz gnuradio-a39870d9fc9c4c7b6b8f9ae5de3286c5362470f7.tar.bz2 gnuradio-a39870d9fc9c4c7b6b8f9ae5de3286c5362470f7.zip |
Merged r4605:4612 from jcorgan/glfsr branch into trunk. Implements Galois LFSR source block of degree 1 through 32.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4613 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r-- | gnuradio-core/src/lib/general/Makefile.am | 7 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_b.cc | 84 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_b.h | 65 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_glfsr_source_b.i | 37 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_glfsr.cc | 67 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gri_glfsr.h | 54 |
7 files changed, 315 insertions, 1 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 3014ee05b..d29259b4a 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2002,2004,2006 Free Software Foundation, Inc. +# Copyright 2001,2002,2004,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -76,6 +76,7 @@ libgeneral_la_SOURCES = \ gr_frequency_modulator_fc.cc \ gr_fxpt.cc \ gr_framer_sink_1.cc \ + gr_glfsr_source_b.cc \ gr_head.cc \ gr_interleave.cc \ gr_interleaved_short_to_complex.cc \ @@ -135,6 +136,7 @@ libgeneral_la_SOURCES = \ gri_float_to_char.cc \ gri_float_to_short.cc \ gri_float_to_uchar.cc \ + gri_glfsr.cc \ gri_interleaved_short_to_complex.cc \ gri_short_to_float.cc \ gri_uchar_to_float.cc \ @@ -196,6 +198,7 @@ grinclude_HEADERS = \ gr_fxpt.h \ gr_fxpt_nco.h \ gr_fxpt_vco.h \ + gr_glfsr_source_b.h \ gr_head.h \ gr_interleave.h \ gr_interleaved_short_to_complex.h \ @@ -264,6 +267,7 @@ grinclude_HEADERS = \ gri_float_to_char.h \ gri_float_to_short.h \ gri_float_to_uchar.h \ + gri_glfsr.h \ gri_interleaved_short_to_complex.h \ gri_lfsr_15_1_0.h \ gri_lfsr_32k.h \ @@ -323,6 +327,7 @@ swiginclude_HEADERS = \ gr_float_to_uchar.i \ gr_frequency_modulator_fc.i \ gr_framer_sink_1.i \ + gr_glfsr_source_b.i \ gr_head.i \ gr_interleave.i \ gr_interleaved_short_to_complex.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index fe3ccacdf..b659beb52 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -109,6 +109,7 @@ #include <gr_ctcss_squelch_ff.h> #include <gr_feedforward_agc_cc.h> #include <gr_bin_statistics_f.h> +#include <gr_glfsr_source_b.h> %} %include "gr_nop.i" @@ -198,3 +199,4 @@ %include "gr_ctcss_squelch_ff.i" %include "gr_feedforward_agc_cc.i" %include "gr_bin_statistics_f.i" +%include "gr_glfsr_source_b.i" diff --git a/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc b/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc new file mode 100644 index 000000000..312edb98d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_glfsr_source_b.cc @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gr_glfsr_source_b.h> +#include <gri_glfsr.h> +#include <gr_io_signature.h> +#include <stdexcept> + +gr_glfsr_source_b_sptr +gr_make_glfsr_source_b(int degree, bool repeat, int mask, int seed) +{ + return gr_glfsr_source_b_sptr(new gr_glfsr_source_b(degree, repeat, mask, seed)); +} + +gr_glfsr_source_b::gr_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("gr_glfsr_source_b: degree must be between 1 and 32 inclusive"); + d_length = (int)(1ULL << degree)-1; + + if (mask == 0) + mask = gri_glfsr::glfsr_mask(degree); + d_glfsr = new gri_glfsr(mask, seed); +} + +gr_glfsr_source_b::~gr_glfsr_source_b() +{ + delete d_glfsr; +} + +int +gr_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 +gr_glfsr_source_b::mask() const +{ + return d_glfsr->mask(); +} diff --git a/gnuradio-core/src/lib/general/gr_glfsr_source_b.h b/gnuradio-core/src/lib/general/gr_glfsr_source_b.h new file mode 100644 index 000000000..717a0e33b --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_glfsr_source_b.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_GLFSR_SOURCE_B_H +#define INCLUDED_GR_GLFSR_SOURCE_B_H + +#include <gr_sync_block.h> + +class gri_glfsr; + +class gr_glfsr_source_b; +typedef boost::shared_ptr<gr_glfsr_source_b> gr_glfsr_source_b_sptr; + +gr_glfsr_source_b_sptr gr_make_glfsr_source_b(int degree, bool repeat=true, int mask=0, int seed=1); + +/*! + * \brief Galois LFSR pseudo-random source + * \ingroup source + */ +class gr_glfsr_source_b : public gr_sync_block +{ + private: + friend gr_glfsr_source_b_sptr + gr_make_glfsr_source_b(int degree, bool repeat, int mask, int seed); + + gri_glfsr *d_glfsr; + + bool d_repeat; + unsigned int d_index; + unsigned int d_length; + + gr_glfsr_source_b(int degree, bool repeat, int mask, int seed); + + public: + + ~gr_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/gnuradio-core/src/lib/general/gr_glfsr_source_b.i b/gnuradio-core/src/lib/general/gr_glfsr_source_b.i new file mode 100644 index 000000000..328372600 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_glfsr_source_b.i @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,glfsr_source_b); + +gr_glfsr_source_b_sptr +gr_make_glfsr_source_b(int degree, bool repeat=true, int mask=0, int seed=1) + throw (std::runtime_error); + +class gr_glfsr_source_b : public gr_sync_block +{ +protected: + gr_glfsr_source_b(int degree, bool repeat, int mask, int seed); + +public: + unsigned int period() const; + int mask() const; +}; diff --git a/gnuradio-core/src/lib/general/gri_glfsr.cc b/gnuradio-core/src/lib/general/gri_glfsr.cc new file mode 100644 index 000000000..76ab2eb09 --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_glfsr.cc @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include <gri_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 gri_glfsr::glfsr_mask(int degree) +{ + if (degree < 1 || degree > 32) + throw std::runtime_error("gri_glfsr::glfsr_mask(): degree must be between 1 and 32 inclusive"); + return s_polynomial_masks[degree]; +} diff --git a/gnuradio-core/src/lib/general/gri_glfsr.h b/gnuradio-core/src/lib/general/gri_glfsr.h new file mode 100644 index 000000000..7fde99370 --- /dev/null +++ b/gnuradio-core/src/lib/general/gri_glfsr.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GRI_GLFSR_H +#define INCLUDED_GRI_GLFSR_H + +/*! + * \brief Galois Linear Feedback Shift Register using specified polynomial mask + * + * Generates a maximal length pseudo-random sequence of length 2^degree-1 + */ + +class gri_glfsr +{ + private: + int d_shift_register; + int d_mask; + + public: + + gri_glfsr(int mask, int seed) { d_shift_register = seed; d_mask = mask; } + 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; } +}; + +#endif /* INCLUDED_GRI_GLFSR_H */ |