Additional constructor for random interleaver (not working yet)
authoranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 08:33:17 +0000 (08:33 +0000)
committeranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 08:33:17 +0000 (08:33 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3233 221aa14e-8319-0410-a670-987f0aec2ac5

gr-trellis/src/lib/Makefile.am
gr-trellis/src/lib/interleaver.cc
gr-trellis/src/lib/interleaver.h
gr-trellis/src/lib/interleaver.i
gr-trellis/src/lib/quicksort_index.cc [new file with mode: 0644]
gr-trellis/src/lib/quicksort_index.h [new file with mode: 0644]
gr-trellis/src/lib/trellis.i

index a6f3d030b936e35aebafaaaf357213452c2cc32b..1b3e66461b4a8a1fa00ac580ab330bb9116472ec 100644 (file)
@@ -64,6 +64,7 @@ ourlib_LTLIBRARIES = _trellis.la
 _trellis_la_SOURCES =                  \
        trellis.cc                      \
         fsm.cc                         \
+        quicksort_index.cc             \
         interleaver.cc                 \
         trellis_calc_metric.cc         \
         trellis_permutation.cc         \
@@ -85,6 +86,7 @@ trellis.cc trellis.py: trellis.i $(ALL_IFILES)
 # These headers get installed in ${prefix}/include/gnuradio
 grinclude_HEADERS =                    \
         fsm.h                          \
+        quicksort_index.h              \
         interleaver.h                  \
         trellis_metric_type.h          \
         trellis_calc_metric.h          \
index 12144bdc0e2105b202a5f4db9784a1e92ce34cda..427db72e3197143556573a6768fe45fd215146ae 100644 (file)
  * Boston, MA 02111-1307, USA.\r
  */\r
 \r
+#include <cstdlib> \r
 #include <cstdio>\r
 #include <stdexcept>\r
 #include <cmath>\r
+#include "quicksort_index.h"\r
 #include "interleaver.h"\r
 \r
 interleaver::interleaver()\r
@@ -78,3 +80,29 @@ interleaver::interleaver(const char *name)
     d_DEINTER[d_INTER[i]]=i;\r
   }\r
 }\r
+\r
+//######################################################################\r
+//# Generate a random interleaver\r
+//######################################################################\r
+interleaver::interleaver(const int K, unsigned int seed)\r
+{\r
+  d_K=K;\r
+  d_INTER.resize(d_K);\r
+  d_DEINTER.resize(d_K);\r
+\r
+  std::runtime_error ("Not yet implemented: something wrong with quicksort\n");\r
+/*\r
+  srand(seed); \r
+  std::vector<int> tmp(d_K);\r
+  for(int i=0;i<d_K;i++)\r
+    //d_INTER[i]=i;\r
+    tmp[i] = rand(); \r
+  quicksort_index <int> (tmp,d_INTER,0,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
index 28d3778601109fb7b4bd99a42e5fbdd7ad9e3293..13c316be2daf7d159615b2663b255753247df966 100644 (file)
@@ -38,6 +38,7 @@ public:
   interleaver(const interleaver & INTERLEAVER);\r
   interleaver(const int K, const std::vector<int> & INTER);\r
   interleaver(const char *name);\r
+  interleaver(const int K, unsigned int seed);\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
index 38b335cb3e1acb7d111bf2697c8ca141a25297cf..6baec3bdc8753274c45f98d8adb35866d9bf87ea 100644 (file)
@@ -30,6 +30,7 @@ public:
   interleaver(const interleaver & INTERLEAVER);\r
   interleaver(const int K, const std::vector<int> & INTER);\r
   interleaver(const char *name);\r
+  interleaver(const int K, unsigned int seed);\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
diff --git a/gr-trellis/src/lib/quicksort_index.cc b/gr-trellis/src/lib/quicksort_index.cc
new file mode 100644 (file)
index 0000000..705aeeb
--- /dev/null
@@ -0,0 +1,57 @@
+/* -*- 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.
+ */
+
+#include "quicksort_index.h"
+
+template <class T> void SWAP (T & a, T & b)
+{
+T temp=a;
+a=b;
+b=temp;
+}
+
+template <class T> void quicksort_index(std::vector<T> & p, std::vector<int> & index, int left, int right)
+{
+T pivot;
+
+if (left < right) {
+    int i = left;
+    int j = right + 1;
+    pivot = p[left];
+    do {
+        do 
+            i++;
+        while ((p[i] < pivot) && (i < right));
+        do 
+            j--;
+        while ((p[j] > pivot) && (j > left));
+        if (i < j) {
+            SWAP <T> (p[i],p[j]);
+            SWAP <int> (index[i],index[j]);
+        }
+    } while (i < j);
+    SWAP <T> (p[left], p[j]);
+    SWAP <int> (index[left], index[j]);
+    quicksort_index(p,index, left, j-1);
+    quicksort_index(p,index, j+1, right);
+}
+}
diff --git a/gr-trellis/src/lib/quicksort_index.h b/gr-trellis/src/lib/quicksort_index.h
new file mode 100644 (file)
index 0000000..9a0e659
--- /dev/null
@@ -0,0 +1,31 @@
+/* -*- 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_QUICKSORT_INDEX_H
+#define INCLUDED_QUICKSORT_INDEX_H
+
+#include <vector>
+
+template <class T> void SWAP (T & a, T & b);
+template <class T> void quicksort_index(std::vector<T> & p, std::vector<int> & index, int left, int right);
+
+#endif
index bd3144119b6c02d8c0449a1b6d0360238947e483..2db07ed1d39a79b142dcbef0c6155d983b6d3df3 100644 (file)
@@ -8,6 +8,7 @@
 %{
 #include "gnuradio_swig_bug_workaround.h"      // mandatory bug fix
 #include "fsm.h"
+#include "quicksort_index.h"
 #include "interleaver.h"
 #include "trellis_permutation.h"
 #include <stdexcept>