include/it/convcode.h

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2008 Francois Cayre, Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   Base class for convolutional codes.
00022   Vivien Chappelier <vivien.chappelier@irisa.fr>
00023 */
00024 
00025 #ifndef __it_convcode_h
00026 #define __it_convcode_h
00027 
00028 #include <it/types.h>
00029 #include <it/mat.h>
00030 #include <it/vec.h>
00031 
00032 
00033 /*---------------------------------------------------------------------------*/
00034 /*! \defgroup convcode Convolutional Codes                                   */
00035 /* @{                                                                        */
00036 /*---------------------------------------------------------------------------*/
00037 
00038 /* Generic convolutional code class */
00039 typedef struct _convolutional_code_ {
00040   it_extends (it_object_t);
00041 
00042   /* overload the virtual destructor */
00043   void (*it_overloaded (destructor)) (it_object_t * it_this);
00044 
00045   /* Encode a binary vector with the convolutional code */
00046 
00047 
00048        
00049   bvec (*encode) (struct _convolutional_code_ * convolutional_code,
00050       bvec v);
00051 
00052   /* Encode a 2^k-valued vector to a 2^n-valued vector */
00053 
00054   ivec (*encode_symbolic) (struct _convolutional_code_ * cc, ivec b);
00055 
00056   int  k;     /* input bits */
00057   int  n;     /* output bits */
00058   int  memory;    /* memory of the code */
00059   int  n_labels;
00060   int  n_states;
00061   int  n_symbols;
00062 
00063   vec  logalpha_0;    /* starting logprobabilities */
00064   vec  logbeta_end;   /* ending logprobabilities */
00065   mat  next_state_logpt;  /* transition logprobabilities */
00066   imat automaton;   /* next state   [n_branches][n_states] */
00067   imat output;    /* output       [1 << k][n_states]     */
00068   imat input;     /* input        [1 << n][n_states]     */
00069 
00070   int  Q;     /* feedback polynomial Q (O=non-recursive) */
00071   imat generators;    /* generator polynomials */
00072 
00073 } it_convolutional_code_t;
00074 
00075 #define IT_CONVOLUTIONAL_CODE(q) IT_CAST(it_convolutional_code_t, q)
00076 
00077 it_instanciate (it_convolutional_code_t);
00078 
00079 /* create a new convolutional code from its generator polynomials */
00080 /* and feedback polynomial. For non-recursive codes, set feedback to zero. */
00081 static inline it_convolutional_code_t *it_convolutional_code_new (imat
00082                   generators,
00083                   int
00084                   feedback) {
00085   return (it_new_va (it_convolutional_code_t)
00086     (it_va, generators, feedback));
00087 }
00088 #define it_convolutional_code_encode(it_this, b) __it_convolutional_code_encode(IT_CONVOLUTIONAL_CODE(it_this), b)
00089 static inline bvec __it_convolutional_code_encode (it_convolutional_code_t
00090                * it_this, bvec b) {
00091   return (it_this->encode (it_this, b));
00092 }
00093 
00094 #define it_convolutional_code_encode_symbolic(it_this, b) __it_convolutional_code_encode_symbolic(IT_CONVOLUTIONAL_CODE(it_this), b)
00095 static inline ivec
00096 __it_convolutional_code_encode_symbolic (it_convolutional_code_t *
00097            it_this, ivec b) {
00098   return (it_this->encode_symbolic (it_this, b));
00099 }
00100 
00101 static inline int
00102 it_convolutional_code_trellis_label (it_convolutional_code_t * cc,
00103              int state, int symbol) {
00104   return (cc->output[symbol][state]);
00105 }
00106 
00107 static inline int
00108 it_convolutional_code_trellis_next (it_convolutional_code_t * cc,
00109             int state, int symbol) {
00110   return (cc->
00111     automaton[it_convolutional_code_trellis_label (cc, state, symbol)]
00112     [state]);
00113 }
00114 
00115 /* shortnames for some functions */
00116 #define it_cc_encode(cc, b) it_convolutional_code_encode(cc, b)
00117 #define it_cc_encode_symbolic(cc, b) it_convolutional_code_encode_symbolic(cc, b)
00118 #define it_cc_decode(cc, v) it_convolutional_code_decode(cc, v)
00119 #define it_cc_next(cc, s, b)  it_convolutional_code_trellis_next(cc, s, b)
00120 #define it_cc_label(cc, s, b) it_convolutional_code_trellis_label(cc, s, b)
00121 
00122 /* helper functions */
00123 ivec it_viterbi_decode_symbolic (it_convolutional_code_t * cc, mat metrics);
00124 bvec it_viterbi_decode (it_convolutional_code_t * cc, mat metrics);
00125 
00126 /* @} */
00127 
00128 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau