Added support for concatenated codes
authoranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 10:27:46 +0000 (10:27 +0000)
committeranastas <anastas@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Aug 2006 10:27:46 +0000 (10:27 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3234 221aa14e-8319-0410-a670-987f0aec2ac5

22 files changed:
gr-trellis/doc/gr-trellis.html
gr-trellis/src/lib/Makefile.gen
gr-trellis/src/lib/generate_common.py
gr-trellis/src/lib/interleaver.cc
gr-trellis/src/lib/quicksort_index.cc
gr-trellis/src/lib/quicksort_index.h
gr-trellis/src/lib/trellis.i
gr-trellis/src/lib/trellis_calc_metric.cc
gr-trellis/src/lib/trellis_calc_metric.h
gr-trellis/src/lib/trellis_generated.i
gr-trellis/src/lib/trellis_metrics_X.cc.t
gr-trellis/src/lib/trellis_metrics_c.cc
gr-trellis/src/lib/trellis_metrics_f.cc
gr-trellis/src/lib/trellis_metrics_i.cc [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_i.h [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_i.i [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_i.lo [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_s.cc [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_s.h [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_s.i [new file with mode: 0644]
gr-trellis/src/lib/trellis_metrics_s.lo [new file with mode: 0644]
gr-trellis/src/python/qa_trellis.py

index 4c0173c2c7748211043dc0299519786ffe802827..82d923753ee15426a7265ebf0681e3187d3d5750 100644 (file)
@@ -2,7 +2,7 @@
 Finite State Machine (FSM) implementation and the related 
 trellis-based encoding and decoding algorithms
 for GNU Radio.
-"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2606540"></a>Trellis-based algorithms for GNU Radio</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Achilleas</span> <span class="surname">Anastasopoulos</span></h3><div class="affiliation"><div class="address"><p><br>
+"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id2753996"></a>Trellis-based algorithms for GNU Radio</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Achilleas</span> <span class="surname">Anastasopoulos</span></h3><div class="affiliation"><div class="address"><p><br>
            <tt class="email">&lt;<a href="mailto:anastas@umich.edu">anastas@umich.edu</a>&gt;</tt><br>
         </p></div></div></div></div><div><div class="revhistory"><table border="1" width="100%" summary="Revision history"><tr><th align="left" valign="top" colspan="2"><b>Revision History</b></th></tr><tr><td align="left">Revision v0.0</td><td align="left">2006-08-03</td></tr><tr><td align="left" colspan="2">
     First cut.
index 9c0ddf9ea704f0b4608d9ebe84f8c341b516328d..7a47ea3a75dd026784a2ca720ec0668f55ee581a 100644 (file)
@@ -10,6 +10,8 @@ GENERATED_H = \
        trellis_encoder_ss.h \
        trellis_metrics_c.h \
        trellis_metrics_f.h \
+       trellis_metrics_i.h \
+       trellis_metrics_s.h \
        trellis_viterbi_b.h \
        trellis_viterbi_combined_b.h \
        trellis_viterbi_combined_i.h \
@@ -26,6 +28,8 @@ GENERATED_I = \
        trellis_encoder_ss.i \
        trellis_metrics_c.i \
        trellis_metrics_f.i \
+       trellis_metrics_i.i \
+       trellis_metrics_s.i \
        trellis_viterbi_b.i \
        trellis_viterbi_combined_b.i \
        trellis_viterbi_combined_i.i \
@@ -42,6 +46,8 @@ GENERATED_CC = \
        trellis_encoder_ss.cc \
        trellis_metrics_c.cc \
        trellis_metrics_f.cc \
+       trellis_metrics_i.cc \
+       trellis_metrics_s.cc \
        trellis_viterbi_b.cc \
        trellis_viterbi_combined_b.cc \
        trellis_viterbi_combined_i.cc \
index c7bb6c865a5b2bb2b7a203fad9078c285266f5d7..ee744b8e1444e9ba04a63e0acc9d3550ce80ffdd 100644 (file)
@@ -35,7 +35,7 @@ other_roots = [
     ]
 other_signatures = (
     ['bb','bs','bi','ss','si','ii'],
-    ['f','c'],
+    ['s','i','f','c'],
     ['b','s','i'],
     ['b','s','i'],
     )
index 427db72e3197143556573a6768fe45fd215146ae..042dc04bac04000446988c540cb4fe5c8871ba76 100644 (file)
@@ -22,6 +22,7 @@
 \r
 #include <cstdlib> \r
 #include <cstdio>\r
+#include <iostream>\r
 #include <stdexcept>\r
 #include <cmath>\r
 #include "quicksort_index.h"\r
@@ -90,19 +91,18 @@ interleaver::interleaver(const int K, unsigned int seed)
   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
+  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
+  //quicksort_index <int> (tmp,d_INTER,0,d_K-1); got to resolve this...\r
+  quicksort_index1 (tmp,d_INTER,0,d_K-1);\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 705aeebed5d18063c04255c7dacc02f62608aee0..0ab63ebbe6644779e96a8e87533119b86e24f45d 100644 (file)
@@ -29,14 +29,14 @@ 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];
+    pivot = p[left];
     do {
         do 
             i++;
@@ -51,7 +51,36 @@ if (left < right) {
     } 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);
+    quicksort_index <T> (p,index, left, j-1);
+    quicksort_index <T> (p,index, j+1, right);
+}
+}
+
+
+
+void quicksort_index1(std::vector<int> & p, std::vector<int> & index, int left, int right)
+{
+
+if (left < right) {
+    int i = left;
+    int j = right + 1;
+    int pivot = p[left];
+    do {
+        do
+            i++;
+        while ((p[i] < pivot) && (i < right));
+        do
+            j--;
+        while ((p[j] > pivot) && (j > left));
+        if (i < j) {
+            SWAP <int> (p[i],p[j]);
+            SWAP <int> (index[i],index[j]);
+        }
+    } while (i < j);
+    SWAP <int> (p[left], p[j]);
+    SWAP <int> (index[left], index[j]);
+    quicksort_index1 (p,index, left, j-1);
+    quicksort_index1 (p,index, j+1, right);
 }
 }
+
index 9a0e659058fc080669492c24591ba1667d740e69..10d36f6193d9598456e180391ee1c00b443d7080 100644 (file)
@@ -27,5 +27,6 @@
 
 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);
+void quicksort_index1(std::vector<int> & p, std::vector<int> & index, int left, int right);
 
 #endif
index 2db07ed1d39a79b142dcbef0c6155d983b6d3df3..bd3144119b6c02d8c0449a1b6d0360238947e483 100644 (file)
@@ -8,7 +8,6 @@
 %{
 #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>
index c6d2ce98cb8435f50b48c0e5f1f09a0fafa52f0e..ae25a67bad4bd2a2b215ae65cd40dc76fdb6bea6 100644 (file)
 #include <stdexcept>
 #include "trellis_calc_metric.h"
 
-// soft decisions (Eucledean distance squared)
+// soft decisions (Euclidean distance squared)
+void calc_metric_s(const int O, const int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
+{
+  float minm = FLT_MAX;
+  int minmi = 0;
+
+  switch (type){
+  case TRELLIS_EUCLIDEAN:
+    for(int o=0;o<O;o++) {
+       metric[o]=0.0;
+       for (int m=0;m<D;m++) {
+           float s=in[m]-TABLE[o*D+m];
+           metric[o]+=s*s;
+       }
+    }
+    break;
+  case TRELLIS_HARD_SYMBOL:
+    for(int o=0;o<O;o++) {
+       metric[o]=0.0;
+       for (int m=0;m<D;m++) {
+           float s=in[m]-TABLE[o*D+m];
+           metric[o]+=s*s;
+       }
+       if(metric[o]<minm) {
+         minm=metric[o];
+         minmi=o;
+       }
+    }
+    for(int o=0;o<O;o++) {
+      metric[o] = (o==minmi?0.0:1.0);
+    }
+    break;
+  case TRELLIS_HARD_BIT:
+    throw std::runtime_error ("Invalid metric type (not yet implemented).");
+    break;
+  default:
+    throw std::runtime_error ("Invalid metric type.");
+  }
+}
+
+
+
+// soft decisions (Euclidean distance squared)
+void calc_metric_i(const int O, const int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
+{
+  float minm = FLT_MAX;
+  int minmi = 0;
+
+  switch (type){
+  case TRELLIS_EUCLIDEAN:
+    for(int o=0;o<O;o++) {
+       metric[o]=0.0;
+       for (int m=0;m<D;m++) {
+           float s=in[m]-TABLE[o*D+m];
+           metric[o]+=s*s;
+       }
+    }
+    break;
+  case TRELLIS_HARD_SYMBOL:
+    for(int o=0;o<O;o++) {
+       metric[o]=0.0;
+       for (int m=0;m<D;m++) {
+           float s=in[m]-TABLE[o*D+m];
+           metric[o]+=s*s;
+       }
+       if(metric[o]<minm) {
+         minm=metric[o];
+         minmi=o;
+       }
+    }
+    for(int o=0;o<O;o++) {
+      metric[o] = (o==minmi?0.0:1.0);
+    }
+    break;
+  case TRELLIS_HARD_BIT:
+    throw std::runtime_error ("Invalid metric type (not yet implemented).");
+    break;
+  default:
+    throw std::runtime_error ("Invalid metric type.");
+  }
+}
+
+
+
+
+
+
+
+// soft decisions (Euclidean distance squared)
 void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
 {
   float minm = FLT_MAX;
@@ -65,7 +153,7 @@ void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, co
 }
 
 
-// soft decisions (Eucledean distance squared)
+// soft decisions (Euclidean distance squared)
 void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
 {
   float minm = FLT_MAX;
index 5375070f868681e45ba7d25519e701a4e5a65649..1e180532227a8620ffd731b06869e9d2f1e7b817 100644 (file)
 #include <gr_complex.h>
 #include <trellis_metric_type.h>
 
+void calc_metric_s(const int O, const int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type);
+
+void calc_metric_i(const int O, const int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type);
+
 void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type);
 
 void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type);
index c76e79c5c1279a73502f92bba0d53a11b4eb79b4..464ffacb3cceecf662b3efe226eeaf6177b9a5ae 100644 (file)
@@ -10,6 +10,8 @@
 #include <trellis_encoder_ss.h>
 #include <trellis_metrics_c.h>
 #include <trellis_metrics_f.h>
+#include <trellis_metrics_i.h>
+#include <trellis_metrics_s.h>
 #include <trellis_viterbi_b.h>
 #include <trellis_viterbi_combined_b.h>
 #include <trellis_viterbi_combined_i.h>
@@ -26,6 +28,8 @@
 %include <trellis_encoder_ss.i>
 %include <trellis_metrics_c.i>
 %include <trellis_metrics_f.i>
+%include <trellis_metrics_i.i>
+%include <trellis_metrics_s.i>
 %include <trellis_viterbi_b.i>
 %include <trellis_viterbi_combined_b.i>
 %include <trellis_viterbi_combined_i.i>
index d5347e12d33bf1e4e177a51ca7e2e375601e140c..2dd1adb12d658c3b3c5d534ce8f14cda83355565 100644 (file)
@@ -83,7 +83,11 @@ for (int m=0;m<nstreams;m++) {
   float *out = (float *) output_items[m];
 
   for (int i = 0; i < noutput_items / d_O ; i++){
-#if @IS_FLOAT@
+#if @IS_SHORT@
+    calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif @IS_INT@
+    calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif @IS_FLOAT@
     calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
 #elif @IS_COMPLEX@
     calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
index 1ff5f4540403cc76f44a4cc44a81b9dd95583071..ea1808e831908fd335292b0a7c9bf89401e2b471 100644 (file)
@@ -84,6 +84,10 @@ for (int m=0;m<nstreams;m++) {
 
   for (int i = 0; i < noutput_items / d_O ; i++){
 #if 0
+    calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
     calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
 #elif 1
     calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
index 472ec594215ec9d8ca2186c034a9b97ad04f341c..2e148bbd550f2822a094ded4932d9a69781b8c7b 100644 (file)
@@ -83,7 +83,11 @@ for (int m=0;m<nstreams;m++) {
   float *out = (float *) output_items[m];
 
   for (int i = 0; i < noutput_items / d_O ; i++){
-#if 1
+#if 0
+    calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 1
     calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
 #elif 0
     calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
diff --git a/gr-trellis/src/lib/trellis_metrics_i.cc b/gr-trellis/src/lib/trellis_metrics_i.cc
new file mode 100644 (file)
index 0000000..5901c55
--- /dev/null
@@ -0,0 +1,100 @@
+/* -*- 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 HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_metrics_i.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+trellis_metrics_i_sptr
+trellis_make_metrics_i (const int O, const int D,  const std::vector<int> &TABLE, trellis_metric_type_t TYPE)
+{
+  return trellis_metrics_i_sptr (new trellis_metrics_i (O,D,TABLE,TYPE));
+}
+
+
+
+trellis_metrics_i::trellis_metrics_i (const int O, const int D,  const std::vector<int> &TABLE, trellis_metric_type_t TYPE)
+  : gr_block ("metrics_i",
+             gr_make_io_signature (1, -1, sizeof (int)),
+             gr_make_io_signature (1, -1, sizeof (float))),
+    d_O (O),
+    d_D (D),
+    d_TYPE (TYPE),
+    d_TABLE (TABLE)
+{
+  set_relative_rate (1.0 * d_O / ((double) d_D));
+  set_output_multiple ((int)d_O);
+}
+
+
+
+
+void
+trellis_metrics_i::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+  assert (noutput_items % d_O == 0);
+  int input_required =  d_D * noutput_items / d_O;
+  unsigned ninputs = ninput_items_required.size();
+  for (unsigned int i = 0; i < ninputs; i++)
+    ninput_items_required[i] = input_required;
+}
+
+
+
+int
+trellis_metrics_i::general_work (int noutput_items,
+                               gr_vector_int &ninput_items,
+                               gr_vector_const_void_star &input_items,
+                               gr_vector_void_star &output_items)
+{
+
+  assert (noutput_items % d_O == 0);
+  assert (input_items.size() == output_items.size());
+  int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+  const int *in = (int *) input_items[m];
+  float *out = (float *) output_items[m];
+
+  for (int i = 0; i < noutput_items / d_O ; i++){
+#if 0
+    calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 1
+    calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#endif
+  } 
+}
+
+  consume_each (d_D * noutput_items / d_O);
+  return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_metrics_i.h b/gr-trellis/src/lib/trellis_metrics_i.h
new file mode 100644 (file)
index 0000000..c51e377
--- /dev/null
@@ -0,0 +1,65 @@
+/* -*- 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.
+ */
+
+// WARNING: this file is machine generated.  Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_METRICS_I_H
+#define INCLUDED_TRELLIS_METRICS_I_H
+
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_metrics_i;
+typedef boost::shared_ptr<trellis_metrics_i> trellis_metrics_i_sptr;
+
+trellis_metrics_i_sptr trellis_make_metrics_i (const int O, const int D,  const std::vector<int> &TABLE, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup block
+ *
+ */
+class trellis_metrics_i : public gr_block
+{
+  int d_O;
+  int d_D;
+  trellis_metric_type_t d_TYPE;
+  std::vector<int> d_TABLE;
+
+  friend trellis_metrics_i_sptr trellis_make_metrics_i (const int O, const int D,  const std::vector<int> &TABLE, trellis_metric_type_t TYPE);
+  trellis_metrics_i (const int O, const int D,  const std::vector<int> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+  int O () const { return d_O; }
+  int D () const { return d_D; }
+  trellis_metric_type_t TYPE () const { return d_TYPE; }
+  std::vector<int> TABLE () const { return d_TABLE; }
+  void forecast (int noutput_items,
+                gr_vector_int &ninput_items_required);
+  int general_work (int noutput_items,
+                   gr_vector_int &ninput_items,
+                   gr_vector_const_void_star &input_items,
+                   gr_vector_void_star &output_items);
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_metrics_i.i b/gr-trellis/src/lib/trellis_metrics_i.i
new file mode 100644 (file)
index 0000000..dadd065
--- /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.
+ */
+
+// WARNING: this file is machine generated.  Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,metrics_i);
+
+trellis_metrics_i_sptr trellis_make_metrics_i (const int O, const int D, const std::vector<int> &TABLE, trellis_metric_type_t TYPE);
+
+class trellis_metrics_i : public gr_block
+{
+private:
+  trellis_metrics_i (const int O, const int D, const std::vector<int> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+  int O () const { return d_O; }
+  int D () const { return d_D; }
+  trellis_metric_type_t TYPE () const { return d_TYPE; }
+  std::vector<int> TABLE () const { return d_TABLE; }
+};
diff --git a/gr-trellis/src/lib/trellis_metrics_i.lo b/gr-trellis/src/lib/trellis_metrics_i.lo
new file mode 100644 (file)
index 0000000..ce7227b
--- /dev/null
@@ -0,0 +1,12 @@
+# trellis_metrics_i.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object='.libs/trellis_metrics_i.o'
+
+# Name of the non-PIC object.
+non_pic_object=none
+
diff --git a/gr-trellis/src/lib/trellis_metrics_s.cc b/gr-trellis/src/lib/trellis_metrics_s.cc
new file mode 100644 (file)
index 0000000..3bee2cc
--- /dev/null
@@ -0,0 +1,100 @@
+/* -*- 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 HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_metrics_s.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+trellis_metrics_s_sptr
+trellis_make_metrics_s (const int O, const int D,  const std::vector<short> &TABLE, trellis_metric_type_t TYPE)
+{
+  return trellis_metrics_s_sptr (new trellis_metrics_s (O,D,TABLE,TYPE));
+}
+
+
+
+trellis_metrics_s::trellis_metrics_s (const int O, const int D,  const std::vector<short> &TABLE, trellis_metric_type_t TYPE)
+  : gr_block ("metrics_s",
+             gr_make_io_signature (1, -1, sizeof (short)),
+             gr_make_io_signature (1, -1, sizeof (float))),
+    d_O (O),
+    d_D (D),
+    d_TYPE (TYPE),
+    d_TABLE (TABLE)
+{
+  set_relative_rate (1.0 * d_O / ((double) d_D));
+  set_output_multiple ((int)d_O);
+}
+
+
+
+
+void
+trellis_metrics_s::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+  assert (noutput_items % d_O == 0);
+  int input_required =  d_D * noutput_items / d_O;
+  unsigned ninputs = ninput_items_required.size();
+  for (unsigned int i = 0; i < ninputs; i++)
+    ninput_items_required[i] = input_required;
+}
+
+
+
+int
+trellis_metrics_s::general_work (int noutput_items,
+                               gr_vector_int &ninput_items,
+                               gr_vector_const_void_star &input_items,
+                               gr_vector_void_star &output_items)
+{
+
+  assert (noutput_items % d_O == 0);
+  assert (input_items.size() == output_items.size());
+  int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+  const short *in = (short *) input_items[m];
+  float *out = (float *) output_items[m];
+
+  for (int i = 0; i < noutput_items / d_O ; i++){
+#if 1
+    calc_metric_s(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_i(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+    calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#endif
+  } 
+}
+
+  consume_each (d_D * noutput_items / d_O);
+  return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_metrics_s.h b/gr-trellis/src/lib/trellis_metrics_s.h
new file mode 100644 (file)
index 0000000..b4332bc
--- /dev/null
@@ -0,0 +1,65 @@
+/* -*- 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.
+ */
+
+// WARNING: this file is machine generated.  Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_METRICS_S_H
+#define INCLUDED_TRELLIS_METRICS_S_H
+
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_metrics_s;
+typedef boost::shared_ptr<trellis_metrics_s> trellis_metrics_s_sptr;
+
+trellis_metrics_s_sptr trellis_make_metrics_s (const int O, const int D,  const std::vector<short> &TABLE, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup block
+ *
+ */
+class trellis_metrics_s : public gr_block
+{
+  int d_O;
+  int d_D;
+  trellis_metric_type_t d_TYPE;
+  std::vector<short> d_TABLE;
+
+  friend trellis_metrics_s_sptr trellis_make_metrics_s (const int O, const int D,  const std::vector<short> &TABLE, trellis_metric_type_t TYPE);
+  trellis_metrics_s (const int O, const int D,  const std::vector<short> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+  int O () const { return d_O; }
+  int D () const { return d_D; }
+  trellis_metric_type_t TYPE () const { return d_TYPE; }
+  std::vector<short> TABLE () const { return d_TABLE; }
+  void forecast (int noutput_items,
+                gr_vector_int &ninput_items_required);
+  int general_work (int noutput_items,
+                   gr_vector_int &ninput_items,
+                   gr_vector_const_void_star &input_items,
+                   gr_vector_void_star &output_items);
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_metrics_s.i b/gr-trellis/src/lib/trellis_metrics_s.i
new file mode 100644 (file)
index 0000000..d7529a3
--- /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.
+ */
+
+// WARNING: this file is machine generated.  Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,metrics_s);
+
+trellis_metrics_s_sptr trellis_make_metrics_s (const int O, const int D, const std::vector<short> &TABLE, trellis_metric_type_t TYPE);
+
+class trellis_metrics_s : public gr_block
+{
+private:
+  trellis_metrics_s (const int O, const int D, const std::vector<short> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+  int O () const { return d_O; }
+  int D () const { return d_D; }
+  trellis_metric_type_t TYPE () const { return d_TYPE; }
+  std::vector<short> TABLE () const { return d_TABLE; }
+};
diff --git a/gr-trellis/src/lib/trellis_metrics_s.lo b/gr-trellis/src/lib/trellis_metrics_s.lo
new file mode 100644 (file)
index 0000000..844c4bf
--- /dev/null
@@ -0,0 +1,12 @@
+# trellis_metrics_s.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object='.libs/trellis_metrics_s.o'
+
+# Name of the non-PIC object.
+non_pic_object=none
+
index e4866e7f924a9dd3f30f00a0b56b7a550a2785a1..fe98177bee03016badbd3feef0ad107be2d0cb17 100755 (executable)
@@ -58,5 +58,19 @@ class qa_trellis (gr_unittest.TestCase):
         OS = (0, 3, 3, 0, 1, 2, 2, 1)
         f = trellis.fsm("awgn1o2_4.fsm")
         self.assertEqual((I,S,O,NS,OS),(f.I(),f.S(),f.O(),f.NS(),f.OS()))
+
+    def test_001_interleaver (self):
+        K = 5
+        IN = (1,2,3,4,0)
+        DIN = (4,0,1,2,3)
+        i = trellis.interleaver(K,IN)
+        self.assertEqual((K,IN,DIN),(i.K(),i.INTER(),i.DEINTER()))
+
+
+
+
+
+
+
 if __name__ == '__main__':
     gr_unittest.main ()