diff options
Diffstat (limited to 'gr-trellis/src/lib')
-rw-r--r-- | gr-trellis/src/lib/.gitignore | 1 | ||||
-rw-r--r-- | gr-trellis/src/lib/Makefile.gen | 84 | ||||
-rw-r--r-- | gr-trellis/src/lib/core_algorithms.cc | 142 | ||||
-rw-r--r-- | gr-trellis/src/lib/core_algorithms.h | 26 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_sccc_decoder_combined_XX.cc.t | 333 |
5 files changed, 153 insertions, 433 deletions
diff --git a/gr-trellis/src/lib/.gitignore b/gr-trellis/src/lib/.gitignore index 7d6409ef2..35b6584c6 100644 --- a/gr-trellis/src/lib/.gitignore +++ b/gr-trellis/src/lib/.gitignore @@ -1,5 +1,6 @@ /Makefile /Makefile.in +/Makefile.gen /.la /.lo /.deps diff --git a/gr-trellis/src/lib/Makefile.gen b/gr-trellis/src/lib/Makefile.gen deleted file mode 100644 index 6a3f83387..000000000 --- a/gr-trellis/src/lib/Makefile.gen +++ /dev/null @@ -1,84 +0,0 @@ -# -# This file is machine generated. All edits will be overwritten -# -GENERATED_H = \ - trellis_encoder_bb.h \ - trellis_encoder_bi.h \ - trellis_encoder_bs.h \ - trellis_encoder_ii.h \ - trellis_encoder_si.h \ - trellis_encoder_ss.h \ - trellis_metrics_c.h \ - trellis_metrics_f.h \ - trellis_metrics_i.h \ - trellis_metrics_s.h \ - trellis_viterbi_b.h \ - trellis_viterbi_combined_cb.h \ - trellis_viterbi_combined_ci.h \ - trellis_viterbi_combined_cs.h \ - trellis_viterbi_combined_fb.h \ - trellis_viterbi_combined_fi.h \ - trellis_viterbi_combined_fs.h \ - trellis_viterbi_combined_ib.h \ - trellis_viterbi_combined_ii.h \ - trellis_viterbi_combined_is.h \ - trellis_viterbi_combined_sb.h \ - trellis_viterbi_combined_si.h \ - trellis_viterbi_combined_ss.h \ - trellis_viterbi_i.h \ - trellis_viterbi_s.h - -GENERATED_I = \ - trellis_encoder_bb.i \ - trellis_encoder_bi.i \ - trellis_encoder_bs.i \ - trellis_encoder_ii.i \ - trellis_encoder_si.i \ - trellis_encoder_ss.i \ - trellis_metrics_c.i \ - trellis_metrics_f.i \ - trellis_metrics_i.i \ - trellis_metrics_s.i \ - trellis_viterbi_b.i \ - trellis_viterbi_combined_cb.i \ - trellis_viterbi_combined_ci.i \ - trellis_viterbi_combined_cs.i \ - trellis_viterbi_combined_fb.i \ - trellis_viterbi_combined_fi.i \ - trellis_viterbi_combined_fs.i \ - trellis_viterbi_combined_ib.i \ - trellis_viterbi_combined_ii.i \ - trellis_viterbi_combined_is.i \ - trellis_viterbi_combined_sb.i \ - trellis_viterbi_combined_si.i \ - trellis_viterbi_combined_ss.i \ - trellis_viterbi_i.i \ - trellis_viterbi_s.i - -GENERATED_CC = \ - trellis_encoder_bb.cc \ - trellis_encoder_bi.cc \ - trellis_encoder_bs.cc \ - trellis_encoder_ii.cc \ - trellis_encoder_si.cc \ - trellis_encoder_ss.cc \ - trellis_metrics_c.cc \ - trellis_metrics_f.cc \ - trellis_metrics_i.cc \ - trellis_metrics_s.cc \ - trellis_viterbi_b.cc \ - trellis_viterbi_combined_cb.cc \ - trellis_viterbi_combined_ci.cc \ - trellis_viterbi_combined_cs.cc \ - trellis_viterbi_combined_fb.cc \ - trellis_viterbi_combined_fi.cc \ - trellis_viterbi_combined_fs.cc \ - trellis_viterbi_combined_ib.cc \ - trellis_viterbi_combined_ii.cc \ - trellis_viterbi_combined_is.cc \ - trellis_viterbi_combined_sb.cc \ - trellis_viterbi_combined_si.cc \ - trellis_viterbi_combined_ss.cc \ - trellis_viterbi_i.cc \ - trellis_viterbi_s.cc - diff --git a/gr-trellis/src/lib/core_algorithms.cc b/gr-trellis/src/lib/core_algorithms.cc index 41ecaf174..6c7187cff 100644 --- a/gr-trellis/src/lib/core_algorithms.cc +++ b/gr-trellis/src/lib/core_algorithms.cc @@ -27,6 +27,19 @@ static const float INF = 1.0e9; +float min(float a, float b) +{ + return a <= b ? a : b; +} + +float min_star(float a, float b) +{ + return (a <= b ? a : b)-log(1+exp(a <= b ? a-b : b-a)); +} + + + + template <class T> void viterbi_algorithm(int I, int S, int O, const std::vector<int> &NS, @@ -399,16 +412,6 @@ void viterbi_algorithm_combined<gr_complex,int>(int I, int S, int O, //=============================================== -inline float min(float a, float b) -{ - return a <= b ? a : b; -} - -inline float min_star(float a, float b) -{ - return (a <= b ? a : b)-log(1+exp(a <= b ? a-b : b-a)); - //return 0; -} void siso_algorithm(int I, int S, int O, const std::vector<int> &NS, @@ -557,6 +560,7 @@ else //=========================================================== +template <class T> void siso_algorithm_combined(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS, @@ -567,12 +571,10 @@ void siso_algorithm_combined(int I, int S, int O, bool POSTI, bool POSTO, float (*p2mymin)(float,float), int D, - const std::vector<float> &TABLE, + const std::vector<T> &TABLE, trellis_metric_type_t TYPE, - const float *priori, const float *observations, float *post//, - //std::vector<float> &alpha, - //std::vector<float> &beta - ) + const float *priori, const T *observations, float *post +) { float norm,mm,minm; std::vector<float> alpha(S*(K+1)); @@ -708,3 +710,113 @@ void siso_algorithm_combined(int I, int S, int O, } +//--------- + +template +void siso_algorithm_combined<short>(int I, int S, int O, + const std::vector<int> &NS, + const std::vector<int> &OS, + const std::vector< std::vector<int> > &PS, + const std::vector< std::vector<int> > &PI, + int K, + int S0,int SK, + bool POSTI, bool POSTO, + float (*p2mymin)(float,float), + int D, + const std::vector<short> &TABLE, + trellis_metric_type_t TYPE, + const float *priori, const short *observations, float *post +); + +template +void siso_algorithm_combined<int>(int I, int S, int O, + const std::vector<int> &NS, + const std::vector<int> &OS, + const std::vector< std::vector<int> > &PS, + const std::vector< std::vector<int> > &PI, + int K, + int S0,int SK, + bool POSTI, bool POSTO, + float (*p2mymin)(float,float), + int D, + const std::vector<int> &TABLE, + trellis_metric_type_t TYPE, + const float *priori, const int *observations, float *post +); + +template +void siso_algorithm_combined<float>(int I, int S, int O, + const std::vector<int> &NS, + const std::vector<int> &OS, + const std::vector< std::vector<int> > &PS, + const std::vector< std::vector<int> > &PI, + int K, + int S0,int SK, + bool POSTI, bool POSTO, + float (*p2mymin)(float,float), + int D, + const std::vector<float> &TABLE, + trellis_metric_type_t TYPE, + const float *priori, const float *observations, float *post +); + +template +void siso_algorithm_combined<gr_complex>(int I, int S, int O, + const std::vector<int> &NS, + const std::vector<int> &OS, + const std::vector< std::vector<int> > &PS, + const std::vector< std::vector<int> > &PI, + int K, + int S0,int SK, + bool POSTI, bool POSTO, + float (*p2mymin)(float,float), + int D, + const std::vector<gr_complex> &TABLE, + trellis_metric_type_t TYPE, + const float *priori, const gr_complex *observations, float *post +); + +//========================================================= + +template<class Ti, class To> +void sccc_decoder_combined( + const fsm &FSMo, int STo0, int SToK, + const fsm &FSMi, int STi0, int STiK, + const interleaver &INTERLEAVER, int blocklength, int repetitions, + float (*p2mymin)(float,float), + int D, const std::vector<Ti> &TABLE, + trellis_metric_type_t METRIC_TYPE, + const Ti *observations, To *data +) +{ + +// to be implemented + +} + +//------- + +template +void sccc_decoder_combined<short,short>( + const fsm &FSMo, int STo0, int SToK, + const fsm &FSMi, int STi0, int STiK, + const interleaver &INTERLEAVER, int blocklength, int repetitions, + float (*p2mymin)(float,float), + int D, const std::vector<short> &TABLE, + trellis_metric_type_t METRIC_TYPE, + const short *observations, short *data +); + +template +void sccc_decoder_combined<int,int>( + const fsm &FSMo, int STo0, int SToK, + const fsm &FSMi, int STi0, int STiK, + const interleaver &INTERLEAVER, int blocklength, int repetitions, + float (*p2mymin)(float,float), + int D, const std::vector<int> &TABLE, + trellis_metric_type_t METRIC_TYPE, + const int *observations, int *data +); + + + diff --git a/gr-trellis/src/lib/core_algorithms.h b/gr-trellis/src/lib/core_algorithms.h index 77b27b797..ad1b48057 100644 --- a/gr-trellis/src/lib/core_algorithms.h +++ b/gr-trellis/src/lib/core_algorithms.h @@ -27,10 +27,12 @@ #include <vector> //#include <gr_complex.h> #include "metric_type.h" +#include "fsm.h" +#include "interleaver.h" -inline float min(float a, float b); -inline float min_star(float a, float b); +float min(float a, float b); +float min_star(float a, float b); template <class T> void viterbi_algorithm(int I, int S, int O, @@ -72,6 +74,7 @@ void siso_algorithm(int I, int S, int O, ); +template <class T> void siso_algorithm_combined(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS, @@ -82,10 +85,25 @@ void siso_algorithm_combined(int I, int S, int O, bool POSTI, bool POSTO, float (*p2mymin)(float,float), int D, - const std::vector<float> &TABLE, + const std::vector<T> &TABLE, trellis_metric_type_t TYPE, - const float *priori, const float *observations, float *post + const float *priori, const T *observations, float *post ); +template<class Ti, class To> +void sccc_decoder_combined( + const fsm &FSMo, int STo0, int SToK, + const fsm &FSMi, int STi0, int STiK, + const interleaver &INTERLEAVER, int blocklength, int repetitions, + float (*p2mymin)(float,float), + int D, const std::vector<Ti> &TABLE, + trellis_metric_type_t METRIC_TYPE, + const Ti *observations, To *data +); + + + + + #endif diff --git a/gr-trellis/src/lib/trellis_sccc_decoder_combined_XX.cc.t b/gr-trellis/src/lib/trellis_sccc_decoder_combined_XX.cc.t index c23445e61..f354197dd 100644 --- a/gr-trellis/src/lib/trellis_sccc_decoder_combined_XX.cc.t +++ b/gr-trellis/src/lib/trellis_sccc_decoder_combined_XX.cc.t @@ -30,6 +30,8 @@ #include <gr_io_signature.h> #include <assert.h> #include <iostream> +#include "core_algorithms.h" + static const float INF = 1.0e9; @@ -73,7 +75,7 @@ trellis_make_@BASE_NAME@ ( gr_make_io_signature (1, 1, sizeof (@I_TYPE@)), gr_make_io_signature (1, 1, sizeof (@O_TYPE@))), d_FSMo (FSMo), d_STo0 (STo0), d_SToK (SToK), - d_FSMi (FSMo), d_STi0 (STi0), d_STiK (STiK), + d_FSMi (FSMi), d_STi0 (STi0), d_STiK (STiK), d_INTERLEAVER (INTERLEAVER), d_blocklength (blocklength), d_repetitions (repetitions), @@ -98,337 +100,8 @@ void } } -//======================================= - -inline float min(float a, float b) -{ - return a <= b ? a : b; -} - -inline float min_star(float a, float b) -{ - return (a <= b ? a : b)-log(1+exp(a <= b ? a-b : b-a)); -} - - -//======================================= - -void siso_outer_algorithm(int I, int S, int O, - const std::vector<int> &NS, - const std::vector<int> &OS, - const std::vector< std::vector<int> > &PS, - const std::vector< std::vector<int> > &PI, - int K, - int S0,int SK, - bool POSTI, bool POSTO, - float (*p2mymin)(float,float), - const float *priori, const float *prioro, float *post, - @O_TYPE@ *data - ) -{ - float norm,mm,minm; - std::vector<float> alpha(S*(K+1)); - std::vector<float> beta(S*(K+1)); - - - if(S0<0) { // initial state not specified - for(int i=0;i<S;i++) alpha[0*S+i]=0; - } - else { - for(int i=0;i<S;i++) alpha[0*S+i]=INF; - alpha[0*S+S0]=0.0; - } - - for(int k=0;k<K;k++) { // forward recursion - norm=INF; - for(int j=0;j<S;j++) { - minm=INF; - for(unsigned int i=0;i<PS[j].size();i++) { - //int i0 = j*I+i; - mm=alpha[k*S+PS[j][i]]+priori[k*I+PI[j][i]]+prioro[k*O+OS[PS[j][i]*I+PI[j][i]]]; - minm=(*p2mymin)(minm,mm); - } - alpha[(k+1)*S+j]=minm; - if(minm<norm) norm=minm; - } - for(int j=0;j<S;j++) - alpha[(k+1)*S+j]-=norm; // normalize total metrics so they do not explode - } - - if(SK<0) { // final state not specified - for(int i=0;i<S;i++) beta[K*S+i]=0; - } - else { - for(int i=0;i<S;i++) beta[K*S+i]=INF; - beta[K*S+SK]=0.0; - } - - for(int k=K-1;k>=0;k--) { // backward recursion - norm=INF; - for(int j=0;j<S;j++) { - minm=INF; - for(int i=0;i<I;i++) { - int i0 = j*I+i; - mm=beta[(k+1)*S+NS[i0]]+priori[k*I+i]+prioro[k*O+OS[i0]]; - minm=(*p2mymin)(minm,mm); - } - beta[k*S+j]=minm; - if(minm<norm) norm=minm; - } - for(int j=0;j<S;j++) - beta[k*S+j]-=norm; // normalize total metrics so they do not explode - } - -if (POSTI && POSTO) -{ - for(int k=0;k<K;k++) { // input combining - norm=INF; - for(int i=0;i<I;i++) { - minm=INF; - for(int j=0;j<S;j++) { - mm=alpha[k*S+j]+prioro[k*O+OS[j*I+i]]+beta[(k+1)*S+NS[j*I+i]]; - minm=(*p2mymin)(minm,mm); - } - post[k*(I+O)+i]=minm; - if(minm<norm) norm=minm; - } - for(int i=0;i<I;i++) - post[k*(I+O)+i]-=norm; // normalize metrics - } - - - for(int k=0;k<K;k++) { // output combining - norm=INF; - for(int n=0;n<O;n++) { - minm=INF; - for(int j=0;j<S;j++) { - for(int i=0;i<I;i++) { - mm= (n==OS[j*I+i] ? alpha[k*S+j]+priori[k*I+i]+beta[(k+1)*S+NS[j*I+i]] : INF); - minm=(*p2mymin)(minm,mm); - } - } - post[k*(I+O)+I+n]=minm; - if(minm<norm) norm=minm; - } - for(int n=0;n<O;n++) - post[k*(I+O)+I+n]-=norm; // normalize metrics - } -} -else if(POSTI) -{ - for(int k=0;k<K;k++) { // input combining - norm=INF; - for(int i=0;i<I;i++) { - minm=INF; - for(int j=0;j<S;j++) { - mm=alpha[k*S+j]+prioro[k*O+OS[j*I+i]]+beta[(k+1)*S+NS[j*I+i]]; - minm=(*p2mymin)(minm,mm); - } - post[k*I+i]=minm; - if(minm<norm) norm=minm; - } - for(int i=0;i<I;i++) - post[k*I+i]-=norm; // normalize metrics - } -} -else if(POSTO) -{ - for(int k=0;k<K;k++) { // output combining - norm=INF; - for(int n=0;n<O;n++) { - minm=INF; - for(int j=0;j<S;j++) { - for(int i=0;i<I;i++) { - mm= (n==OS[j*I+i] ? alpha[k*S+j]+priori[k*I+i]+beta[(k+1)*S+NS[j*I+i]] : INF); - minm=(*p2mymin)(minm,mm); - } - } - post[k*O+n]=minm; - if(minm<norm) norm=minm; - } - for(int n=0;n<O;n++) - post[k*O+n]-=norm; // normalize metrics - } -} -else - throw std::runtime_error ("Not both POSTI and POSTO can be false."); - -} - -//================================== - -void siso_inner_algorithm_combined(int I, int S, int O, - const std::vector<int> &NS, - const std::vector<int> &OS, - const std::vector< std::vector<int> > &PS, - const std::vector< std::vector<int> > &PI, - int K, - int S0,int SK, - bool POSTI, bool POSTO, - float (*p2mymin)(float,float), - int D, - const std::vector<@I_TYPE@> &TABLE, - trellis_metric_type_t TYPE, - const float *priori, const @I_TYPE@ *observations, float *post - ) -{ - float norm,mm,minm; - std::vector<float> alpha(S*(K+1)); - std::vector<float> beta(S*(K+1)); - float *prioro = new float[O*K]; - - - if(S0<0) { // initial state not specified - for(int i=0;i<S;i++) alpha[0*S+i]=0; - } - else { - for(int i=0;i<S;i++) alpha[0*S+i]=INF; - alpha[0*S+S0]=0.0; - } - - for(int k=0;k<K;k++) { // forward recursion - calc_metric(O, D, TABLE, &(observations[k*D]), &(prioro[k*O]),TYPE); // calc metrics - norm=INF; - for(int j=0;j<S;j++) { - minm=INF; - for(unsigned int i=0;i<PS[j].size();i++) { - //int i0 = j*I+i; - mm=alpha[k*S+PS[j][i]]+priori[k*I+PI[j][i]]+prioro[k*O+OS[PS[j][i]*I+PI[j][i]]]; - minm=(*p2mymin)(minm,mm); - } - alpha[(k+1)*S+j]=minm; - if(minm<norm) norm=minm; - } - for(int j=0;j<S;j++) - alpha[(k+1)*S+j]-=norm; // normalize total metrics so they do not explode - } - - if(SK<0) { // final state not specified - for(int i=0;i<S;i++) beta[K*S+i]=0; - } - else { - for(int i=0;i<S;i++) beta[K*S+i]=INF; - beta[K*S+SK]=0.0; - } - - for(int k=K-1;k>=0;k--) { // backward recursion - norm=INF; - for(int j=0;j<S;j++) { - minm=INF; - for(int i=0;i<I;i++) { - int i0 = j*I+i; - mm=beta[(k+1)*S+NS[i0]]+priori[k*I+i]+prioro[k*O+OS[i0]]; - minm=(*p2mymin)(minm,mm); - } - beta[k*S+j]=minm; - if(minm<norm) norm=minm; - } - for(int j=0;j<S;j++) - beta[k*S+j]-=norm; // normalize total metrics so they do not explode - } - - - if (POSTI && POSTO) - { - for(int k=0;k<K;k++) { // input combining - norm=INF; - for(int i=0;i<I;i++) { - minm=INF; - for(int j=0;j<S;j++) { - mm=alpha[k*S+j]+prioro[k*O+OS[j*I+i]]+beta[(k+1)*S+NS[j*I+i]]; - minm=(*p2mymin)(minm,mm); - } - post[k*(I+O)+i]=minm; - if(minm<norm) norm=minm; - } - for(int i=0;i<I;i++) - post[k*(I+O)+i]-=norm; // normalize metrics - } - - - for(int k=0;k<K;k++) { // output combining - norm=INF; - for(int n=0;n<O;n++) { - minm=INF; - for(int j=0;j<S;j++) { - for(int i=0;i<I;i++) { - mm= (n==OS[j*I+i] ? alpha[k*S+j]+priori[k*I+i]+beta[(k+1)*S+NS[j*I+i]] : INF); - minm=(*p2mymin)(minm,mm); - } - } - post[k*(I+O)+I+n]=minm; - if(minm<norm) norm=minm; - } - for(int n=0;n<O;n++) - post[k*(I+O)+I+n]-=norm; // normalize metrics - } - } - else if(POSTI) - { - for(int k=0;k<K;k++) { // input combining - norm=INF; - for(int i=0;i<I;i++) { - minm=INF; - for(int j=0;j<S;j++) { - mm=alpha[k*S+j]+prioro[k*O+OS[j*I+i]]+beta[(k+1)*S+NS[j*I+i]]; - minm=(*p2mymin)(minm,mm); - } - post[k*I+i]=minm; - if(minm<norm) norm=minm; - } - for(int i=0;i<I;i++) - post[k*I+i]-=norm; // normalize metrics - } - } - else if(POSTO) - { - for(int k=0;k<K;k++) { // output combining - norm=INF; - for(int n=0;n<O;n++) { - minm=INF; - for(int j=0;j<S;j++) { - for(int i=0;i<I;i++) { - mm= (n==OS[j*I+i] ? alpha[k*S+j]+priori[k*I+i]+beta[(k+1)*S+NS[j*I+i]] : INF); - minm=(*p2mymin)(minm,mm); - } - } - post[k*O+n]=minm; - if(minm<norm) norm=minm; - } - for(int n=0;n<O;n++) - post[k*O+n]-=norm; // normalize metrics - } - } - else - throw std::runtime_error ("Not both POSTI and POSTO can be false."); - - delete [] prioro; - -} - - -//========================================================== - - -void sccc_decoder_combined( - const fsm &FSMo, int STo0, int SToK, - const fsm &FSMi, int STi0, int STiK, - const interleaver &INTERLEAVER, int blocklength, int repetitions, - float (*p2mymin)(float,float), - int D, const std::vector<@I_TYPE@> &TABLE, - trellis_metric_type_t METRIC_TYPE, - const @I_TYPE@ *observations, @O_TYPE@ *data - ) -{ - - - - -} - - //d_FSMo.I(),d_FSMo.S(),d_FSMo.O(),d_FSMo.NS(),d_FSMo.OS(),d_FSMo.PS(),d_FSMo.PI(), //=========================================================== int |