ccsoft  0.0.0
Convolutional codes library with soft decision decoding
/shared/development/google_code/rssoft/libccsoft/lib/CC_SequentialDecoding_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_FA_H__
00025 #define __CC_SEQUENTIAL_DECODING_FA_H__
00026 
00027 #include "CC_Encoding_FA.h"
00028 #include "CC_ReliabilityMatrix.h"
00029 
00030 #include <cmath>
00031 #include <algorithm>
00032 #include <iostream>
00033 
00034 
00035 
00036 namespace ccsoft
00037 {
00038 
00042 class NodeEdgeOrdering
00043 {
00044 public:
00045         NodeEdgeOrdering(float _path_metric, unsigned int _node_id) :
00046         path_metric(_path_metric),
00047         node_id(_node_id)
00048     {}
00049 
00050     ~NodeEdgeOrdering()
00051     {}
00052 
00053     bool operator>(const NodeEdgeOrdering& other) const
00054     {
00055         if (path_metric == other.path_metric)
00056         {
00057             return node_id > other.node_id;
00058         }
00059         else
00060         {
00061             return path_metric > other.path_metric;
00062         }
00063     }
00064 
00065     float path_metric;
00066     unsigned int node_id;
00067 };
00068 
00069 template<typename T_NodeEdge>
00070 bool node_edge_pointer_ordering(T_NodeEdge* n1, T_NodeEdge* n2)
00071 {
00072     if (n1->get_path_metric() == n2->get_path_metric())
00073     {
00074         return n1->get_id() > n2->get_id();
00075     }
00076     else
00077     {
00078         return n1->get_path_metric() > n2->get_path_metric();
00079     }
00080 }
00081 
00090 template<typename T_Register, typename T_IOSymbol, unsigned int N_k>
00091 class CC_SequentialDecoding_FA
00092 {
00093 public:
00103         CC_SequentialDecoding_FA(const std::vector<unsigned int>& constraints,
00104             const std::vector<std::vector<T_Register> >& genpoly_representations) :
00105                 encoding(constraints, genpoly_representations),
00106                 use_metric_limit(false),
00107                 metric_limit(0.0),
00108                 use_node_limit(false),
00109                 node_limit(0),
00110                 codeword_score(0.0),
00111                 cur_depth(-1),
00112                 max_depth(0),
00113                 node_count(0),
00114                 tail_zeros(true),
00115                 edge_bias(0.0),
00116                 verbosity(0)
00117         {}
00118 
00122         virtual ~CC_SequentialDecoding_FA()
00123         {
00124         }
00125 
00129     void set_node_limit(unsigned int _node_limit)
00130     {
00131         node_limit = _node_limit;
00132         use_node_limit = true;
00133     }
00134 
00138     void reset_node_limit()
00139     {
00140         use_node_limit = false;
00141     }
00142 
00146     void set_metric_limit(float _metric_limit)
00147     {
00148         metric_limit = _metric_limit;
00149         use_metric_limit = true;
00150     }
00151 
00155     void reset_metric_limit()
00156     {
00157         use_metric_limit = false;
00158     }
00159 
00163     void set_tail_zeros(bool _tail_zeros)
00164     {
00165         tail_zeros = _tail_zeros;
00166     }
00167 
00171     void reset()
00172     {
00173         node_count = 0;
00174         codeword_score = 0.0;
00175         cur_depth = -1;
00176         max_depth = 0;
00177         encoding.clear(); // clear encoder's registers
00178     }
00179 
00183     CC_Encoding_FA<T_Register, T_IOSymbol, N_k>& get_encoding()
00184     {
00185         return encoding;
00186     }
00187 
00191     float get_score() const
00192     {
00193         return codeword_score;
00194     }
00195 
00199     float get_score_db_sym() const
00200     {
00201         if (cur_depth > 0)
00202         {
00203             return (10.0*log(2.0)*codeword_score) / cur_depth;
00204         }
00205         else
00206         {
00207             return 0.0;
00208         }
00209     }
00210 
00214     unsigned int get_nb_nodes() const
00215     {
00216         return node_count;
00217     }
00218 
00222     unsigned int get_current_depth() const
00223     {
00224         return cur_depth;
00225     }
00226 
00230     unsigned int get_max_depth() const
00231     {
00232         return max_depth;
00233     }
00234     
00238     void set_edge_bias(float _edge_bias)
00239     {
00240         edge_bias = _edge_bias;
00241     }
00242 
00246     void set_verbosity(unsigned int _verbosity)
00247     {
00248         verbosity = _verbosity;
00249     }
00250 
00255     virtual void print_dot(std::ostream& os) = 0;
00256     
00262     virtual void print_stats(std::ostream& os, bool success) = 0;
00263 
00269     virtual bool decode(const CC_ReliabilityMatrix& relmat, std::vector<T_IOSymbol>& decoded_message) = 0;
00270 
00271 protected:
00272     CC_Encoding_FA<T_Register, T_IOSymbol, N_k> encoding;   
00273     bool use_metric_limit;    
00274     float metric_limit;       
00275     bool use_node_limit;      
00276     unsigned int node_limit;  
00277     float codeword_score;     
00278     int cur_depth;            
00279     int max_depth;            
00280     unsigned int node_count;  
00281     bool tail_zeros;          
00282     float edge_bias;          
00283     unsigned int verbosity;   
00284 };
00285 
00286 } // namespace ccsoft
00287 
00288 
00289 #endif // __CC_SEQUENTIAL_DECODING_FA_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines