summaryrefslogtreecommitdiff
path: root/gr-trellis/src
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/src')
-rw-r--r--gr-trellis/src/lib/Makefile.am2
-rw-r--r--gr-trellis/src/lib/interleaver.cc28
-rw-r--r--gr-trellis/src/lib/interleaver.h1
-rw-r--r--gr-trellis/src/lib/interleaver.i1
-rw-r--r--gr-trellis/src/lib/quicksort_index.cc57
-rw-r--r--gr-trellis/src/lib/quicksort_index.h31
-rw-r--r--gr-trellis/src/lib/trellis.i1
7 files changed, 121 insertions, 0 deletions
diff --git a/gr-trellis/src/lib/Makefile.am b/gr-trellis/src/lib/Makefile.am
index a6f3d030b..1b3e66461 100644
--- a/gr-trellis/src/lib/Makefile.am
+++ b/gr-trellis/src/lib/Makefile.am
@@ -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 \
diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc
index 12144bdc0..427db72e3 100644
--- a/gr-trellis/src/lib/interleaver.cc
+++ b/gr-trellis/src/lib/interleaver.cc
@@ -20,9 +20,11 @@
* Boston, MA 02111-1307, USA.
*/
+#include <cstdlib>
#include <cstdio>
#include <stdexcept>
#include <cmath>
+#include "quicksort_index.h"
#include "interleaver.h"
interleaver::interleaver()
@@ -78,3 +80,29 @@ interleaver::interleaver(const char *name)
d_DEINTER[d_INTER[i]]=i;
}
}
+
+//######################################################################
+//# Generate a random interleaver
+//######################################################################
+interleaver::interleaver(const int K, unsigned int seed)
+{
+ d_K=K;
+ d_INTER.resize(d_K);
+ d_DEINTER.resize(d_K);
+
+ std::runtime_error ("Not yet implemented: something wrong with quicksort\n");
+/*
+ srand(seed);
+ std::vector<int> tmp(d_K);
+ for(int i=0;i<d_K;i++)
+ //d_INTER[i]=i;
+ tmp[i] = rand();
+ quicksort_index <int> (tmp,d_INTER,0,d_K);
+
+ // 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
index 28d377860..13c316be2 100644
--- a/gr-trellis/src/lib/interleaver.h
+++ b/gr-trellis/src/lib/interleaver.h
@@ -38,6 +38,7 @@ public:
interleaver(const interleaver & INTERLEAVER);
interleaver(const int K, const std::vector<int> & INTER);
interleaver(const char *name);
+ interleaver(const int K, unsigned int seed);
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/interleaver.i b/gr-trellis/src/lib/interleaver.i
index 38b335cb3..6baec3bdc 100644
--- a/gr-trellis/src/lib/interleaver.i
+++ b/gr-trellis/src/lib/interleaver.i
@@ -30,6 +30,7 @@ public:
interleaver(const interleaver & INTERLEAVER);
interleaver(const int K, const std::vector<int> & INTER);
interleaver(const char *name);
+ interleaver(const int K, unsigned int seed);
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/quicksort_index.cc b/gr-trellis/src/lib/quicksort_index.cc
new file mode 100644
index 000000000..705aeebed
--- /dev/null
+++ b/gr-trellis/src/lib/quicksort_index.cc
@@ -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
index 000000000..9a0e65905
--- /dev/null
+++ b/gr-trellis/src/lib/quicksort_index.h
@@ -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
diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i
index bd3144119..2db07ed1d 100644
--- a/gr-trellis/src/lib/trellis.i
+++ b/gr-trellis/src/lib/trellis.i
@@ -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>