ccsoft  0.0.0
Convolutional codes library with soft decision decoding
/shared/development/google_code/rssoft/libccsoft/lib/CC_SequentialDecodingInternal.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_H__
00025 #define __CC_SEQUENTIAL_DECODING_INERNAL_H__
00026 
00027 #include "CC_TreeNodeEdge.h"
00028 #include "CC_ReliabilityMatrix.h"
00029 #include "CC_TreeGraphviz.h"
00030 
00031 #include <cmath>
00032 #include <algorithm>
00033 #include <iostream>
00034 
00035 
00036 
00037 namespace ccsoft
00038 {
00039 
00048 template<typename T_Register, typename T_IOSymbol, typename T_Tag>
00049 class CC_SequentialDecodingInternal
00050 {
00051 public:
00061         CC_SequentialDecodingInternal() :
00062         root_node(0)
00063         {}
00064 
00068         virtual ~CC_SequentialDecodingInternal()
00069         {
00070         if (root_node)
00071         {
00072             delete root_node;
00073             root_node = 0;
00074         }
00075         }
00076 
00080     void reset()
00081     {
00082         if (root_node)
00083         {
00084             delete root_node;
00085             root_node = 0;
00086         }
00087     }
00088 
00089 protected:
00093     float log2(float x)
00094     {
00095         return log(x)/log(2.0);
00096     }
00097 
00101     void init_root()
00102     {
00103         root_node = new CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag>(0, 0, 0, 0.0, 0.0, -1);
00104     }
00105 
00111     virtual void visit_node_forward(CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag>* node, const CC_ReliabilityMatrix& relmat) = 0;
00112 
00119     void back_track(CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag>* node_edge, std::vector<T_IOSymbol>& decoded_message, bool mark_nodes = false)
00120     {
00121         std::vector<T_IOSymbol> reversed_message;
00122         CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag> *cur_node_edge = node_edge;
00123         CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag> *incoming_node_edge;
00124 
00125         reversed_message.push_back(cur_node_edge->get_in_symbol());
00126 
00127         while (incoming_node_edge = (cur_node_edge->get_incoming_node_edge()))
00128         {
00129             cur_node_edge->set_on_final_path(mark_nodes);
00130 
00131             if (incoming_node_edge->get_depth() >= 0) // don't take root node
00132             {
00133                 reversed_message.push_back(incoming_node_edge->get_in_symbol());
00134             }
00135 
00136             cur_node_edge = incoming_node_edge;
00137         }
00138 
00139         decoded_message.resize(reversed_message.size());
00140         std::reverse_copy(reversed_message.begin(), reversed_message.end(), decoded_message.begin());
00141     }
00142 
00147     void print_dot_internal(std::ostream& os)
00148     {
00149         CC_TreeGraphviz<T_IOSymbol, T_Register, T_Tag>::create_dot(root_node, os);
00150     }
00151     
00152     CC_TreeNodeEdge<T_IOSymbol, T_Register, T_Tag> *root_node; 
00153 };
00154 
00155 
00156 } // namespace ccsoft
00157 
00158 
00159 #endif // __CC_SEQUENTIAL_DECODING_INERNAL_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines