summaryrefslogtreecommitdiff
path: root/gr-trellis/src/lib/trellis_calc_metric.cc
diff options
context:
space:
mode:
authoranastas2006-08-16 20:07:36 +0000
committeranastas2006-08-16 20:07:36 +0000
commitd5c192f9e3cde58589845b7b51057afc45d3bc79 (patch)
tree04dc746388bb19f66bae93d110e4f2a5ca14c64b /gr-trellis/src/lib/trellis_calc_metric.cc
parent1f0a124c68a40b2eee063267d4f7aeba4ed87619 (diff)
downloadgnuradio-d5c192f9e3cde58589845b7b51057afc45d3bc79.tar.gz
gnuradio-d5c192f9e3cde58589845b7b51057afc45d3bc79.tar.bz2
gnuradio-d5c192f9e3cde58589845b7b51057afc45d3bc79.zip
Several enhancements to gr-trellis and gnuradio-examples/python/channel-coding:
-Added fsm constructor for generating FSM directly from the generator matrix of binary convolutional codes. -Added functionality to fsm class to compute the best way to go from any state to any other state (useful for termination) -Added soft-in-soft-out (SISO) block for turbo processing -Added turbo decoding examples git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3322 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-trellis/src/lib/trellis_calc_metric.cc')
-rw-r--r--gr-trellis/src/lib/trellis_calc_metric.cc115
1 files changed, 60 insertions, 55 deletions
diff --git a/gr-trellis/src/lib/trellis_calc_metric.cc b/gr-trellis/src/lib/trellis_calc_metric.cc
index ae25a67ba..5faa4b7c7 100644
--- a/gr-trellis/src/lib/trellis_calc_metric.cc
+++ b/gr-trellis/src/lib/trellis_calc_metric.cc
@@ -24,8 +24,7 @@
#include <stdexcept>
#include "trellis_calc_metric.h"
-// soft decisions (Euclidean distance squared)
-void calc_metric_s(const int O, const int D, const std::vector<short> &TABLE, const short *in, float *metric, trellis_metric_type_t type)
+void calc_metric_s(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;
@@ -33,24 +32,24 @@ void calc_metric_s(const int O, const int D, const std::vector<short> &TABLE, co
switch (type){
case TRELLIS_EUCLIDEAN:
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;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ 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++) {
- float s=in[m]-TABLE[o*D+m];
- metric[o]+=s*s;
- }
- if(metric[o]<minm) {
- minm=metric[o];
- minmi=o;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ float s=in[m]-TABLE[o*D+m];
+ metric[o]+=s*s;
+ }
+ if(metric[o]<minm) {
+ minm=metric[o];
+ minmi=o;
+ }
}
for(int o=0;o<O;o++) {
metric[o] = (o==minmi?0.0:1.0);
@@ -66,8 +65,7 @@ void calc_metric_s(const int O, const int D, const std::vector<short> &TABLE, co
-// soft decisions (Euclidean distance squared)
-void calc_metric_i(const int O, const int D, const std::vector<int> &TABLE, const int *in, float *metric, trellis_metric_type_t type)
+void calc_metric_i(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;
@@ -75,24 +73,24 @@ void calc_metric_i(const int O, const int D, const std::vector<int> &TABLE, cons
switch (type){
case TRELLIS_EUCLIDEAN:
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;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ 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++) {
- float s=in[m]-TABLE[o*D+m];
- metric[o]+=s*s;
- }
- if(metric[o]<minm) {
- minm=metric[o];
- minmi=o;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ float s=in[m]-TABLE[o*D+m];
+ metric[o]+=s*s;
+ }
+ if(metric[o]<minm) {
+ minm=metric[o];
+ minmi=o;
+ }
}
for(int o=0;o<O;o++) {
metric[o] = (o==minmi?0.0:1.0);
@@ -108,12 +106,7 @@ void calc_metric_i(const int O, const int D, const std::vector<int> &TABLE, cons
-
-
-
-
-// soft decisions (Euclidean distance squared)
-void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
+void calc_metric_f(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;
@@ -121,24 +114,24 @@ void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, co
switch (type){
case TRELLIS_EUCLIDEAN:
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;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ 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++) {
- float s=in[m]-TABLE[o*D+m];
- metric[o]+=s*s;
- }
- if(metric[o]<minm) {
- minm=metric[o];
- minmi=o;
- }
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ float s=in[m]-TABLE[o*D+m];
+ metric[o]+=s*s;
+ }
+ if(metric[o]<minm) {
+ minm=metric[o];
+ minmi=o;
+ }
}
for(int o=0;o<O;o++) {
metric[o] = (o==minmi?0.0:1.0);
@@ -153,8 +146,7 @@ void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, co
}
-// soft decisions (Euclidean distance squared)
-void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
+void calc_metric_c(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;
@@ -169,7 +161,20 @@ void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABL
}
}
case TRELLIS_HARD_SYMBOL:
- throw std::runtime_error ("Invalid metric type (not yet implemented).");
+ 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();
+ }
+ if(metric[o]<minm) {
+ minm=metric[o];
+ minmi=o;
+ }
+ }
+ for(int o=0;o<O;o++) {
+ metric[o] = (o==minmi?0.0:1.0);
+ }
break;
case TRELLIS_HARD_BIT:
throw std::runtime_error ("Invalid metric type (not yet implemented).");