3 * Copyright 2004 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 3, 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.
25 #include "trellis_calc_metric.h"
30 void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type)
37 case TRELLIS_EUCLIDEAN:
38 for(int o=0;o<O;o++) {
40 for (int m=0;m<D;m++) {
41 T s=in[m]-TABLE[o*D+m];
42 //gr_complex sc(1.0*s,0);
43 //metric[o]+=(sc*conj(sc)).real();
48 case TRELLIS_HARD_SYMBOL:
49 for(int o=0;o<O;o++) {
51 for (int m=0;m<D;m++) {
52 T s=in[m]-TABLE[o*D+m];
53 //gr_complex sc(1.0*s,0);
54 //metric[o]+=(sc*conj(sc)).real();
62 for(int o=0;o<O;o++) {
63 metric[o] = (o==minmi?0.0:1.0);
66 case TRELLIS_HARD_BIT:
67 throw std::runtime_error ("Invalid metric type (not yet implemented).");
70 throw std::runtime_error ("Invalid metric type.");
77 void calc_metric<short>(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type);
80 void calc_metric<int>(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type);
83 void calc_metric<float>(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type);
87 void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
93 case TRELLIS_EUCLIDEAN:
94 for(int o=0;o<O;o++) {
96 for (int m=0;m<D;m++) {
97 float s=in[m]-TABLE[o*D+m];
102 case TRELLIS_HARD_SYMBOL:
103 for(int o=0;o<O;o++) {
105 for (int m=0;m<D;m++) {
106 float s=in[m]-TABLE[o*D+m];
114 for(int o=0;o<O;o++) {
115 metric[o] = (o==minmi?0.0:1.0);
118 case TRELLIS_HARD_BIT:
119 throw std::runtime_error ("Invalid metric type (not yet implemented).");
122 throw std::runtime_error ("Invalid metric type.");
127 void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
129 float minm = FLT_MAX;
133 case TRELLIS_EUCLIDEAN:
134 for(int o=0;o<O;o++) {
136 for (int m=0;m<D;m++) {
137 float s=in[m]-TABLE[o*D+m];
142 case TRELLIS_HARD_SYMBOL:
143 for(int o=0;o<O;o++) {
145 for (int m=0;m<D;m++) {
146 float s=in[m]-TABLE[o*D+m];
154 for(int o=0;o<O;o++) {
155 metric[o] = (o==minmi?0.0:1.0);
158 case TRELLIS_HARD_BIT:
159 throw std::runtime_error ("Invalid metric type (not yet implemented).");
162 throw std::runtime_error ("Invalid metric type.");
168 void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
170 float minm = FLT_MAX;
174 case TRELLIS_EUCLIDEAN:
175 for(int o=0;o<O;o++) {
177 for (int m=0;m<D;m++) {
178 float s=in[m]-TABLE[o*D+m];
183 case TRELLIS_HARD_SYMBOL:
184 for(int o=0;o<O;o++) {
186 for (int m=0;m<D;m++) {
187 float s=in[m]-TABLE[o*D+m];
195 for(int o=0;o<O;o++) {
196 metric[o] = (o==minmi?0.0:1.0);
199 case TRELLIS_HARD_BIT:
200 throw std::runtime_error ("Invalid metric type (not yet implemented).");
203 throw std::runtime_error ("Invalid metric type.");
212 void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
214 float minm = FLT_MAX;
219 case TRELLIS_EUCLIDEAN:
220 for(int o=0;o<O;o++) {
222 for (int m=0;m<D;m++) {
223 gr_complex s=in[m]-TABLE[o*D+m];
224 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
228 case TRELLIS_HARD_SYMBOL:
229 for(int o=0;o<O;o++) {
231 for (int m=0;m<D;m++) {
232 gr_complex s=in[m]-TABLE[o*D+m];
233 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
240 for(int o=0;o<O;o++) {
241 metric[o] = (o==minmi?0.0:1.0);
244 case TRELLIS_HARD_BIT:
245 throw std::runtime_error ("Invalid metric type (not yet implemented).");
248 throw std::runtime_error ("Invalid metric type.");