diff options
Diffstat (limited to 'gr-trellis/lib')
-rw-r--r-- | gr-trellis/lib/calc_metric.cc | 17 | ||||
-rw-r--r-- | gr-trellis/lib/core_algorithms.cc | 39 | ||||
-rw-r--r-- | gr-trellis/lib/encoder_XX_impl.h.t | 7 | ||||
-rw-r--r-- | gr-trellis/lib/fsm.cc | 48 | ||||
-rw-r--r-- | gr-trellis/lib/metrics_X_impl.cc.t | 22 | ||||
-rw-r--r-- | gr-trellis/lib/metrics_X_impl.h.t | 4 | ||||
-rw-r--r-- | gr-trellis/lib/permutation_impl.cc | 14 | ||||
-rw-r--r-- | gr-trellis/lib/permutation_impl.h | 6 | ||||
-rw-r--r-- | gr-trellis/lib/siso_combined_f_impl.cc | 75 | ||||
-rw-r--r-- | gr-trellis/lib/siso_combined_f_impl.h | 12 | ||||
-rw-r--r-- | gr-trellis/lib/siso_f_impl.cc | 57 | ||||
-rw-r--r-- | gr-trellis/lib/siso_f_impl.h | 9 | ||||
-rw-r--r-- | gr-trellis/lib/viterbi_X_impl.cc.t | 12 | ||||
-rw-r--r-- | gr-trellis/lib/viterbi_X_impl.h.t | 12 | ||||
-rw-r--r-- | gr-trellis/lib/viterbi_combined_XX_impl.cc.t | 14 | ||||
-rw-r--r-- | gr-trellis/lib/viterbi_combined_XX_impl.h.t | 19 |
16 files changed, 306 insertions, 61 deletions
diff --git a/gr-trellis/lib/calc_metric.cc b/gr-trellis/lib/calc_metric.cc index b95899940a..bdbb13ea08 100644 --- a/gr-trellis/lib/calc_metric.cc +++ b/gr-trellis/lib/calc_metric.cc @@ -73,19 +73,17 @@ namespace gr { } template - void calc_metric<short>(int O, int D, const std::vector<short> &TABLE, const short *input, - float *metric, digital::trellis_metric_type_t type); + void calc_metric<char>(int O, int D, const std::vector<char> &TABLE, const char *input, float *metric, digital::trellis_metric_type_t type); template - void calc_metric<int>(int O, int D, const std::vector<int> &TABLE, const int *input, - float *metric, digital::trellis_metric_type_t type); + void calc_metric<short>(int O, int D, const std::vector<short> &TABLE, const short *input, float *metric, digital::trellis_metric_type_t type); - template - void calc_metric<float>(int O, int D, const std::vector<float> &TABLE, const float *input, - float *metric, digital::trellis_metric_type_t type); + template void calc_metric<int>(int O, int D, const std::vector<int> &TABLE, const int *input, float *metric, digital::trellis_metric_type_t type); - void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *input, - float *metric, digital::trellis_metric_type_t type) + template void calc_metric<float>(int O, int D, const std::vector<float> &TABLE, const float *input, float *metric, digital::trellis_metric_type_t type); + + /* + void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *input, float *metric, digital::trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -124,7 +122,6 @@ namespace gr { } } - /* void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *input, float *metric, digital::trellis_metric_type_t type) { diff --git a/gr-trellis/lib/core_algorithms.cc b/gr-trellis/lib/core_algorithms.cc index a8a0174551..eb32b65de7 100644 --- a/gr-trellis/lib/core_algorithms.cc +++ b/gr-trellis/lib/core_algorithms.cc @@ -215,6 +215,19 @@ namespace gr { //--------------- template void + viterbi_algorithm_combined<char,unsigned char>(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, + int D, + const std::vector<char> &TABLE, + digital::trellis_metric_type_t TYPE, + const char *in, unsigned char *out); + + template void viterbi_algorithm_combined<short,unsigned char>(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS, @@ -269,6 +282,19 @@ namespace gr { //--------------- template void + viterbi_algorithm_combined<char,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, + int D, + const std::vector<char> &TABLE, + digital::trellis_metric_type_t TYPE, + const char *in, short *out); + + template void viterbi_algorithm_combined<short,short>(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS, @@ -323,6 +349,19 @@ namespace gr { //-------------- template void + viterbi_algorithm_combined<char,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, + int D, + const std::vector<char> &TABLE, + digital::trellis_metric_type_t TYPE, + const char *in, int *out); + + template void viterbi_algorithm_combined<short,int>(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS, diff --git a/gr-trellis/lib/encoder_XX_impl.h.t b/gr-trellis/lib/encoder_XX_impl.h.t index ec2f82611e..d58f9b0a87 100644 --- a/gr-trellis/lib/encoder_XX_impl.h.t +++ b/gr-trellis/lib/encoder_XX_impl.h.t @@ -40,8 +40,11 @@ namespace gr { @IMPL_NAME@(const fsm &FSM, int ST); ~@IMPL_NAME@(); - fsm FSM() const { return d_FSM; } - int ST() const { return d_ST; } + fsm FSM() { return d_FSM;; } + int ST() { return d_ST; } + + void set_FSM(fsm &FSM) { d_FSM = FSM; } + void set_ST(int ST) { d_ST = ST; } int work(int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-trellis/lib/fsm.cc b/gr-trellis/lib/fsm.cc index 20eeed5c25..4e57949f5e 100644 --- a/gr-trellis/lib/fsm.cc +++ b/gr-trellis/lib/fsm.cc @@ -313,6 +313,54 @@ namespace gr { generate_TM(); } + + //###################################################################### + //# Automatically generate an FSM specification describing the + //# the joint trellis of two serially concatenated fsms. + //###################################################################### + fsm::fsm(const fsm &FSMo, const fsm &FSMi, bool serial) + { + if(serial==false || FSMo.O()!=FSMi.I()) { + d_I=0; + d_S=0; + d_O=0; + d_NS.resize(0); + d_OS.resize(0); + d_PS.resize(0); + d_PI.resize(0); + d_TMi.resize(0); + d_TMl.resize(0); + return; + } + + d_I=FSMo.I(); + d_S=FSMo.S()*FSMi.S(); + d_O=FSMi.O(); + + d_NS.resize(d_I*d_S); + d_OS.resize(d_I*d_S); + + for(int s=0;s<d_S;s++) { + for(int i=0;i<d_I;i++) { + int so=s/FSMi.S(); + int si=s%FSMi.S(); + int oo=FSMo.OS()[so * FSMo.I() + i]; + int oi=FSMi.OS()[si * FSMi.I() + oo]; + d_NS[s*d_I+i] = FSMo.NS()[so * FSMo.I() + i] * FSMo.S() + FSMi.NS()[si * FSMi.I() + oo]; + d_OS[s*d_I+i] = oi; + } + } + + generate_PS_PI(); + generate_TM(); + } + + + + + + + //###################################################################### //# Generate a new FSM representing n stages through the original FSM //# AKA radix-n FSM diff --git a/gr-trellis/lib/metrics_X_impl.cc.t b/gr-trellis/lib/metrics_X_impl.cc.t index 499bd8b9cd..2b811de16f 100644 --- a/gr-trellis/lib/metrics_X_impl.cc.t +++ b/gr-trellis/lib/metrics_X_impl.cc.t @@ -54,8 +54,23 @@ namespace gr { set_output_multiple ((int)d_O); } - @IMPL_NAME@::~@IMPL_NAME@() + void @IMPL_NAME@::set_O(int O) + { + d_O = O; + set_relative_rate (1.0 * d_O / ((double) d_D)); + set_output_multiple ((int)d_O); + } + + void @IMPL_NAME@::set_D(int D) + { + d_D = D; + set_relative_rate (1.0 * d_O / ((double) d_D)); + } + + void + @IMPL_NAME@::set_TYPE(digital::trellis_metric_type_t type) { + d_TYPE = type; } void @@ -64,6 +79,11 @@ namespace gr { d_TABLE = table; } + @IMPL_NAME@::~@IMPL_NAME@() + { + } + + void @IMPL_NAME@::forecast(int noutput_items, gr_vector_int &ninput_items_required) { diff --git a/gr-trellis/lib/metrics_X_impl.h.t b/gr-trellis/lib/metrics_X_impl.h.t index 2b4481fdb1..9323ae4645 100644 --- a/gr-trellis/lib/metrics_X_impl.h.t +++ b/gr-trellis/lib/metrics_X_impl.h.t @@ -47,6 +47,10 @@ namespace gr { int D() const { return d_D; } digital::trellis_metric_type_t TYPE() const { return d_TYPE; } std::vector<@I_TYPE@> TABLE() const { return d_TABLE; } + + void set_O(int O); + void set_D(int D); + void set_TYPE(digital::trellis_metric_type_t type); void set_TABLE(const std::vector<@I_TYPE@> &table); void forecast(int noutput_items, diff --git a/gr-trellis/lib/permutation_impl.cc b/gr-trellis/lib/permutation_impl.cc index 06bba1e11f..0d9d3593bf 100644 --- a/gr-trellis/lib/permutation_impl.cc +++ b/gr-trellis/lib/permutation_impl.cc @@ -49,10 +49,22 @@ namespace gr { d_SYMS_PER_BLOCK(SYMS_PER_BLOCK), d_BYTES_PER_SYMBOL(BYTES_PER_SYMBOL) { - set_output_multiple(d_K*SYMS_PER_BLOCK); + set_output_multiple(d_K*d_SYMS_PER_BLOCK); //std::cout << d_K << "\n"; } + void permutation_impl::set_K(int K) + { + d_K=K; + set_output_multiple(d_K*d_SYMS_PER_BLOCK); + } + + void permutation_impl::set_SYMS_PER_BLOCK(int spb) + { + d_SYMS_PER_BLOCK=spb; + set_output_multiple(d_K*d_SYMS_PER_BLOCK); + } + permutation_impl::~permutation_impl() { } diff --git a/gr-trellis/lib/permutation_impl.h b/gr-trellis/lib/permutation_impl.h index 2c7b28d62f..5c74fba8fd 100644 --- a/gr-trellis/lib/permutation_impl.h +++ b/gr-trellis/lib/permutation_impl.h @@ -43,10 +43,14 @@ namespace gr { ~permutation_impl(); int K() const { return d_K; } - const std::vector<int> & TABLE() const { return d_TABLE; } + std::vector<int> TABLE() const { return d_TABLE; } int SYMS_PER_BLOCK() const { return d_SYMS_PER_BLOCK; } size_t BYTES_PER_SYMBOL() const { return d_BYTES_PER_SYMBOL; } + void set_K(int K) ; + void set_TABLE (const std::vector<int> &table) {d_TABLE = table; } + void set_SYMS_PER_BLOCK(int spb) ; + int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); diff --git a/gr-trellis/lib/siso_combined_f_impl.cc b/gr-trellis/lib/siso_combined_f_impl.cc index d30f5cc4bb..f9e8e28a9c 100644 --- a/gr-trellis/lib/siso_combined_f_impl.cc +++ b/gr-trellis/lib/siso_combined_f_impl.cc @@ -48,23 +48,9 @@ namespace gr { SISO_TYPE, D, TABLE, TYPE)); } - siso_combined_f_impl::siso_combined_f_impl(const fsm &FSM, int K, - int S0, int SK, - bool POSTI, bool POSTO, - siso_type_t SISO_TYPE, - int D, const std::vector<float> &TABLE, - digital::trellis_metric_type_t TYPE) - : block("siso_combined_f", - io_signature::make(1, -1, sizeof(float)), - io_signature::make(1, -1, sizeof(float))), - d_FSM(FSM), d_K(K), d_S0(S0), d_SK(SK), - d_POSTI(POSTI), d_POSTO(POSTO), - d_SISO_TYPE(SISO_TYPE), - d_D(D), d_TABLE(TABLE), d_TYPE(TYPE)//, - //d_alpha(FSM.S()*(K+1)), - //d_beta(FSM.S()*(K+1)) + void siso_combined_f_impl::recalculate() { - int multiple; + int multiple; if(d_POSTI && d_POSTO) multiple = d_FSM.I()+d_FSM.O(); else if(d_POSTI) @@ -74,7 +60,6 @@ namespace gr { else throw std::runtime_error ("Not both POSTI and POSTO can be false."); - //printf("constructor: Multiple = %d\n",multiple); set_output_multiple(d_K*multiple); //what is the meaning of relative rate for a block with 2 inputs? @@ -84,11 +69,63 @@ namespace gr { //set_relative_rate ( multiple / ((double) d_FSM.O()) ); // I am tempted to automate like this if(d_FSM.I() <= d_D) - set_relative_rate(multiple / ((double)d_D)); + set_relative_rate(multiple / ((double)d_D)); else - set_relative_rate(multiple / ((double)d_FSM.I())); + set_relative_rate(multiple / ((double)d_FSM.I())); + } + + + siso_combined_f_impl::siso_combined_f_impl(const fsm &FSM, int K, + int S0, int SK, + bool POSTI, bool POSTO, + siso_type_t SISO_TYPE, + int D, const std::vector<float> &TABLE, + digital::trellis_metric_type_t TYPE) + : block("siso_combined_f", + io_signature::make(1, -1, sizeof(float)), + io_signature::make(1, -1, sizeof(float))), + d_FSM(FSM), d_K(K), d_S0(S0), d_SK(SK), + d_POSTI(POSTI), d_POSTO(POSTO), + d_SISO_TYPE(SISO_TYPE), + d_D(D), d_TABLE(TABLE), d_TYPE(TYPE)//, + //d_alpha(FSM.S()*(K+1)), + //d_beta(FSM.S()*(K+1)) + { + recalculate(); + } + + void siso_combined_f_impl::set_FSM(const fsm &FSM) + { + d_FSM=FSM; + recalculate(); } + void siso_combined_f_impl::set_K(int K) + { + d_K=K; + recalculate(); + } + + void siso_combined_f_impl::set_POSTI(bool POSTI) + { + d_POSTI = POSTI; + recalculate(); + } + + void siso_combined_f_impl::set_POSTO(bool POSTO) + { + d_POSTO = POSTO; + recalculate(); + } + + void siso_combined_f_impl::set_D(int D) + { + d_D=D; + recalculate(); + } + + + siso_combined_f_impl::~siso_combined_f_impl() { } diff --git a/gr-trellis/lib/siso_combined_f_impl.h b/gr-trellis/lib/siso_combined_f_impl.h index 5035a0a83d..9457637259 100644 --- a/gr-trellis/lib/siso_combined_f_impl.h +++ b/gr-trellis/lib/siso_combined_f_impl.h @@ -41,6 +41,7 @@ namespace gr { int d_D; std::vector<float> d_TABLE; digital::trellis_metric_type_t d_TYPE; + void recalculate(); //std::vector<float> d_alpha; //std::vector<float> d_beta; @@ -64,6 +65,17 @@ namespace gr { std::vector<float> TABLE() const { return d_TABLE; } digital::trellis_metric_type_t TYPE() const { return d_TYPE; } + void set_FSM(const fsm &FSM); + void set_K(int K); + void set_S0(int S0){ d_S0 = S0; } + void set_SK(int SK){ d_SK = SK; } + void set_POSTI(bool POSTI); + void set_POSTO(bool POSTO); + void set_SISO_TYPE(trellis::siso_type_t type) { d_SISO_TYPE = type; } + void set_D(int D); + void set_TABLE(const std::vector<float> &table){ d_TABLE = table; } + void set_TYPE(digital::trellis_metric_type_t type){ d_TYPE = type; } + void forecast(int noutput_items, gr_vector_int &ninput_items_required); diff --git a/gr-trellis/lib/siso_f_impl.cc b/gr-trellis/lib/siso_f_impl.cc index d699cecaec..a1c7ab3320 100644 --- a/gr-trellis/lib/siso_f_impl.cc +++ b/gr-trellis/lib/siso_f_impl.cc @@ -45,19 +45,8 @@ namespace gr { (new siso_f_impl(FSM, K, S0, SK, POSTI, POSTO, SISO_TYPE)); } - siso_f_impl::siso_f_impl(const fsm &FSM, int K, - int S0, int SK, - bool POSTI, bool POSTO, - siso_type_t SISO_TYPE) - : block("siso_f", - io_signature::make(1, -1, sizeof(float)), - io_signature::make(1, -1, sizeof(float))), - d_FSM(FSM), d_K(K), - d_S0(S0),d_SK(SK), - d_POSTI(POSTI), d_POSTO(POSTO), - d_SISO_TYPE(SISO_TYPE)//, - //d_alpha(FSM.S()*(K+1)), - //d_beta(FSM.S()*(K+1)) + + void siso_f_impl::recalculate() { int multiple; if(d_POSTI && d_POSTO) @@ -69,7 +58,6 @@ namespace gr { else throw std::runtime_error ("Not both POSTI and POSTO can be false."); - //printf("constructor: Multiple = %d\n",multiple); set_output_multiple (d_K*multiple); //what is the meaning of relative rate for a block with 2 inputs? @@ -84,6 +72,47 @@ namespace gr { set_relative_rate(multiple / ((double) d_FSM.I())); } + siso_f_impl::siso_f_impl(const fsm &FSM, int K, + int S0, int SK, + bool POSTI, bool POSTO, + siso_type_t SISO_TYPE) + : block("siso_f", + io_signature::make(1, -1, sizeof(float)), + io_signature::make(1, -1, sizeof(float))), + d_FSM(FSM), d_K(K), + d_S0(S0),d_SK(SK), + d_POSTI(POSTI), d_POSTO(POSTO), + d_SISO_TYPE(SISO_TYPE)//, + //d_alpha(FSM.S()*(K+1)), + //d_beta(FSM.S()*(K+1)) + { + recalculate(); + } + + void siso_f_impl::set_FSM(const fsm &FSM) + { + d_FSM=FSM; + recalculate(); + } + + void siso_f_impl::set_K(int K) + { + d_K=K; + recalculate(); + } + + void siso_f_impl::set_POSTI(bool POSTI) + { + d_POSTI = POSTI; + recalculate(); + } + + void siso_f_impl::set_POSTO(bool POSTO) + { + d_POSTO = POSTO; + recalculate(); + } + siso_f_impl::~siso_f_impl() { } diff --git a/gr-trellis/lib/siso_f_impl.h b/gr-trellis/lib/siso_f_impl.h index ca8f623aaf..c8c9e1ae41 100644 --- a/gr-trellis/lib/siso_f_impl.h +++ b/gr-trellis/lib/siso_f_impl.h @@ -42,6 +42,7 @@ namespace gr { bool d_POSTI; bool d_POSTO; siso_type_t d_SISO_TYPE; + void recalculate(); //std::vector<float> d_alpha; //std::vector<float> d_beta; @@ -60,6 +61,14 @@ namespace gr { bool POSTO() const { return d_POSTO; } siso_type_t SISO_TYPE() const { return d_SISO_TYPE; } + void set_FSM(const fsm &FSM); + void set_K(int K); + void set_S0(int S0){ d_S0 = S0; } + void set_SK(int SK){ d_SK = SK; } + void set_POSTI(bool POSTI); + void set_POSTO(bool POSTO); + void set_SISO_TYPE(trellis::siso_type_t type) { d_SISO_TYPE = type; } + void forecast(int noutput_items, gr_vector_int &ninput_items_required); diff --git a/gr-trellis/lib/viterbi_X_impl.cc.t b/gr-trellis/lib/viterbi_X_impl.cc.t index 247424b3f3..bd5bdd8413 100644 --- a/gr-trellis/lib/viterbi_X_impl.cc.t +++ b/gr-trellis/lib/viterbi_X_impl.cc.t @@ -55,6 +55,18 @@ namespace gr { set_output_multiple(d_K); } + void @IMPL_NAME@::set_FSM(fsm &FSM) + { + d_FSM = FSM; + set_relative_rate(1.0 / ((double)d_FSM.O())); + } + + void @IMPL_NAME@::set_K(int K) + { + d_K = K; + set_output_multiple(d_K); + } + @IMPL_NAME@::~@IMPL_NAME@() { } diff --git a/gr-trellis/lib/viterbi_X_impl.h.t b/gr-trellis/lib/viterbi_X_impl.h.t index b9554e8c39..44934a5e22 100644 --- a/gr-trellis/lib/viterbi_X_impl.h.t +++ b/gr-trellis/lib/viterbi_X_impl.h.t @@ -44,11 +44,15 @@ namespace gr { int S0, int SK); ~@IMPL_NAME@(); - fsm FSM() const { return d_FSM; } - int K() const { return d_K; } - int S0() const { return d_S0; } - int SK() const { return d_SK; } + fsm FSM() const { return d_FSM; } + int K() const { return d_K; } + int S0() const { return d_S0; } + int SK() const { return d_SK; } + void set_FSM(fsm &FSM); + void set_K(int K); + void set_S0(int S0) { d_S0 = S0; } + void set_SK(int SK) { d_SK = SK; } //std::vector<int> trace () const { return d_trace; } void forecast(int noutput_items, diff --git a/gr-trellis/lib/viterbi_combined_XX_impl.cc.t b/gr-trellis/lib/viterbi_combined_XX_impl.cc.t index c7cf10e567..91bb4e6c34 100644 --- a/gr-trellis/lib/viterbi_combined_XX_impl.cc.t +++ b/gr-trellis/lib/viterbi_combined_XX_impl.cc.t @@ -60,14 +60,22 @@ namespace gr { set_output_multiple(d_K); } - @IMPL_NAME@::~@IMPL_NAME@() + void + @IMPL_NAME@::set_K(int K) { + d_K = K; + set_output_multiple(d_K); } void - @IMPL_NAME@::set_TABLE(const std::vector<@I_TYPE@> &table) + @IMPL_NAME@::set_D(int D) + { + d_D = D; + set_relative_rate(1.0 / ((double)d_D)); + } + + @IMPL_NAME@::~@IMPL_NAME@() { - d_TABLE = table; } void diff --git a/gr-trellis/lib/viterbi_combined_XX_impl.h.t b/gr-trellis/lib/viterbi_combined_XX_impl.h.t index 199e8c8e88..7098d8b329 100644 --- a/gr-trellis/lib/viterbi_combined_XX_impl.h.t +++ b/gr-trellis/lib/viterbi_combined_XX_impl.h.t @@ -49,15 +49,22 @@ namespace gr { digital::trellis_metric_type_t TYPE); ~@IMPL_NAME@(); - fsm FSM() const { return d_FSM; } - int K() const { return d_K; } - int S0() const { return d_S0; } - int SK() const { return d_SK; } - int D() const { return d_D; } + fsm FSM() const { return d_FSM; } + int K() const { return d_K; } + int S0() const { return d_S0; } + int SK() const { return d_SK; } + int D() const { return d_D; } std::vector<@I_TYPE@> TABLE() const { return d_TABLE; } digital::trellis_metric_type_t TYPE() const { return d_TYPE; } //std::vector<int> trace() const { return d_trace; } - void set_TABLE(const std::vector<@I_TYPE@> &table); + + void set_FSM(const fsm &FSM){ d_FSM = FSM; } + void set_K(int K); + void set_S0(int S0){ d_S0 = S0; } + void set_SK(int SK){ d_SK = SK; } + void set_D(int D); + void set_TABLE(const std::vector<@I_TYPE@> &table) { d_TABLE = table; } + void set_TYPE(digital::trellis_metric_type_t type) { d_TYPE = type; } void forecast(int noutput_items, gr_vector_int &ninput_items_required); |