summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/general/Makefile.am1
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.cc42
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.h11
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.i3
-rw-r--r--gnuradio-core/src/lib/general/gr_metric_type.h (renamed from gr-trellis/src/lib/trellis_metric_type.h)4
-rw-r--r--gr-trellis/src/lib/Makefile.am4
-rw-r--r--gr-trellis/src/lib/trellis.i12
-rw-r--r--gr-trellis/src/lib/trellis_calc_metric.h2
-rw-r--r--gr-trellis/src/lib/trellis_constellation_metrics_cf.cc85
-rw-r--r--gr-trellis/src/lib/trellis_constellation_metrics_cf.h60
-rw-r--r--gr-trellis/src/lib/trellis_constellation_metrics_cf.i33
11 files changed, 252 insertions, 5 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am
index e5ea49640..0830f5d2e 100644
--- a/gnuradio-core/src/lib/general/Makefile.am
+++ b/gnuradio-core/src/lib/general/Makefile.am
@@ -266,6 +266,7 @@ grinclude_HEADERS = \
gr_log2_const.h \
gr_map_bb.h \
gr_math.h \
+ gr_metric_type.h \
gr_misc.h \
gr_nco.h \
gr_nlog10_ff.h \
diff --git a/gnuradio-core/src/lib/general/gr_constellation.cc b/gnuradio-core/src/lib/general/gr_constellation.cc
index 403394eaa..8f5624668 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.cc
+++ b/gnuradio-core/src/lib/general/gr_constellation.cc
@@ -22,11 +22,14 @@
#include <gr_io_signature.h>
#include <gr_constellation.h>
+#include <gr_metric_type.h>
#include <gr_math.h>
#include <gr_complex.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
+#include <float.h>
+#include <stdexcept>
#define M_TWOPI (2*M_PI)
#define SQRT_TWO 0.707107
@@ -76,6 +79,45 @@ unsigned int gr_constellation::decision_maker(gr_complex sample)
return min_index;
}
+void gr_constellation::calc_metric(gr_complex sample, float *metric, trellis_metric_type_t type) {
+ switch (type){
+ case TRELLIS_EUCLIDEAN:
+ calc_euclidean_metric(sample, metric);
+ break;
+ case TRELLIS_HARD_SYMBOL:
+ calc_hard_symbol_metric(sample, metric);
+ break;
+ case TRELLIS_HARD_BIT:
+ throw std::runtime_error ("Invalid metric type (not yet implemented).");
+ break;
+ default:
+ throw std::runtime_error ("Invalid metric type.");
+ }
+}
+
+void gr_constellation::calc_euclidean_metric(gr_complex sample, float *metric) {
+ for (int o=0; o<d_constellation.size(); o++) {
+ gr_complex s = sample - d_constellation[o];
+ metric[o] = s.real()*s.real()+s.imag()*s.imag();
+ }
+}
+
+void gr_constellation::calc_hard_symbol_metric(gr_complex sample, float *metric){
+ float minm = FLT_MAX;
+ int minmi = 0;
+ for (int o=0; o<d_constellation.size(); o++) {
+ gr_complex s = sample - d_constellation[o];
+ float dist = s.real()*s.real()+s.imag()*s.imag();
+ if (dist < minm) {
+ minm = dist;
+ minmi = o;
+ }
+ }
+ for(int o=0; o<d_constellation.size(); o++) {
+ metric[o] = (o==minmi?0.0:1.0);
+ }
+}
+
gr_constellation_sector::gr_constellation_sector (std::vector<gr_complex> constellation,
unsigned int n_sectors) :
gr_constellation(constellation),
diff --git a/gnuradio-core/src/lib/general/gr_constellation.h b/gnuradio-core/src/lib/general/gr_constellation.h
index 8ba22d59a..6908f43f1 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.h
+++ b/gnuradio-core/src/lib/general/gr_constellation.h
@@ -27,6 +27,7 @@
#include <math.h>
#include <gr_complex.h>
#include <boost/enable_shared_from_this.hpp>
+#include <gr_metric_type.h>
/************************************************************/
/* gr_constellation */
@@ -55,9 +56,19 @@ class gr_constellation : public boost::enable_shared_from_this<gr_constellation>
//! Also calculates the phase error.
virtual unsigned int decision_maker (gr_complex sample);
+ //! Calculates metrics for all points in the constellation.
+ //! For use with the viterbi algorithm.
+ void calc_metric(gr_complex sample, float *metric, trellis_metric_type_t type);
+ void calc_euclidean_metric(gr_complex sample, float *metric);
+ void calc_hard_symbol_metric(gr_complex sample, float *metric);
+
unsigned int bits_per_symbol () {
return floor(log(d_constellation.size())/log(2));
}
+
+ unsigned int arity () {
+ return d_constellation.size();
+ }
gr_constellation_sptr base() {
return shared_from_this();
diff --git a/gnuradio-core/src/lib/general/gr_constellation.i b/gnuradio-core/src/lib/general/gr_constellation.i
index 6620721ea..d00c62f90 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.i
+++ b/gnuradio-core/src/lib/general/gr_constellation.i
@@ -23,6 +23,9 @@
%template(gr_complex_vector) std::vector<gr_complex>;
%template(unsigned_int_vector) std::vector<unsigned int>;
+// Make sure metric types get SWIGed.
+%include gr_metric_type.h
+
class gr_constellation;
typedef boost::shared_ptr<gr_constellation> gr_constellation_sptr;
%template(gr_constellation_sptr) boost::shared_ptr<gr_constellation>;
diff --git a/gr-trellis/src/lib/trellis_metric_type.h b/gnuradio-core/src/lib/general/gr_metric_type.h
index a1040f108..74c93b55e 100644
--- a/gr-trellis/src/lib/trellis_metric_type.h
+++ b/gnuradio-core/src/lib/general/gr_metric_type.h
@@ -20,8 +20,8 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef INCLUDED_TRELLIS_METRIC_TYPE_H
-#define INCLUDED_TRELLIS_METRIC_TYPE_H
+#ifndef INCLUDED_GR_METRIC_TYPE_H
+#define INCLUDED_GR_METRIC_TYPE_H
typedef enum {
TRELLIS_EUCLIDEAN = 200, TRELLIS_HARD_SYMBOL, TRELLIS_HARD_BIT
diff --git a/gr-trellis/src/lib/Makefile.am b/gr-trellis/src/lib/Makefile.am
index 08e75291a..d6926f2a0 100644
--- a/gr-trellis/src/lib/Makefile.am
+++ b/gr-trellis/src/lib/Makefile.am
@@ -66,12 +66,12 @@ grinclude_HEADERS = \
quicksort_index.h \
base.h \
interleaver.h \
- trellis_metric_type.h \
trellis_calc_metric.h \
trellis_permutation.h \
trellis_siso_type.h \
trellis_siso_f.h \
trellis_siso_combined_f.h \
+ trellis_constellation_metrics_cf.h \
$(GENERATED_H)
lib_LTLIBRARIES = libgnuradio-trellis.la
@@ -85,6 +85,7 @@ libgnuradio_trellis_la_SOURCES = \
trellis_permutation.cc \
trellis_siso_f.cc \
trellis_siso_combined_f.cc \
+ trellis_constellation_metrics_cf.cc \
$(GENERATED_CC)
libgnuradio_trellis_la_LIBADD = \
@@ -119,6 +120,7 @@ trellis_swiginclude_headers = \
trellis_permutation.i \
trellis_siso_f.i \
trellis_siso_combined_f.i \
+ trellis_constellation_metrics_cf.i \
trellis_generated.i
# Do creation and inclusion of other Makefiles last
diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i
index d035cea54..fe74c8d9f 100644
--- a/gr-trellis/src/lib/trellis.i
+++ b/gr-trellis/src/lib/trellis.i
@@ -28,8 +28,11 @@
#include "trellis_permutation.h"
#include "trellis_siso_f.h"
#include "trellis_siso_combined_f.h"
+#include "trellis_constellation_metrics_cf.h"
+#include "gr_constellation.h"
%}
+
// ----------------------------------------------------------------
%include "fsm.i"
@@ -38,12 +41,19 @@
%include "trellis_siso_f.i"
%include "trellis_siso_combined_f.i"
-%include "trellis_metric_type.h"
%include "trellis_siso_type.h"
+%include "trellis_constellation_metrics_cf.i"
%include "trellis_generated.i"
+%import "gr_metric_type.h"
+%import "gr_constellation.i"
+
+%pythoncode %{
+ from gnuradio.gr import TRELLIS_EUCLIDEAN, TRELLIS_HARD_SYMBOL, TRELLIS_HARD_BIT
+ %}
+
#if SWIGGUILE
%scheme %{
(load-extension-global "libguile-gnuradio-trellis" "scm_init_gnuradio_trellis_module")
diff --git a/gr-trellis/src/lib/trellis_calc_metric.h b/gr-trellis/src/lib/trellis_calc_metric.h
index fabf4e145..b9eacb086 100644
--- a/gr-trellis/src/lib/trellis_calc_metric.h
+++ b/gr-trellis/src/lib/trellis_calc_metric.h
@@ -25,7 +25,7 @@
#include <vector>
#include <gr_complex.h>
-#include <trellis_metric_type.h>
+#include <gr_metric_type.h>
template <class T>
diff --git a/gr-trellis/src/lib/trellis_constellation_metrics_cf.cc b/gr-trellis/src/lib/trellis_constellation_metrics_cf.cc
new file mode 100644
index 000000000..73e848259
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_constellation_metrics_cf.cc
@@ -0,0 +1,85 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010 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 3, 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., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_constellation_metrics_cf.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+
+trellis_constellation_metrics_cf_sptr
+trellis_make_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE)
+{
+ return gnuradio::get_initial_sptr (new trellis_constellation_metrics_cf (constellation, TYPE));
+}
+
+
+
+trellis_constellation_metrics_cf::trellis_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE)
+ : gr_block ("constellation_metrics_cf",
+ gr_make_io_signature (1, -1, sizeof (gr_complex)),
+ gr_make_io_signature (1, -1, sizeof (float))),
+ d_constellation (constellation),
+ d_TYPE (TYPE),
+ d_O (constellation->arity())
+{
+ set_relative_rate (d_O);
+ set_output_multiple (d_O);
+}
+
+void
+trellis_constellation_metrics_cf::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_O == 0);
+ int input_required = noutput_items / d_O;
+ ninput_items_required[0] = input_required;
+}
+
+
+
+int
+trellis_constellation_metrics_cf::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);
+
+ const gr_complex *in = (gr_complex *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ for (int i = 0; i < noutput_items / d_O ; i++){
+ d_constellation->calc_metric(in[i], &(out[i*d_O]), d_TYPE);
+ }
+
+ consume_each (noutput_items / d_O);
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_constellation_metrics_cf.h b/gr-trellis/src/lib/trellis_constellation_metrics_cf.h
new file mode 100644
index 000000000..a50e92841
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_constellation_metrics_cf.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004, 2010 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 3, 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., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_CONSTELLATION_METRICS_CF_H
+#define INCLUDED_TRELLIS_CONSTELLATION_METRICS_CF_H
+
+#include <gr_block.h>
+#include <gr_constellation.h>
+#include <gr_metric_type.h>
+
+class trellis_constellation_metrics_cf;
+typedef boost::shared_ptr<trellis_constellation_metrics_cf> trellis_constellation_metrics_cf_sptr;
+
+trellis_constellation_metrics_cf_sptr trellis_make_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup coding_blk
+ */
+class trellis_constellation_metrics_cf : public gr_block
+{
+ public:
+ 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);
+ protected:
+ trellis_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE);
+
+ private:
+ gr_constellation_sptr d_constellation;
+ trellis_metric_type_t d_TYPE;
+ unsigned int d_O;
+ friend trellis_constellation_metrics_cf_sptr trellis_make_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE);
+
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_constellation_metrics_cf.i b/gr-trellis/src/lib/trellis_constellation_metrics_cf.i
new file mode 100644
index 000000000..b4a5bbbb7
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_constellation_metrics_cf.i
@@ -0,0 +1,33 @@
+/* -*- 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 3, 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., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,constellation_metrics_cf);
+
+trellis_constellation_metrics_cf_sptr trellis_make_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE);
+
+class trellis_constellation_metrics_cf : public gr_block
+{
+private:
+ trellis_constellation_metrics_cf (gr_constellation_sptr constellation, trellis_metric_type_t TYPE);
+};