3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_CODE_METRICS_H
24 #define INCLUDED_CODE_METRICS_H
26 #include "code_types.h"
29 template<typename pdf_fcn_io_t>
30 class code_metrics_table;
32 template<typename pdf_fcn_io_t>
33 code_metrics_table<pdf_fcn_io_t>*
34 libecc_code_metrics_create_table
35 (pdf_fcn_io_t (*pdf_fcn_0_bit) (pdf_fcn_io_t),
36 pdf_fcn_io_t (*pdf_fcn_1_bit) (pdf_fcn_io_t),
38 pdf_fcn_io_t min_sample,
39 pdf_fcn_io_t max_sample,
40 int sample_precision = 0);
43 template<typename pdf_fcn_io_t>
44 class code_metrics_decoder;
46 template<typename pdf_fcn_io_t>
47 libecc_code_metrics_create_decoder
48 (code_convolutional_trellis* trellis,
49 code_metrics_table<pdf_fcn_io_t>* table = 0,
50 int sample_precision = 0);
53 template<typename pdf_fcn_io_t>
54 class code_metrics_table
57 * class code_metrics_table: metrics table for convolutional codes.
58 * Pre-compute a lookup table upon instantiation, which makes for
59 * quick conversion from soft-float symbol value ('sym') to metric
60 * value. The symbol value probability is defined by the arguments
61 * 'pdf_fcn_0_bit' and 'pdf_fcn_1_bit' for p(0|sym) and p(1|sym)
62 * respectively. Internally, the PDF's are sampled and normalized to
63 * always have a minimum value of 0. For float-precision, the maximum
64 * value is 1.0, while for integer M-bits the maximum value is
65 * (2^M)-1. Smaller metric values indicate that the received symbols
66 * are closer to the given output bits; larger values indicate greater
67 * differences. The only constraint on the PDF functions are that
68 * they are piecewise continuous; otherwise, they don't even have to
69 * be a true PDF in terms of the integral from -inf to +inf being
70 * equal to 1 due to the normalization.
72 * Storage type for the tables is determined by the "sample_precision"
73 * argument. When the precision equals 0, 32-bit float storage is
74 * used; otherwise, the next largest standard integer type is used
75 * unsigned (char for 1 to 8 bits, short for 9 to 16 bits, and long
76 * for 17 to 32 bits). For the purposes of coding gain, any
77 * sample_precision larger than about 9 will have minimal added
78 * benefit under most conditions where communications are possible.
79 * Trellis computations are performed in either 32-bit float (for
80 * float storage) or 32-bit unsigned long (for all integer storage).
82 * The number of samples to store is determined by the "n_samples"
83 * argument, which must be at least 2 but is otherwise not limited
84 * except by the memory of the host computer.
86 * Samples of the PDF functions are taken from "min_sample" to
87 * "max_sample", which represent the floor and ceiling on input symbol
88 * values below and above which symbol values are truncated.
89 * Internally, a sub-n_samples value is determined and used to "sum"
90 * the PDF functions to divide the probabilities into "bins".
94 typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
96 virtual ~code_metrics_table () {};
98 // lookup() returns either a float, or a sign-extended
99 // 'sample_precision'-bit integer value.
101 virtual void lookup (pdf_fcn_io_t sym,
105 // convert does a lookup on 'n_syms' input symbols
107 virtual void convert (size_t n_syms,
112 inline const unsigned char out_item_size_bytes ()
113 {return(d_out_item_size_bytes);};
116 code_metrics_table (pdf_fcn_t pdf_fcn_0_bit,
117 pdf_fcn_t pdf_fcn_1_bit,
119 pdf_fcn_io_t min_sample,
120 pdf_fcn_io_t max_sample);
122 unsigned char d_out_item_size_bytes, d_sample_precision;
124 pdf_fcn_io_t d_max_sample, d_min_sample, d_delta;
125 pdf_fcn_t d_pdf_fcn_0_bit, d_pdf_fcn_1_bit;
126 std::vector<pdf_fcn_io_t> d_pdf_fcn_0_samples, d_pdf_fcn_1_samples;
129 template<typename pdf_fcn_io_t, typename metric_t>
130 class code_metrics_table_work : public code_metrics_table<pdf_fcn_io_t>
133 typedef metric_t *metric_ptr_t;
134 typedef pdf_fcn_io_t (*pdf_fcn_t) (pdf_fcn_io_t);
136 ~code_metrics_table_work () {};
138 void lookup (pdf_fcn_io_t sym, void* bit_0, void* bit_1);
139 void convert (size_t n_syms, pdf_fcn_io_t* sym, void* bit_0, void* bit_1);
142 code_metrics_table_work (pdf_fcn_t pdf_fcn_0_bit,
143 pdf_fcn_t pdf_fcn_1_bit,
145 pdf_fcn_io_t min_sample,
146 pdf_fcn_io_t max_sample,
147 int sample_precision = 0);
149 friend code_metrics_table<pdf_fcn_io_t>*
150 libecc_code_metrics_create_table<pdf_fcn_io_t>
151 (pdf_fcn_io_t (*pdf_fcn_0_bit) (pdf_fcn_io_t),
152 pdf_fcn_io_t (*pdf_fcn_1_bit) (pdf_fcn_io_t),
154 pdf_fcn_io_t min_sample,
155 pdf_fcn_io_t max_sample,
156 int sample_precision);
158 std::vector<metric_t> d_metric_table_0_bit, d_metric_table_1_bit;
162 // compute all output-bit combinations of the incoming symbols' metrics
164 void compute_all_outputs (pdf_fcn_io_t* syms, std::vector<unsigned long>& out);
165 void compute_all_outputs (pdf_fcn_io_t* syms, std::vector<float>& out);
167 size_t d_n_code_outputs;
168 std::vector<unsigned long> in_l[2];
169 std::vector<float> in_f[2];
172 #endif /* INCLUDED_CODE_METRICS_H */