aboutsummaryrefslogtreecommitdiffstats
path: root/CommonLibs/BitVector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CommonLibs/BitVector.cpp')
-rw-r--r--CommonLibs/BitVector.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/CommonLibs/BitVector.cpp b/CommonLibs/BitVector.cpp
index 54a3edc..7487834 100644
--- a/CommonLibs/BitVector.cpp
+++ b/CommonLibs/BitVector.cpp
@@ -29,6 +29,7 @@
#include "BitVector.h"
#include <iostream>
#include <stdio.h>
+#include <sstream>
using namespace std;
@@ -274,9 +275,6 @@ void BitVector::unmap(const unsigned *map, size_t mapSize, BitVector& dest) cons
-
-
-
ostream& operator<<(ostream& os, const BitVector& hv)
{
for (size_t i=0; i<hv.size(); i++) {
@@ -527,6 +525,22 @@ void SoftVector::decode(ViterbiR2O4 &decoder, BitVector& target) const
+// (pat) Added 6-22-2012
+float SoftVector::getEnergy(float *plow) const
+{
+ const SoftVector &vec = *this;
+ int len = vec.size();
+ float avg = 0; float low = 1;
+ for (int i = 0; i < len; i++) {
+ float bit = vec[i];
+ float energy = 2*((bit < 0.5) ? (0.5-bit) : (bit-0.5));
+ if (energy < low) low = energy;
+ avg += energy/len;
+ }
+ if (plow) { *plow = low; }
+ return avg;
+}
+
ostream& operator<<(ostream& os, const SoftVector& sv)
{
@@ -578,6 +592,14 @@ void BitVector::hex(ostream& os) const
os << std::dec;
}
+std::string BitVector::hexstr() const
+{
+ std::ostringstream ss;
+ hex(ss);
+ return ss.str();
+}
+
+
bool BitVector::unhex(const char* src)
{
// Assumes MSB-first packing.