diff options
Diffstat (limited to 'gr-trellis')
22 files changed, 606 insertions, 17 deletions
diff --git a/gr-trellis/doc/gr-trellis.html b/gr-trellis/doc/gr-trellis.html index 4c0173c2c..82d923753 100644 --- a/gr-trellis/doc/gr-trellis.html +++ b/gr-trellis/doc/gr-trellis.html @@ -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"><<a href="mailto:anastas@umich.edu">anastas@umich.edu</a>></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. diff --git a/gr-trellis/src/lib/Makefile.gen b/gr-trellis/src/lib/Makefile.gen index 9c0ddf9ea..7a47ea3a7 100644 --- a/gr-trellis/src/lib/Makefile.gen +++ b/gr-trellis/src/lib/Makefile.gen @@ -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 \ diff --git a/gr-trellis/src/lib/generate_common.py b/gr-trellis/src/lib/generate_common.py index c7bb6c865..ee744b8e1 100644 --- a/gr-trellis/src/lib/generate_common.py +++ b/gr-trellis/src/lib/generate_common.py @@ -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'], ) diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc index 427db72e3..042dc04ba 100644 --- a/gr-trellis/src/lib/interleaver.cc +++ b/gr-trellis/src/lib/interleaver.cc @@ -22,6 +22,7 @@ #include <cstdlib>
#include <cstdio>
+#include <iostream>
#include <stdexcept>
#include <cmath>
#include "quicksort_index.h"
@@ -90,19 +91,18 @@ interleaver::interleaver(const int K, unsigned int seed) 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;
+ for(int i=0;i<d_K;i++) {
+ d_INTER[i]=i;
tmp[i] = rand();
- quicksort_index <int> (tmp,d_INTER,0,d_K);
+ }
+ //quicksort_index <int> (tmp,d_INTER,0,d_K-1); got to resolve this...
+ quicksort_index1 (tmp,d_INTER,0,d_K-1);
// generate DEINTER table
for(int i=0;i<d_K;i++) {
d_DEINTER[d_INTER[i]]=i;
}
-*/
}
diff --git a/gr-trellis/src/lib/quicksort_index.cc b/gr-trellis/src/lib/quicksort_index.cc index 705aeebed..0ab63ebbe 100644 --- a/gr-trellis/src/lib/quicksort_index.cc +++ b/gr-trellis/src/lib/quicksort_index.cc @@ -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]; + T 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); } } + diff --git a/gr-trellis/src/lib/quicksort_index.h b/gr-trellis/src/lib/quicksort_index.h index 9a0e65905..10d36f619 100644 --- a/gr-trellis/src/lib/quicksort_index.h +++ b/gr-trellis/src/lib/quicksort_index.h @@ -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 diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i index 2db07ed1d..bd3144119 100644 --- a/gr-trellis/src/lib/trellis.i +++ b/gr-trellis/src/lib/trellis.i @@ -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> diff --git a/gr-trellis/src/lib/trellis_calc_metric.cc b/gr-trellis/src/lib/trellis_calc_metric.cc index c6d2ce98c..ae25a67ba 100644 --- a/gr-trellis/src/lib/trellis_calc_metric.cc +++ b/gr-trellis/src/lib/trellis_calc_metric.cc @@ -24,7 +24,95 @@ #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; diff --git a/gr-trellis/src/lib/trellis_calc_metric.h b/gr-trellis/src/lib/trellis_calc_metric.h index 5375070f8..1e1805322 100644 --- a/gr-trellis/src/lib/trellis_calc_metric.h +++ b/gr-trellis/src/lib/trellis_calc_metric.h @@ -27,6 +27,10 @@ #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); diff --git a/gr-trellis/src/lib/trellis_generated.i b/gr-trellis/src/lib/trellis_generated.i index c76e79c5c..464ffacb3 100644 --- a/gr-trellis/src/lib/trellis_generated.i +++ b/gr-trellis/src/lib/trellis_generated.i @@ -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> diff --git a/gr-trellis/src/lib/trellis_metrics_X.cc.t b/gr-trellis/src/lib/trellis_metrics_X.cc.t index d5347e12d..2dd1adb12 100644 --- a/gr-trellis/src/lib/trellis_metrics_X.cc.t +++ b/gr-trellis/src/lib/trellis_metrics_X.cc.t @@ -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); diff --git a/gr-trellis/src/lib/trellis_metrics_c.cc b/gr-trellis/src/lib/trellis_metrics_c.cc index 1ff5f4540..ea1808e83 100644 --- a/gr-trellis/src/lib/trellis_metrics_c.cc +++ b/gr-trellis/src/lib/trellis_metrics_c.cc @@ -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); diff --git a/gr-trellis/src/lib/trellis_metrics_f.cc b/gr-trellis/src/lib/trellis_metrics_f.cc index 472ec5942..2e148bbd5 100644 --- a/gr-trellis/src/lib/trellis_metrics_f.cc +++ b/gr-trellis/src/lib/trellis_metrics_f.cc @@ -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 index 000000000..5901c5513 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_i.cc @@ -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 index 000000000..c51e377e7 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_i.h @@ -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 index 000000000..dadd06577 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_i.i @@ -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 index 000000000..ce7227bf5 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_i.lo @@ -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 index 000000000..3bee2cc92 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_s.cc @@ -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 index 000000000..b4332bcc3 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_s.h @@ -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 index 000000000..d7529a3e1 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_s.i @@ -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 index 000000000..844c4bf29 --- /dev/null +++ b/gr-trellis/src/lib/trellis_metrics_s.lo @@ -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 + diff --git a/gr-trellis/src/python/qa_trellis.py b/gr-trellis/src/python/qa_trellis.py index e4866e7f9..fe98177be 100755 --- a/gr-trellis/src/python/qa_trellis.py +++ b/gr-trellis/src/python/qa_trellis.py @@ -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 () |