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"
29 void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
35 case TRELLIS_EUCLIDEAN:
36 for(int o=0;o<O;o++) {
38 for (int m=0;m<D;m++) {
39 float s=in[m]-TABLE[o*D+m];
44 case TRELLIS_HARD_SYMBOL:
45 for(int o=0;o<O;o++) {
47 for (int m=0;m<D;m++) {
48 float s=in[m]-TABLE[o*D+m];
56 for(int o=0;o<O;o++) {
57 metric[o] = (o==minmi?0.0:1.0);
60 case TRELLIS_HARD_BIT:
61 throw std::runtime_error ("Invalid metric type (not yet implemented).");
64 throw std::runtime_error ("Invalid metric type.");
69 void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
75 case TRELLIS_EUCLIDEAN:
76 for(int o=0;o<O;o++) {
78 for (int m=0;m<D;m++) {
79 float s=in[m]-TABLE[o*D+m];
84 case TRELLIS_HARD_SYMBOL:
85 for(int o=0;o<O;o++) {
87 for (int m=0;m<D;m++) {
88 float s=in[m]-TABLE[o*D+m];
96 for(int o=0;o<O;o++) {
97 metric[o] = (o==minmi?0.0:1.0);
100 case TRELLIS_HARD_BIT:
101 throw std::runtime_error ("Invalid metric type (not yet implemented).");
104 throw std::runtime_error ("Invalid metric type.");
110 void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
112 float minm = FLT_MAX;
116 case TRELLIS_EUCLIDEAN:
117 for(int o=0;o<O;o++) {
119 for (int m=0;m<D;m++) {
120 float s=in[m]-TABLE[o*D+m];
125 case TRELLIS_HARD_SYMBOL:
126 for(int o=0;o<O;o++) {
128 for (int m=0;m<D;m++) {
129 float s=in[m]-TABLE[o*D+m];
137 for(int o=0;o<O;o++) {
138 metric[o] = (o==minmi?0.0:1.0);
141 case TRELLIS_HARD_BIT:
142 throw std::runtime_error ("Invalid metric type (not yet implemented).");
145 throw std::runtime_error ("Invalid metric type.");
150 void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
152 float minm = FLT_MAX;
156 case TRELLIS_EUCLIDEAN:
157 for(int o=0;o<O;o++) {
159 for (int m=0;m<D;m++) {
160 gr_complex s=in[m]-TABLE[o*D+m];
161 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
164 case TRELLIS_HARD_SYMBOL:
165 for(int o=0;o<O;o++) {
167 for (int m=0;m<D;m++) {
168 gr_complex s=in[m]-TABLE[o*D+m];
169 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
176 for(int o=0;o<O;o++) {
177 metric[o] = (o==minmi?0.0:1.0);
180 case TRELLIS_HARD_BIT:
181 throw std::runtime_error ("Invalid metric type (not yet implemented).");
184 throw std::runtime_error ("Invalid metric type.");
190 template <class T> void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type)
192 float minm = FLT_MAX;
196 case TRELLIS_EUCLIDEAN:
197 for(int o=0;o<O;o++) {
199 for (int m=0;m<D;m++) {
200 T s=in[m]-TABLE[o*D+m];
201 gr_complex sc(1.0*s,0);
202 metric[o]+=(s*conj(s)).real();
206 case TRELLIS_HARD_SYMBOL:
207 for(int o=0;o<O;o++) {
209 for (int m=0;m<D;m++) {
210 T s=in[m]-TABLE[o*D+m];
211 gr_complex sc(1.0*s,0);
212 metric[o]+=(s*conj(s)).real();
219 for(int o=0;o<O;o++) {
220 metric[o] = (o==minmi?0.0:1.0);
223 case TRELLIS_HARD_BIT:
224 throw std::runtime_error ("Invalid metric type (not yet implemented).");
227 throw std::runtime_error ("Invalid metric type.");