summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/general
diff options
context:
space:
mode:
authorBen Reynwar2011-02-06 14:02:44 -0700
committerBen Reynwar2011-02-06 14:02:44 -0700
commit4b42ab554e45e4326466976028ed25123746205f (patch)
tree1b045d382818cfacaf5bb61fddb77035634f6074 /gnuradio-core/src/lib/general
parentf450ed2d99672832eb8ca10af4c3be9a1dc81a96 (diff)
downloadgnuradio-4b42ab554e45e4326466976028ed25123746205f.tar.gz
gnuradio-4b42ab554e45e4326466976028ed25123746205f.tar.bz2
gnuradio-4b42ab554e45e4326466976028ed25123746205f.zip
Added trellis_constellation_metrics_cf. It is equivalent to trellis_metrics_c but it uses the constellation object's calc_metric method. This method is also added here. trellis_metric_type.h is moved to gr_metric_type since constellation object is now dependent on it.
Diffstat (limited to 'gnuradio-core/src/lib/general')
-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.h31
5 files changed, 88 insertions, 0 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/gnuradio-core/src/lib/general/gr_metric_type.h b/gnuradio-core/src/lib/general/gr_metric_type.h
new file mode 100644
index 000000000..74c93b55e
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_metric_type.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 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_GR_METRIC_TYPE_H
+#define INCLUDED_GR_METRIC_TYPE_H
+
+typedef enum {
+ TRELLIS_EUCLIDEAN = 200, TRELLIS_HARD_SYMBOL, TRELLIS_HARD_BIT
+} trellis_metric_type_t;
+
+#endif
+