error_counters.cpp
Go to the documentation of this file.
#include <itpp/comm/error_counters.h>
#include <itpp/base/matfunc.h>
#include <itpp/base/converters.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
namespace itpp
{
//-----------------------------------------------------------
// The Bit error rate counter class (BERC)
//-----------------------------------------------------------
BERC::BERC(int indelay, int inignorefirst, int inignorelast):
delay(indelay), ignorefirst(inignorefirst), ignorelast(inignorelast),
errors(0), corrects(0) {}
void BERC::count(const bvec &in1, const bvec &in2)
{
int countlength = std::min(in1.length(), in2.length()) - std::abs(delay)
- ignorefirst - ignorelast;
if (delay >= 0) {
for (int i = 0; i < countlength; i++) {
if (in1(i + ignorefirst) == in2(i + ignorefirst + delay)) {
corrects++;
}
else {
errors++;
}
}
}
else {
for (int i = 0; i < countlength; i++) {
if (in1(i + ignorefirst - delay) == in2(i + ignorefirst)) {
corrects++;
}
else {
errors++;
}
}
}
}
void BERC::count(const bool x)
{
if (x) {
errors++;
} else {
corrects++;
}
}
void BERC::estimate_delay(const bvec &in1, const bvec &in2, int mindelay,
int maxdelay)
{
int num, start1, start2;
int min_input_length = std::min(in1.length(), in2.length());
int bestdelay = mindelay;
double correlation;
double bestcorr = 0;
for (int i = mindelay; i < maxdelay; i++) {
num = min_input_length - std::abs(i) - ignorefirst - ignorelast;
start1 = (i < 0) ? -i : 0;
start2 = (i > 0) ? i : 0;
correlation = fabs(sum(to_vec(elem_mult(in1.mid(start1, num),
in2.mid(start2, num)))));
if (correlation > bestcorr) {
bestdelay = i;
bestcorr = correlation;
}
}
delay = bestdelay;
}
void BERC::report() const
{
std::cout.setf(std::ios::fixed);
std::cout << std::endl
<< "==================================" << std::endl
<< " Bit Error Counter Report " << std::endl
<< "==================================" << std::endl
<< " Ignore First = " << ignorefirst << std::endl
<< " Ignore Last = " << ignorelast << std::endl
<< " Delay = " << delay << std::endl
<< " Number of counted bits = " << std::setprecision(0)
<< (errors + corrects) << std::endl
<< " Number of errors = " << std::setprecision(0)
<< errors << std::endl
<< "==================================" << std::endl
<< " Error rate = " << std::setprecision(8)
<< (errors / (errors + corrects)) << std::endl
<< "==================================" << std::endl << std::endl;
}
double BERC::count_errors(const bvec &in1, const bvec &in2, int indelay,
int inignorefirst, int inignorelast)
{
int countlength = std::min(in1.length(), in2.length()) - std::abs(indelay)
- inignorefirst - inignorelast;
int local_errors = 0;
if (indelay >= 0) {
for (int i = 0; i < countlength; i++) {
if (in1(i + inignorefirst) != in2(i + inignorefirst + indelay)) {
local_errors++;
}
}
}
else {
for (int i = 0; i < countlength; i++) {
if (in1(i + inignorefirst - indelay) != in2(i + inignorefirst)) {
local_errors++;
}
}
}
return local_errors;
}
//-----------------------------------------------------------
// The Block error rate counter class (BERC)
//-----------------------------------------------------------
BLERC::BLERC(): setup_done(false), blocksize(0), errors(0),
corrects(0) {}
BLERC::BLERC(int inblocksize): setup_done(true), blocksize(inblocksize),
errors(0), corrects(0) {}
void BLERC::set_blocksize(int inblocksize, bool clear)
{
blocksize = inblocksize;
if (clear) {
errors = 0;
corrects = 0;
}
setup_done = true;
}
void BLERC::count(const bvec &in1, const bvec &in2)
{
it_assert(setup_done == true,
"BLERC::count(): Block size has to be setup before counting errors.");
int min_input_length = std::min(in1.length(), in2.length());
it_assert(blocksize <= min_input_length,
"BLERC::count(): Block size must not be longer than input vectors.");
for (int i = 0; i < (min_input_length / blocksize); i++) {
CORR = true;
for (int j = 0; j < blocksize; j++) {
if (in1(i * blocksize + j) != in2(i * blocksize + j)) {
CORR = false;
break;
}
}
if (CORR) {
corrects++;
}
else {
errors++;
}
}
}
void BLERC::count(const bool x)
{
if (x) {
errors++;
} else {
corrects++;
}
}
} // namespace itpp
itpp::Array
General array class.
Definition array.h:105
itpp::Array::mid
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
Definition array.h:377
itpp::Array::length
int length() const
Returns the number of data elements in the array object.
Definition array.h:157
itpp::BERC::report
void report() const
Writes an error report.
Definition error_counters.cpp:107
itpp::BERC::count
void count(const bvec &in1, const bvec &in2)
Cumulative error counter.
Definition error_counters.cpp:49
itpp::BERC::estimate_delay
void estimate_delay(const bvec &in1, const bvec &in2, int mindelay=-100, int maxdelay=100)
Run this member function if the delay between in1 and in2 is unknown.
Definition error_counters.cpp:85
itpp::BERC::count_errors
static double count_errors(const bvec &in1, const bvec &in2, int indelay=0, int inignorefirst=0, int inignorelast=0)
static function to allow simple and fast count of bit-errors
Definition error_counters.cpp:127
itpp::BERC::BERC
BERC(int indelay=0, int inignorefirst=0, int inignorelast=0)
Constructor for the berc class.
Definition error_counters.cpp:45
itpp::BLERC::set_blocksize
void set_blocksize(int inblocksize, bool clear=true)
Set the block size.
Definition error_counters.cpp:165
itpp::BLERC::clear
void clear()
Clear the block error counter.
Definition error_counters.h:146
itpp::BLERC::BLERC
BLERC(void)
Class constructor.
Definition error_counters.cpp:157
itpp::BLERC::count
void count(const bvec &in1, const bvec &in2)
Calculate the number of block errors between in1 and in2.
Definition error_counters.cpp:175
converters.h
Definitions of converters between different vector and matrix types.
error_counters.h
Definitions of Bit Error Rate Counter (BERC) and BLock Error Rate Counter (BLERC) classes.
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition itassert.h:94
itpp::sum
T sum(const Vec< T > &v)
Sum of all elements in the vector.
Definition matfunc.h:59
matfunc.h
Various functions on vectors and matrices - header file.
itpp
itpp namespace
Definition itmex.h:37
itpp::to_vec
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
Definition converters.h:93
itpp::elem_mult
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
Definition mat.h:1582

Generated on Mon Jun 10 2024 11:49:20 for IT++ by Doxygen 1.9.8