diff options
Diffstat (limited to 'gr-trellis/src/lib')
-rw-r--r-- | gr-trellis/src/lib/trellis_calc_metric.cc | 67 | ||||
-rw-r--r-- | gr-trellis/src/lib/trellis_calc_metric.h | 6 |
2 files changed, 47 insertions, 26 deletions
diff --git a/gr-trellis/src/lib/trellis_calc_metric.cc b/gr-trellis/src/lib/trellis_calc_metric.cc index 238e506b8..ec2ed794d 100644 --- a/gr-trellis/src/lib/trellis_calc_metric.cc +++ b/gr-trellis/src/lib/trellis_calc_metric.cc @@ -26,7 +26,8 @@ -void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type) +template <class T> +void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -36,8 +37,10 @@ void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - float s=in[m]-TABLE[o*D+m]; - metric[o]+=s*s; + T s=in[m]-TABLE[o*D+m]; + //gr_complex sc(1.0*s,0); + //metric[o]+=(sc*conj(sc)).real(); + metric[o]+= s * s; } } break; @@ -45,8 +48,10 @@ void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - float s=in[m]-TABLE[o*D+m]; - metric[o]+=s*s; + T s=in[m]-TABLE[o*D+m]; + //gr_complex sc(1.0*s,0); + //metric[o]+=(sc*conj(sc)).real(); + metric[o]+= s * s; } if(metric[o]<minm) { minm=metric[o]; @@ -66,7 +71,19 @@ void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, } -void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type) + +template +void calc_metric<short>(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type); + +template +void calc_metric<int>(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type); + +template +void calc_metric<float>(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type); + + +/* +void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -106,8 +123,7 @@ void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, flo } - -void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type) +void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -120,7 +136,7 @@ void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float s=in[m]-TABLE[o*D+m]; metric[o]+=s*s; } - } + } break; case TRELLIS_HARD_SYMBOL: for(int o=0;o<O;o++) { @@ -147,7 +163,8 @@ void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, } -void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type) + +void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -157,16 +174,17 @@ void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_co for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - gr_complex s=in[m]-TABLE[o*D+m]; - metric[o]+=s.real()*s.real()+s.imag()*s.imag(); + float s=in[m]-TABLE[o*D+m]; + metric[o]+=s*s; } - } + } + break; case TRELLIS_HARD_SYMBOL: for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - gr_complex s=in[m]-TABLE[o*D+m]; - metric[o]+=s.real()*s.real()+s.imag()*s.imag(); + float s=in[m]-TABLE[o*D+m]; + metric[o]+=s*s; } if(metric[o]<minm) { minm=metric[o]; @@ -184,10 +202,13 @@ void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_co throw std::runtime_error ("Invalid metric type."); } } +*/ -/* -template <class T> void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type) + + + +void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type) { float minm = FLT_MAX; int minmi = 0; @@ -197,19 +218,16 @@ template <class T> void calc_metric(int O, int D, const std::vector<T> &TABLE, c for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - T s=in[m]-TABLE[o*D+m]; - gr_complex sc(1.0*s,0); - metric[o]+=(s*conj(s)).real(); + gr_complex s=in[m]-TABLE[o*D+m]; + metric[o]+=s.real()*s.real()+s.imag()*s.imag(); } } - break; case TRELLIS_HARD_SYMBOL: for(int o=0;o<O;o++) { metric[o]=0.0; for (int m=0;m<D;m++) { - T s=in[m]-TABLE[o*D+m]; - gr_complex sc(1.0*s,0); - metric[o]+=(s*conj(s)).real(); + gr_complex s=in[m]-TABLE[o*D+m]; + metric[o]+=s.real()*s.real()+s.imag()*s.imag(); } if(metric[o]<minm) { minm=metric[o]; @@ -227,4 +245,3 @@ template <class T> void calc_metric(int O, int D, const std::vector<T> &TABLE, c throw std::runtime_error ("Invalid metric type."); } } -*/ diff --git a/gr-trellis/src/lib/trellis_calc_metric.h b/gr-trellis/src/lib/trellis_calc_metric.h index 2a4a78824..5e9f3efbf 100644 --- a/gr-trellis/src/lib/trellis_calc_metric.h +++ b/gr-trellis/src/lib/trellis_calc_metric.h @@ -28,15 +28,19 @@ #include <trellis_metric_type.h> +template <class T> +void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type); + +/* void calc_metric(int O, int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type); void calc_metric(int O, int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type); void calc_metric(int O, int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type); +*/ void calc_metric(int O, int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type); -//template <class T> void calc_metric(int O, int D, const std::vector<T> &TABLE, const T *in, float *metric, trellis_metric_type_t type); #endif |