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)
36 case TRELLIS_EUCLIDEAN:
37 for(int o=0;o<O;o++) {
39 for (int m=0;m<D;m++) {
40 T s=in[m]-TABLE[o*D+m];
41 //gr_complex sc(1.0*s,0);
42 //metric[o]+=(sc*conj(sc)).real();
47 case TRELLIS_HARD_SYMBOL:
48 for(int o=0;o<O;o++) {
50 for (int m=0;m<D;m++) {
51 T s=in[m]-TABLE[o*D+m];
52 //gr_complex sc(1.0*s,0);
53 //metric[o]+=(sc*conj(sc)).real();
61 for(int o=0;o<O;o++) {
62 metric[o] = (o==minmi?0.0:1.0);
65 case TRELLIS_HARD_BIT:
66 throw std::runtime_error ("Invalid metric type (not yet implemented).");
69 throw std::runtime_error ("Invalid metric type.");
76 void calc_metric<short>(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type);
79 void calc_metric<int>(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type);
82 void calc_metric<float>(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type);
86 void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
92 case TRELLIS_EUCLIDEAN:
93 for(int o=0;o<O;o++) {
95 for (int m=0;m<D;m++) {
96 float s=in[m]-TABLE[o*D+m];
101 case TRELLIS_HARD_SYMBOL:
102 for(int o=0;o<O;o++) {
104 for (int m=0;m<D;m++) {
105 float s=in[m]-TABLE[o*D+m];
113 for(int o=0;o<O;o++) {
114 metric[o] = (o==minmi?0.0:1.0);
117 case TRELLIS_HARD_BIT:
118 throw std::runtime_error ("Invalid metric type (not yet implemented).");
121 throw std::runtime_error ("Invalid metric type.");
126 void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
128 float minm = FLT_MAX;
132 case TRELLIS_EUCLIDEAN:
133 for(int o=0;o<O;o++) {
135 for (int m=0;m<D;m++) {
136 float s=in[m]-TABLE[o*D+m];
141 case TRELLIS_HARD_SYMBOL:
142 for(int o=0;o<O;o++) {
144 for (int m=0;m<D;m++) {
145 float s=in[m]-TABLE[o*D+m];
153 for(int o=0;o<O;o++) {
154 metric[o] = (o==minmi?0.0:1.0);
157 case TRELLIS_HARD_BIT:
158 throw std::runtime_error ("Invalid metric type (not yet implemented).");
161 throw std::runtime_error ("Invalid metric type.");
167 void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
169 float minm = FLT_MAX;
173 case TRELLIS_EUCLIDEAN:
174 for(int o=0;o<O;o++) {
176 for (int m=0;m<D;m++) {
177 float s=in[m]-TABLE[o*D+m];
182 case TRELLIS_HARD_SYMBOL:
183 for(int o=0;o<O;o++) {
185 for (int m=0;m<D;m++) {
186 float s=in[m]-TABLE[o*D+m];
194 for(int o=0;o<O;o++) {
195 metric[o] = (o==minmi?0.0:1.0);
198 case TRELLIS_HARD_BIT:
199 throw std::runtime_error ("Invalid metric type (not yet implemented).");
202 throw std::runtime_error ("Invalid metric type.");
211 void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
213 float minm = FLT_MAX;
217 case TRELLIS_EUCLIDEAN:
218 for(int o=0;o<O;o++) {
220 for (int m=0;m<D;m++) {
221 gr_complex s=in[m]-TABLE[o*D+m];
222 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
225 case TRELLIS_HARD_SYMBOL:
226 for(int o=0;o<O;o++) {
228 for (int m=0;m<D;m++) {
229 gr_complex s=in[m]-TABLE[o*D+m];
230 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
237 for(int o=0;o<O;o++) {
238 metric[o] = (o==minmi?0.0:1.0);
241 case TRELLIS_HARD_BIT:
242 throw std::runtime_error ("Invalid metric type (not yet implemented).");
245 throw std::runtime_error ("Invalid metric type.");