![]() |
ccsoft
0.0.0
Convolutional codes library with soft decision decoding
|
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_H__ 00025 #define __CC_SEQUENTIAL_DECODING_H__ 00026 00027 #include "CC_Encoding.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 00087 template<typename T_Register, typename T_IOSymbol> 00088 class CC_SequentialDecoding 00089 { 00090 public: 00100 CC_SequentialDecoding(const std::vector<unsigned int>& constraints, 00101 const std::vector<std::vector<T_Register> >& genpoly_representations) : 00102 encoding(constraints, genpoly_representations), 00103 use_metric_limit(false), 00104 metric_limit(0.0), 00105 use_node_limit(false), 00106 node_limit(0), 00107 codeword_score(0.0), 00108 cur_depth(-1), 00109 max_depth(0), 00110 node_count(0), 00111 tail_zeros(true), 00112 edge_bias(0.0), 00113 verbosity(0) 00114 {} 00115 00119 virtual ~CC_SequentialDecoding() 00120 { 00121 } 00122 00126 void set_node_limit(unsigned int _node_limit) 00127 { 00128 node_limit = _node_limit; 00129 use_node_limit = true; 00130 } 00131 00135 void reset_node_limit() 00136 { 00137 use_node_limit = false; 00138 } 00139 00143 void set_metric_limit(float _metric_limit) 00144 { 00145 metric_limit = _metric_limit; 00146 use_metric_limit = true; 00147 } 00148 00152 void reset_metric_limit() 00153 { 00154 use_metric_limit = false; 00155 } 00156 00160 void set_tail_zeros(bool _tail_zeros) 00161 { 00162 tail_zeros = _tail_zeros; 00163 } 00164 00168 void reset() 00169 { 00170 node_count = 0; 00171 codeword_score = 0.0; 00172 cur_depth = -1; 00173 max_depth = 0; 00174 encoding.clear(); // clear encoder's registers 00175 } 00176 00180 CC_Encoding<T_Register, T_IOSymbol>& get_encoding() 00181 { 00182 return encoding; 00183 } 00184 00188 float get_score() const 00189 { 00190 return codeword_score; 00191 } 00192 00196 float get_score_db_sym() const 00197 { 00198 if (cur_depth > 0) 00199 { 00200 return (10.0*log(2.0)*codeword_score) / cur_depth; 00201 } 00202 else 00203 { 00204 return 0.0; 00205 } 00206 } 00207 00211 unsigned int get_nb_nodes() const 00212 { 00213 return node_count; 00214 } 00215 00219 unsigned int get_current_depth() const 00220 { 00221 return cur_depth; 00222 } 00223 00227 unsigned int get_max_depth() const 00228 { 00229 return max_depth; 00230 } 00231 00235 void set_edge_bias(float _edge_bias) 00236 { 00237 edge_bias = _edge_bias; 00238 } 00239 00243 void set_verbosity(unsigned int _verbosity) 00244 { 00245 verbosity = _verbosity; 00246 } 00247 00252 virtual void print_dot(std::ostream& os) = 0; 00253 00259 virtual void print_stats(std::ostream& os, bool success) = 0; 00260 00266 virtual bool decode(const CC_ReliabilityMatrix& relmat, std::vector<T_IOSymbol>& decoded_message) = 0; 00267 00268 protected: 00269 CC_Encoding<T_Register, T_IOSymbol> encoding; 00270 bool use_metric_limit; 00271 float metric_limit; 00272 bool use_node_limit; 00273 unsigned int node_limit; 00274 float codeword_score; 00275 int cur_depth; 00276 int max_depth; 00277 unsigned int node_count; 00278 bool tail_zeros; 00279 float edge_bias; 00280 unsigned int verbosity; 00281 }; 00282 00283 } // namespace ccsoft 00284 00285 00286 #endif // __CC_SEQUENTIAL_DECODING_H__