From 4b42ab554e45e4326466976028ed25123746205f Mon Sep 17 00:00:00 2001 From: Ben Reynwar Date: Sun, 6 Feb 2011 14:02:44 -0700 Subject: 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. --- gnuradio-core/src/lib/general/Makefile.am | 1 + gnuradio-core/src/lib/general/gr_constellation.cc | 42 +++++++++++++++++++++++ gnuradio-core/src/lib/general/gr_constellation.h | 11 ++++++ gnuradio-core/src/lib/general/gr_constellation.i | 3 ++ gnuradio-core/src/lib/general/gr_metric_type.h | 31 +++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_metric_type.h (limited to 'gnuradio-core/src/lib/general') 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 #include +#include #include #include #include #include #include +#include +#include #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 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 #include #include +#include /************************************************************/ /* gr_constellation */ @@ -55,9 +56,19 @@ class gr_constellation : public boost::enable_shared_from_this //! 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; %template(unsigned_int_vector) std::vector; +// Make sure metric types get SWIGed. +%include gr_metric_type.h + class gr_constellation; typedef boost::shared_ptr gr_constellation_sptr; %template(gr_constellation_sptr) boost::shared_ptr; 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 + -- cgit