diff options
author | anastas | 2006-08-11 07:03:03 +0000 |
---|---|---|
committer | anastas | 2006-08-11 07:03:03 +0000 |
commit | ebd3845a6aac08b8b7058963e1d72c93d652f2f3 (patch) | |
tree | 7fa125ba4e26f558b5ce496a0ed986f97acaa7b2 | |
parent | 30f2121800afe283879a3369a7462d699a77af50 (diff) | |
download | gnuradio-ebd3845a6aac08b8b7058963e1d72c93d652f2f3.tar.gz gnuradio-ebd3845a6aac08b8b7058963e1d72c93d652f2f3.tar.bz2 gnuradio-ebd3845a6aac08b8b7058963e1d72c93d652f2f3.zip |
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
-rw-r--r-- | gr-trellis/src/lib/Makefile.am | 4 | ||||
-rw-r--r-- | gr-trellis/src/lib/interleaver.cc | 80 | ||||
-rw-r--r-- | gr-trellis/src/lib/interleaver.h | 46 | ||||
-rw-r--r-- | gr-trellis/src/lib/interleaver.i | 36 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis.i | 4 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_permutation.cc | 73 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_permutation.h | 60 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_permutation.i | 39 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_X.cc.t | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_b.cc | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_combined_b.cc | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_combined_i.cc | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_combined_s.cc | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_i.cc | 2 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_viterbi_s.cc | 2 |
16 files changed, 350 insertions, 8 deletions
diff --git a/gr-trellis/src/lib/Makefile.am b/gr-trellis/src/lib/Makefile.am index 52e677a10..a6f3d030b 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 000000000..12144bdc0 --- /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 <cstdio>
+#include <stdexcept>
+#include <cmath>
+#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<int> &INTER)
+{
+ d_K=K;
+ d_INTER=INTER;
+ d_DEINTER.resize(d_K);
+
+ // generate DEINTER table
+ for(int i=0;i<d_K;i++) {
+ d_DEINTER[d_INTER[i]]=i;
+ }
+}
+
+//######################################################################
+//# Read an INTERLEAVER specification from a file.
+//# Format (hopefully will become more flexible in the future...):
+//# K
+//# blank line
+//# list of space separated K integers from 0 to K-1 in appropriate order
+//# optional comments
+//######################################################################
+interleaver::interleaver(const char *name)
+{
+ FILE *interleaverfile;
+
+ if((interleaverfile=fopen(name,"r"))==NULL)
+ throw std::runtime_error ("file open error in interleaver()");
+ //printf("file open error in interleaver()\n");
+
+ fscanf(interleaverfile,"%d\n",&d_K);
+ d_INTER.resize(d_K);
+ d_DEINTER.resize(d_K);
+
+ for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
+
+ // generate DEINTER table
+ for(int i=0;i<d_K;i++) {
+ d_DEINTER[d_INTER[i]]=i;
+ }
+}
diff --git a/gr-trellis/src/lib/interleaver.h b/gr-trellis/src/lib/interleaver.h new file mode 100644 index 000000000..28d377860 --- /dev/null +++ b/gr-trellis/src/lib/interleaver.h @@ -0,0 +1,46 @@ +/* -*- 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.
+ */
+
+#ifndef INCLUDED_TRELLIS_INTERLEAVER_H
+#define INCLUDED_TRELLIS_INTERLEAVER_H
+
+#include <vector>
+
+/*!
+ * \brief INTERLEAVER class
+ */
+class interleaver {
+private:
+ int d_K;
+ std::vector<int> d_INTER;
+ std::vector<int> d_DEINTER;
+public:
+ interleaver();
+ interleaver(const interleaver & INTERLEAVER);
+ interleaver(const int K, const std::vector<int> & INTER);
+ interleaver(const char *name);
+ int K () const { return d_K; }
+ const std::vector<int> & INTER () const { return d_INTER; }
+ const std::vector<int> & 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 000000000..38b335cb3 --- /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<int> d_INTER;
+ std::vector<int> d_DEINTER;
+public:
+ interleaver();
+ interleaver(const interleaver & INTERLEAVER);
+ interleaver(const int K, const std::vector<int> & INTER);
+ interleaver(const char *name);
+ int K () const { return d_K; }
+ const std::vector<int> & INTER () const { return d_INTER; }
+ const std::vector<int> & DEINTER () const { return d_DEINTER; }
+};
diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i index 5dd781402..bd3144119 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 <stdexcept> %} // ---------------------------------------------------------------- %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 000000000..78bdbaf46 --- /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 <trellis_permutation.h> +#include <gr_io_signature.h> +#include <iostream> + +trellis_permutation_sptr +trellis_make_permutation (const int K, const std::vector<int> &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<int> &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<nstreams;m++) { + const char *in = (const char *) input_items[m]; + char *out = (char *) output_items[m]; + + // per stream processing + for (unsigned int i = 0; i < noutput_items; i++){ + //std::cout << i << " " << i*d_NBYTES << " " << (d_K*(i/d_K)+d_TABLE[i%d_K])*d_NBYTES << "\n"; + memcpy(&(out[i*d_NBYTES]), &(in[(d_K*(i/d_K)+d_TABLE[i%d_K])*d_NBYTES]), d_NBYTES); + } + // end per stream processing + } + return noutput_items; +} diff --git a/gr-trellis/src/lib/trellis_permutation.h b/gr-trellis/src/lib/trellis_permutation.h new file mode 100644 index 000000000..815ed3976 --- /dev/null +++ b/gr-trellis/src/lib/trellis_permutation.h @@ -0,0 +1,60 @@ +/* -*- 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. + */ + + +#ifndef INCLUDED_TRELLIS_PERMUTATION_H +#define INCLUDED_TRELLIS_PERMUTATION_H + +#include <vector> +#include <gr_sync_block.h> + +class trellis_permutation; +typedef boost::shared_ptr<trellis_permutation> trellis_permutation_sptr; + +trellis_permutation_sptr trellis_make_permutation (const int K, const std::vector<int> &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<int> &TABLE, const size_t NBYTES); + int d_K; + std::vector<int> d_TABLE; + size_t d_NBYTES; + trellis_permutation (const int K, const std::vector<int> &TABLE, const size_t NBYTES); + +public: + int K () const { return d_K; } + const std::vector<int> & 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 000000000..db74cdf05 --- /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<int> &TABLE, const size_t NBYTES); + +class trellis_permutation : public gr_sync_block +{ +private: + int d_K; + std::vector<int> d_TABLE; + size_t d_NBYTES; + trellis_permutation (const int K, const std::vector<int> &TABLE, const size_t NBYTES); + +public: + int K () const { return d_K; } + const std::vector<int> & 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 e8b9ee695..0ab423b0a 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<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_b.cc b/gr-trellis/src/lib/trellis_viterbi_b.cc index dbcd85bbd..2e005a316 100644 --- a/gr-trellis/src/lib/trellis_viterbi_b.cc +++ b/gr-trellis/src/lib/trellis_viterbi_b.cc @@ -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<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t b/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t index e62d90fea..52e01026b 100644 --- a/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t +++ b/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t @@ -136,7 +136,7 @@ void viterbi_algorithm_combined(const int I, const int S, const int O, minm=INF; minmi=0; for(int i=0;i<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_b.cc b/gr-trellis/src/lib/trellis_viterbi_combined_b.cc index ee4f5f8f8..8c72b2a3c 100644 --- a/gr-trellis/src/lib/trellis_viterbi_combined_b.cc +++ b/gr-trellis/src/lib/trellis_viterbi_combined_b.cc @@ -136,7 +136,7 @@ void viterbi_algorithm_combined(const int I, const int S, const int O, minm=INF; minmi=0; for(int i=0;i<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_i.cc b/gr-trellis/src/lib/trellis_viterbi_combined_i.cc index b415f064e..3301d0283 100644 --- a/gr-trellis/src/lib/trellis_viterbi_combined_i.cc +++ b/gr-trellis/src/lib/trellis_viterbi_combined_i.cc @@ -136,7 +136,7 @@ void viterbi_algorithm_combined(const int I, const int S, const int O, minm=INF; minmi=0; for(int i=0;i<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_s.cc b/gr-trellis/src/lib/trellis_viterbi_combined_s.cc index 6a7883420..46dda3d1d 100644 --- a/gr-trellis/src/lib/trellis_viterbi_combined_s.cc +++ b/gr-trellis/src/lib/trellis_viterbi_combined_s.cc @@ -136,7 +136,7 @@ void viterbi_algorithm_combined(const int I, const int S, const int O, minm=INF; minmi=0; for(int i=0;i<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_i.cc b/gr-trellis/src/lib/trellis_viterbi_i.cc index b5ae79d1f..58a39f6e5 100644 --- a/gr-trellis/src/lib/trellis_viterbi_i.cc +++ b/gr-trellis/src/lib/trellis_viterbi_i.cc @@ -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<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { diff --git a/gr-trellis/src/lib/trellis_viterbi_s.cc b/gr-trellis/src/lib/trellis_viterbi_s.cc index 6180dabc3..f5a0705c2 100644 --- a/gr-trellis/src/lib/trellis_viterbi_s.cc +++ b/gr-trellis/src/lib/trellis_viterbi_s.cc @@ -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<S;i++) - if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i; + if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i; st=minmi; } else { |