3 * Copyright 2002 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.
24 #include <atsci_single_viterbi.h>
30 const float atsci_single_viterbi::was_sent[32] = {
31 -7,-3,-7,-3,-7,-3,-7,-3,
32 -5,-1,-5,-1,-5,-1,-5,-1,
37 const int atsci_single_viterbi::transition_table[32] = {
49 atsci_single_viterbi::reset()
51 for (unsigned int i = 0; i<2; i++)
52 for (unsigned int j = 0; j<8; j++) {
53 path_metrics[i][j] = 0;
59 atsci_single_viterbi::atsci_single_viterbi()
65 atsci_single_viterbi::decode(float input)
67 for (unsigned int next_state = 0; next_state < 8; next_state++) {
68 unsigned int index = next_state << 2;
69 int min_metric_symb = 0;
70 float min_metric = fabs(input - was_sent[index + 0]) +
71 path_metrics[phase][transition_table[index + 0]];
73 for (unsigned int symbol_sent = 1; symbol_sent < 4; symbol_sent++)
74 if( (fabs(input-was_sent[index+symbol_sent]) +
75 path_metrics[phase][transition_table[index+symbol_sent]])
77 min_metric = fabs(input-was_sent[index+symbol_sent]) +
78 path_metrics[phase][transition_table[index+symbol_sent]];
79 min_metric_symb = symbol_sent;
82 path_metrics[phase^1][next_state] = min_metric;
83 traceback[phase^1][next_state] = (((unsigned long long)min_metric_symb) << 62) |
84 (traceback[phase][transition_table[index+min_metric_symb]] >> 2);
86 unsigned int best_state = 0;
87 float best_state_metric = path_metrics[phase^1][0];
88 for (unsigned int state = 1; state < 8; state++)
89 if(path_metrics[phase^1][state] < best_state_metric) {
91 best_state_metric = path_metrics[phase^1][state];
93 if(best_state_metric > 10000) {
94 for(unsigned int state = 0; state < 8; state++)
95 path_metrics[phase^1][state] -= best_state_metric;
96 // cerr << "Resetting Path Metrics from " << best_state_metric << " to 0\n";
99 return (0x3 & traceback[phase][best_state]);