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 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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include "trellis_calc_metric.h"
27 void calc_metric_s(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
33 case TRELLIS_EUCLIDEAN:
34 for(int o=0;o<O;o++) {
36 for (int m=0;m<D;m++) {
37 float s=in[m]-TABLE[o*D+m];
42 case TRELLIS_HARD_SYMBOL:
43 for(int o=0;o<O;o++) {
45 for (int m=0;m<D;m++) {
46 float s=in[m]-TABLE[o*D+m];
54 for(int o=0;o<O;o++) {
55 metric[o] = (o==minmi?0.0:1.0);
58 case TRELLIS_HARD_BIT:
59 throw std::runtime_error ("Invalid metric type (not yet implemented).");
62 throw std::runtime_error ("Invalid metric type.");
68 void calc_metric_i(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
74 case TRELLIS_EUCLIDEAN:
75 for(int o=0;o<O;o++) {
77 for (int m=0;m<D;m++) {
78 float s=in[m]-TABLE[o*D+m];
83 case TRELLIS_HARD_SYMBOL:
84 for(int o=0;o<O;o++) {
86 for (int m=0;m<D;m++) {
87 float s=in[m]-TABLE[o*D+m];
95 for(int o=0;o<O;o++) {
96 metric[o] = (o==minmi?0.0:1.0);
99 case TRELLIS_HARD_BIT:
100 throw std::runtime_error ("Invalid metric type (not yet implemented).");
103 throw std::runtime_error ("Invalid metric type.");
109 void calc_metric_f(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
111 float minm = FLT_MAX;
115 case TRELLIS_EUCLIDEAN:
116 for(int o=0;o<O;o++) {
118 for (int m=0;m<D;m++) {
119 float s=in[m]-TABLE[o*D+m];
124 case TRELLIS_HARD_SYMBOL:
125 for(int o=0;o<O;o++) {
127 for (int m=0;m<D;m++) {
128 float s=in[m]-TABLE[o*D+m];
136 for(int o=0;o<O;o++) {
137 metric[o] = (o==minmi?0.0:1.0);
140 case TRELLIS_HARD_BIT:
141 throw std::runtime_error ("Invalid metric type (not yet implemented).");
144 throw std::runtime_error ("Invalid metric type.");
149 void calc_metric_c(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
151 float minm = FLT_MAX;
155 case TRELLIS_EUCLIDEAN:
156 for(int o=0;o<O;o++) {
158 for (int m=0;m<D;m++) {
159 gr_complex s=in[m]-TABLE[o*D+m];
160 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
163 case TRELLIS_HARD_SYMBOL:
164 for(int o=0;o<O;o++) {
166 for (int m=0;m<D;m++) {
167 gr_complex s=in[m]-TABLE[o*D+m];
168 metric[o]+=s.real()*s.real()+s.imag()*s.imag();
175 for(int o=0;o<O;o++) {
176 metric[o] = (o==minmi?0.0:1.0);
179 case TRELLIS_HARD_BIT:
180 throw std::runtime_error ("Invalid metric type (not yet implemented).");
183 throw std::runtime_error ("Invalid metric type.");