From ebd3845a6aac08b8b7058963e1d72c93d652f2f3 Mon Sep 17 00:00:00 2001 From: anastas Date: Fri, 11 Aug 2006 07:03:03 +0000 Subject: [PATCH] 1) Minor correction in Viterbi. 2) Checked in interleaver structure git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3232 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-trellis/src/lib/Makefile.am | 4 + gr-trellis/src/lib/interleaver.cc | 80 +++++++++++++++++++ gr-trellis/src/lib/interleaver.h | 46 +++++++++++ gr-trellis/src/lib/interleaver.i | 36 +++++++++ gr-trellis/src/lib/trellis.i | 4 + gr-trellis/src/lib/trellis_permutation.cc | 73 +++++++++++++++++ gr-trellis/src/lib/trellis_permutation.h | 60 ++++++++++++++ gr-trellis/src/lib/trellis_permutation.i | 39 +++++++++ gr-trellis/src/lib/trellis_viterbi_X.cc.t | 2 +- gr-trellis/src/lib/trellis_viterbi_b.cc | 2 +- .../src/lib/trellis_viterbi_combined_X.cc.t | 2 +- .../src/lib/trellis_viterbi_combined_b.cc | 2 +- .../src/lib/trellis_viterbi_combined_i.cc | 2 +- .../src/lib/trellis_viterbi_combined_s.cc | 2 +- gr-trellis/src/lib/trellis_viterbi_i.cc | 2 +- gr-trellis/src/lib/trellis_viterbi_s.cc | 2 +- 16 files changed, 350 insertions(+), 8 deletions(-) create mode 100644 gr-trellis/src/lib/interleaver.cc create mode 100644 gr-trellis/src/lib/interleaver.h create mode 100644 gr-trellis/src/lib/interleaver.i create mode 100644 gr-trellis/src/lib/trellis_permutation.cc create mode 100644 gr-trellis/src/lib/trellis_permutation.h create mode 100644 gr-trellis/src/lib/trellis_permutation.i diff --git a/gr-trellis/src/lib/Makefile.am b/gr-trellis/src/lib/Makefile.am index 52e677a1..a6f3d030 100644 --- a/gr-trellis/src/lib/Makefile.am +++ b/gr-trellis/src/lib/Makefile.am @@ -64,7 +64,9 @@ ourlib_LTLIBRARIES = _trellis.la _trellis_la_SOURCES = \ trellis.cc \ fsm.cc \ + interleaver.cc \ trellis_calc_metric.cc \ + trellis_permutation.cc \ $(GENERATED_CC) # magic flags @@ -83,8 +85,10 @@ trellis.cc trellis.py: trellis.i $(ALL_IFILES) # These headers get installed in ${prefix}/include/gnuradio grinclude_HEADERS = \ fsm.h \ + interleaver.h \ trellis_metric_type.h \ trellis_calc_metric.h \ + trellis_permutation.h \ $(GENERATED_H) diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc new file mode 100644 index 00000000..12144bdc --- /dev/null +++ b/gr-trellis/src/lib/interleaver.cc @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include "interleaver.h" + +interleaver::interleaver() +{ + d_K=0; + d_INTER.resize(0); + d_DEINTER.resize(0); +} + +interleaver::interleaver(const interleaver &INTERLEAVER) +{ + d_K=INTERLEAVER.K(); + d_INTER=INTERLEAVER.INTER(); + d_DEINTER=INTERLEAVER.DEINTER(); +} + +interleaver::interleaver(const int K, const std::vector &INTER) +{ + d_K=K; + d_INTER=INTER; + d_DEINTER.resize(d_K); + + // generate DEINTER table + for(int i=0;i + +/*! + * \brief INTERLEAVER class + */ +class interleaver { +private: + int d_K; + std::vector d_INTER; + std::vector d_DEINTER; +public: + interleaver(); + interleaver(const interleaver & INTERLEAVER); + interleaver(const int K, const std::vector & INTER); + interleaver(const char *name); + int K () const { return d_K; } + const std::vector & INTER () const { return d_INTER; } + const std::vector & DEINTER () const { return d_DEINTER; } +}; + +#endif diff --git a/gr-trellis/src/lib/interleaver.i b/gr-trellis/src/lib/interleaver.i new file mode 100644 index 00000000..38b335cb --- /dev/null +++ b/gr-trellis/src/lib/interleaver.i @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class interleaver { +private: + int d_K; + std::vector d_INTER; + std::vector d_DEINTER; +public: + interleaver(); + interleaver(const interleaver & INTERLEAVER); + interleaver(const int K, const std::vector & INTER); + interleaver(const char *name); + int K () const { return d_K; } + const std::vector & INTER () const { return d_INTER; } + const std::vector & DEINTER () const { return d_DEINTER; } +}; diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i index 5dd78140..bd314411 100644 --- a/gr-trellis/src/lib/trellis.i +++ b/gr-trellis/src/lib/trellis.i @@ -8,12 +8,16 @@ %{ #include "gnuradio_swig_bug_workaround.h" // mandatory bug fix #include "fsm.h" +#include "interleaver.h" +#include "trellis_permutation.h" #include %} // ---------------------------------------------------------------- %include "fsm.i" +%include "interleaver.i" +%include "trellis_permutation.i" %include "trellis_metric_type.h" diff --git a/gr-trellis/src/lib/trellis_permutation.cc b/gr-trellis/src/lib/trellis_permutation.cc new file mode 100644 index 00000000..78bdbaf4 --- /dev/null +++ b/gr-trellis/src/lib/trellis_permutation.cc @@ -0,0 +1,73 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +trellis_permutation_sptr +trellis_make_permutation (const int K, const std::vector &TABLE, const size_t NBYTES) +{ + return trellis_permutation_sptr (new trellis_permutation (K,TABLE,NBYTES)); +} + +trellis_permutation::trellis_permutation (const int K, const std::vector &TABLE, const size_t NBYTES) + : gr_sync_block ("permutation", + gr_make_io_signature (1, -1, NBYTES), + gr_make_io_signature (1, -1, NBYTES)), + d_K (K), + d_TABLE (TABLE), + d_NBYTES (NBYTES) +{ + set_output_multiple (d_K); + //std::cout << d_K << "\n"; +} + + + +int +trellis_permutation::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int nstreams = input_items.size(); + assert (input_items.size() == output_items.size()); + assert (noutput_items % d_K ==0); + //std::cout << noutput_items << "\n"; + + for (int m=0;m +#include + +class trellis_permutation; +typedef boost::shared_ptr trellis_permutation_sptr; + +trellis_permutation_sptr trellis_make_permutation (const int K, const std::vector &TABLE, const size_t NBYTES); + +/*! + * \brief Permutation. + * \ingroup block + * + * + */ +class trellis_permutation : public gr_sync_block +{ +private: + friend trellis_permutation_sptr trellis_make_permutation (const int K, const std::vector &TABLE, const size_t NBYTES); + int d_K; + std::vector d_TABLE; + size_t d_NBYTES; + trellis_permutation (const int K, const std::vector &TABLE, const size_t NBYTES); + +public: + int K () const { return d_K; } + const std::vector & TABLE () const { return d_TABLE; } + size_t NBYTES () const { return d_NBYTES; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gr-trellis/src/lib/trellis_permutation.i b/gr-trellis/src/lib/trellis_permutation.i new file mode 100644 index 00000000..db74cdf0 --- /dev/null +++ b/gr-trellis/src/lib/trellis_permutation.i @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +GR_SWIG_BLOCK_MAGIC(trellis,permutation); + +trellis_permutation_sptr trellis_make_permutation (const int K, const std::vector &TABLE, const size_t NBYTES); + +class trellis_permutation : public gr_sync_block +{ +private: + int d_K; + std::vector d_TABLE; + size_t d_NBYTES; + trellis_permutation (const int K, const std::vector &TABLE, const size_t NBYTES); + +public: + int K () const { return d_K; } + const std::vector & TABLE () const { return d_TABLE; } + size_t NBYTES () const { return d_NBYTES; } +}; diff --git a/gr-trellis/src/lib/trellis_viterbi_X.cc.t b/gr-trellis/src/lib/trellis_viterbi_X.cc.t index e8b9ee69..0ab423b0 100644 --- a/gr-trellis/src/lib/trellis_viterbi_X.cc.t +++ b/gr-trellis/src/lib/trellis_viterbi_X.cc.t @@ -123,7 +123,7 @@ void viterbi_algorithm(const int I, const int S, const int O, minm=INF; minmi=0; for(int i=0;i