From 954e2976e43507479e0bc5d1526e555627117125 Mon Sep 17 00:00:00 2001 From: anastas Date: Fri, 11 Aug 2006 08:33:17 +0000 Subject: Additional constructor for random interleaver (not working yet) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3233 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-trellis/src/lib/Makefile.am | 2 ++ gr-trellis/src/lib/interleaver.cc | 28 +++++++++++++++++ gr-trellis/src/lib/interleaver.h | 1 + gr-trellis/src/lib/interleaver.i | 1 + gr-trellis/src/lib/quicksort_index.cc | 57 +++++++++++++++++++++++++++++++++++ gr-trellis/src/lib/quicksort_index.h | 31 +++++++++++++++++++ gr-trellis/src/lib/trellis.i | 1 + 7 files changed, 121 insertions(+) create mode 100644 gr-trellis/src/lib/quicksort_index.cc create mode 100644 gr-trellis/src/lib/quicksort_index.h (limited to 'gr-trellis/src') 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 #include #include #include +#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 tmp(d_K); + for(int i=0;i (tmp,d_INTER,0,d_K); + + // generate DEINTER table + for(int i=0;i & INTER); interleaver(const char *name); + interleaver(const int K, unsigned int seed); 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/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 & INTER); interleaver(const char *name); + interleaver(const int K, unsigned int seed); 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/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 void SWAP (T & a, T & b) +{ +T temp=a; +a=b; +b=temp; +} + +template void quicksort_index(std::vector & p, std::vector & 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 (p[i],p[j]); + SWAP (index[i],index[j]); + } + } while (i < j); + SWAP (p[left], p[j]); + SWAP (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 + +template void SWAP (T & a, T & b); +template void quicksort_index(std::vector & p, std::vector & 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 -- cgit