1) Minor correction in Viterbi. 2) Checked in interleaver structure
authoranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 07:03:03 +0000 (07:03 +0000)
committeranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 07:03:03 +0000 (07:03 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3232 221aa14e-8319-0410-a670-987f0aec2ac5

16 files changed:
gr-trellis/src/lib/Makefile.am
gr-trellis/src/lib/interleaver.cc [new file with mode: 0644]
gr-trellis/src/lib/interleaver.h [new file with mode: 0644]
gr-trellis/src/lib/interleaver.i [new file with mode: 0644]
gr-trellis/src/lib/trellis.i
gr-trellis/src/lib/trellis_permutation.cc [new file with mode: 0644]
gr-trellis/src/lib/trellis_permutation.h [new file with mode: 0644]
gr-trellis/src/lib/trellis_permutation.i [new file with mode: 0644]
gr-trellis/src/lib/trellis_viterbi_X.cc.t
gr-trellis/src/lib/trellis_viterbi_b.cc
gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t
gr-trellis/src/lib/trellis_viterbi_combined_b.cc
gr-trellis/src/lib/trellis_viterbi_combined_i.cc
gr-trellis/src/lib/trellis_viterbi_combined_s.cc
gr-trellis/src/lib/trellis_viterbi_i.cc
gr-trellis/src/lib/trellis_viterbi_s.cc

index 52e677a10f0965d132a35c36ec8822e6a3f774db..a6f3d030b936e35aebafaaaf357213452c2cc32b 100644 (file)
@@ -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 (file)
index 0000000..12144bd
--- /dev/null
@@ -0,0 +1,80 @@
+/* -*- c++ -*- */\r
+/*\r
+ * Copyright 2002 Free Software Foundation, Inc.\r
+ *\r
+ * This file is part of GNU Radio\r
+ *\r
+ * GNU Radio is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2, or (at your option)\r
+ * any later version.\r
+ *\r
+ * GNU Radio is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with GNU Radio; see the file COPYING.  If not, write to\r
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
+ * Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#include <cstdio>\r
+#include <stdexcept>\r
+#include <cmath>\r
+#include "interleaver.h"\r
+\r
+interleaver::interleaver()\r
+{\r
+  d_K=0;\r
+  d_INTER.resize(0);\r
+  d_DEINTER.resize(0);\r
+}\r
+\r
+interleaver::interleaver(const interleaver &INTERLEAVER)\r
+{\r
+  d_K=INTERLEAVER.K();\r
+  d_INTER=INTERLEAVER.INTER();\r
+  d_DEINTER=INTERLEAVER.DEINTER();\r
+}\r
+\r
+interleaver::interleaver(const int K, const std::vector<int> &INTER)\r
+{\r
+  d_K=K;\r
+  d_INTER=INTER;\r
+  d_DEINTER.resize(d_K);\r
+  \r
+  // generate DEINTER table\r
+  for(int i=0;i<d_K;i++) {\r
+    d_DEINTER[d_INTER[i]]=i;\r
+  }\r
+}\r
+\r
+//######################################################################\r
+//# Read an INTERLEAVER specification from a file.\r
+//# Format (hopefully will become more flexible in the future...):\r
+//# K\r
+//# blank line\r
+//# list of space separated K integers from 0 to K-1 in appropriate order\r
+//# optional comments\r
+//######################################################################\r
+interleaver::interleaver(const char *name) \r
+{\r
+  FILE *interleaverfile;\r
+\r
+  if((interleaverfile=fopen(name,"r"))==NULL) \r
+    throw std::runtime_error ("file open error in interleaver()");\r
+    //printf("file open error in interleaver()\n");\r
+  \r
+  fscanf(interleaverfile,"%d\n",&d_K);\r
+  d_INTER.resize(d_K);\r
+  d_DEINTER.resize(d_K);\r
+\r
+  for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));\r
+  \r
+  // generate DEINTER table\r
+  for(int i=0;i<d_K;i++) {\r
+    d_DEINTER[d_INTER[i]]=i;\r
+  }\r
+}\r
diff --git a/gr-trellis/src/lib/interleaver.h b/gr-trellis/src/lib/interleaver.h
new file mode 100644 (file)
index 0000000..28d3778
--- /dev/null
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */\r
+/*\r
+ * Copyright 2002 Free Software Foundation, Inc.\r
+ *\r
+ * This file is part of GNU Radio\r
+ *\r
+ * GNU Radio is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2, or (at your option)\r
+ * any later version.\r
+ *\r
+ * GNU Radio is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with GNU Radio; see the file COPYING.  If not, write to\r
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
+ * Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifndef INCLUDED_TRELLIS_INTERLEAVER_H\r
+#define INCLUDED_TRELLIS_INTERLEAVER_H\r
+\r
+#include <vector>\r
+\r
+/*!\r
+ * \brief  INTERLEAVER class\r
+ */\r
+class interleaver {\r
+private:\r
+  int d_K;\r
+  std::vector<int> d_INTER;\r
+  std::vector<int> d_DEINTER;\r
+public:\r
+  interleaver();\r
+  interleaver(const interleaver & INTERLEAVER);\r
+  interleaver(const int K, const std::vector<int> & INTER);\r
+  interleaver(const char *name);\r
+  int K () const { return d_K; }\r
+  const std::vector<int> & INTER () const { return d_INTER; }\r
+  const std::vector<int> & DEINTER () const { return d_DEINTER; }\r
+};\r
+\r
+#endif\r
diff --git a/gr-trellis/src/lib/interleaver.i b/gr-trellis/src/lib/interleaver.i
new file mode 100644 (file)
index 0000000..38b335c
--- /dev/null
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */\r
+/*\r
+ * Copyright 2002 Free Software Foundation, Inc.\r
+ *\r
+ * This file is part of GNU Radio\r
+ *\r
+ * GNU Radio is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2, or (at your option)\r
+ * any later version.\r
+ *\r
+ * GNU Radio is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with GNU Radio; see the file COPYING.  If not, write to\r
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
+ * Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+class interleaver {\r
+private:\r
+  int d_K;\r
+  std::vector<int> d_INTER;\r
+  std::vector<int> d_DEINTER;\r
+public:\r
+  interleaver();\r
+  interleaver(const interleaver & INTERLEAVER);\r
+  interleaver(const int K, const std::vector<int> & INTER);\r
+  interleaver(const char *name);\r
+  int K () const { return d_K; }\r
+  const std::vector<int> & INTER () const { return d_INTER; }\r
+  const std::vector<int> & DEINTER () const { return d_DEINTER; }\r
+};\r
index 5dd781402d9cf905de42c352dd7198b10f7cd516..bd3144119b6c02d8c0449a1b6d0360238947e483 100644 (file)
@@ -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 (file)
index 0000000..78bdbaf
--- /dev/null
@@ -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 (file)
index 0000000..815ed39
--- /dev/null
@@ -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 (file)
index 0000000..db74cdf
--- /dev/null
@@ -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; }
+};
index e8b9ee69585c2073e95593bbf2a28ddae1bbc06a..0ab423b0ae2a44b775ff107325972f033eb0071b 100644 (file)
@@ -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 {
index dbcd85bbd0897b8c3017ae2f4c1df2a69cd9f98e..2e005a316f5b3d4f2322b4f7265c6d8b924262ef 100644 (file)
@@ -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 {
index e62d90feaab422982ad540bef6dfb845efc0122d..52e01026bea8af3043c05d6e0520be7f84ba0cb2 100644 (file)
@@ -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 {
index ee4f5f8f847c5a65cbab261a00fd6251ed166edb..8c72b2a3c969f48061bfe3c44c8b778eb832339a 100644 (file)
@@ -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 {
index b415f064e24cd93d0508344b3ece6ed80c16d6ed..3301d028393614f3dba5d74d53068069d4a4ef44 100644 (file)
@@ -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 {
index 6a788342083ea419db1f6f6ccf8b0cfa182cb3bf..46dda3d1d1924535e6da12a449eed357c5a9e536 100644 (file)
@@ -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 {
index b5ae79d1f2d930e0146992a33429030302d057d5..58a39f6e5d60a78ed632dfa0cafc638335e38d43 100644 (file)
@@ -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 {
index 6180dabc3e7a3ddd3f05ad432402e8548d135b4f..f5a0705c2af67e22e9a6dc718761fdea45852b26 100644 (file)
@@ -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 {