ccsoft  0.0.0
Convolutional codes library with soft decision decoding
/shared/development/google_code/rssoft/libccsoft/lib/CC_SequentialDecodingInternal_FA.h
Go to the documentation of this file.
00001 /*
00002  Copyright 2013 Edouard Griffiths <f4exb at free dot fr>
00003 
00004  This file is part of CCSoft. A Convolutional Codes Soft Decoding library
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009  (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
00019 
00020  Convolutional soft-decision sequential decoder generic (virtual) class
00021  Based on node+edge combination in the code tree
00022 
00023  */
00024 #ifndef __CC_SEQUENTIAL_DECODING_INERNAL_FA_H__
00025 #define __CC_SEQUENTIAL_DECODING_INERNAL_FA_H__
00026 
00027 #include "CC_TreeNodeEdge_FA.h"
00028 #include "CC_ReliabilityMatrix.h"
00029 #include "CC_TreeGraphviz_FA.h"
00030 
00031 #include <cmath>
00032 #include <algorithm>
00033 #include <iostream>
00034 
00035 
00036 
00037 namespace ccsoft
00038 {
00039 
00052 template<typename T_Register, typename T_IOSymbol, typename T_Tag, unsigned int N_k>
00053 class CC_SequentialDecodingInternal_FA
00054 {
00055 public:
00065         CC_SequentialDecodingInternal_FA() :
00066         root_node(0)
00067         {}
00068 
00072         virtual ~CC_SequentialDecodingInternal_FA()
00073         {
00074         if (root_node)
00075         {
00076             delete root_node;
00077             root_node = 0;
00078         }
00079         }
00080 
00084     void reset()
00085     {
00086         if (root_node)
00087         {
00088             delete root_node;
00089             root_node = 0;
00090         }
00091     }
00092 
00093 protected:
00097     float log2(float x)
00098     {
00099         return log(x)/log(2.0);
00100     }
00101 
00105     void init_root()
00106     {
00107         root_node = new CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>(0, 0, 0, 0.0, 0.0, -1);
00108     }
00109 
00115     virtual void visit_node_forward(CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>* node, const CC_ReliabilityMatrix& relmat) = 0;
00116 
00123     void back_track(CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>* node_edge, std::vector<T_IOSymbol>& decoded_message, bool mark_nodes = false)
00124     {
00125         std::vector<T_IOSymbol> reversed_message;
00126         CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *cur_node_edge = node_edge;
00127         CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *incoming_node_edge;
00128 
00129         reversed_message.push_back(cur_node_edge->get_in_symbol());
00130 
00131         while (incoming_node_edge = (cur_node_edge->get_incoming_node_edge()))
00132         {
00133             cur_node_edge->set_on_final_path(mark_nodes);
00134 
00135             if (incoming_node_edge->get_depth() >= 0) // don't take root node
00136             {
00137                 reversed_message.push_back(incoming_node_edge->get_in_symbol());
00138             }
00139 
00140             cur_node_edge = incoming_node_edge;
00141         }
00142 
00143         decoded_message.resize(reversed_message.size());
00144         std::reverse_copy(reversed_message.begin(), reversed_message.end(), decoded_message.begin());
00145     }
00146 
00151     void print_dot_internal(std::ostream& os)
00152     {
00153         CC_TreeGraphviz_FA<T_IOSymbol, T_Register, T_Tag, N_k>::create_dot(root_node, os);
00154     }
00155     
00156     CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *root_node; 
00157 };
00158 
00159 
00160 } // namespace ccsoft
00161 
00162 
00163 #endif // __CC_SEQUENTIAL_DECODING_INERNAL_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines