IT++ Logo
Simulation of a Reed-Solomon Block Code

A Reed-Solomon code is a $q^m$-ary BCH code of length $q^m-1$. The generator polynomial for a $t$-error correcting code is $g(x) = (x-\alpha) (x-\alpha^1) \ldots (x-\alpha^{2t-1})$. The decoder uses the Berlkamp-Massey algorithm for decoding as described in: S. B. Wicker, "Error Control Systems for digital communication and storage," Prentice Hall. The following example simulates a binary (i.e. $q=2$) Reed-Solomon code with parameters $m$ and $t$:

#include <itpp/itcomm.h>
using namespace itpp;
//These lines are needed for use of cout and endl
using std::cout;
using std::endl;
int main()
{
//Scalars and vectors:
int m, t, n, k, q, NumBits, NumCodeWords;
double p;
bvec uncoded_bits, coded_bits, received_bits, decoded_bits;
//Set parameters:
NumCodeWords = 1000; //Number of Reed-Solomon code-words to simulate
p = 0.01; //BSC Error probability
m = 3; //Reed-Solomon parameter m
t = 2; //Reed-Solomon parameter t
cout << "Number of Reed-Solomon code-words to simulate: " << NumCodeWords << endl;
cout << "BSC Error probability : " << p << endl;
cout << "RS m: " << m << endl;
cout << "RS t: " << t << endl;
//Classes:
Reed_Solomon reed_solomon(m, t);
BSC bsc(p);
BERC berc;
//Calculate parameters for the Reed-Solomon Code:
n = round_i(pow(2.0, m) - 1);
k = round_i(pow(2.0, m)) - 1 - 2 * t;
q = round_i(pow(2.0, m));
cout << "Simulating an Reed-Solomon code with the following parameters:" << endl;
cout << "n = " << n << endl;
cout << "k = " << k << endl;
cout << "q = " << q << endl;
NumBits = m * k * NumCodeWords;
uncoded_bits = randb(NumBits);
coded_bits = reed_solomon.encode(uncoded_bits);
received_bits = bsc(coded_bits);
decoded_bits = reed_solomon.decode(received_bits);
berc.count(uncoded_bits, decoded_bits);
cout << "The bit error probability after decoding is " << berc.get_errorrate() << endl;
//Exit program:
return 0;
}

A typical run of this program can look like this:

Number of Reed-Solomon code-words to simulate: 1000
BSC Error probability : 0.01
RS m: 3
RS t: 2
Simulating an Reed-Solomon code with the following parameters:
n = 7
k = 3
q = 8
The bit error probability after decoding is 0.000333333
itpp::BSC
A Binary Symetric Channel with crossover probability p.
Definition: channel.h:1037
itpp::BERC::get_errorrate
double get_errorrate() const
Returns the estimated bit error rate.
Definition: error_counters.h:103
itpp::RNG_randomize
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
Definition: random.cpp:254
itpp
itpp namespace
Definition: itmex.h:36
itpp::Reed_Solomon
Reed-Solomon Codes.
Definition: reedsolomon.h:51
itpp::randb
bin randb(void)
Generates a random bit (equally likely 0s and 1s)
Definition: random.h:793
itpp::pow
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
Definition: log_exp.h:176
itpp::BERC
Bit Error Rate Counter (BERC) Class.
Definition: error_counters.h:67
itcomm.h
Include file for the IT++ communications module.
itpp::round_i
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
itpp::BERC::count
void count(const bvec &in1, const bvec &in2)
Cumulative error counter.
Definition: error_counters.cpp:49

Generated on Mon Mar 23 2020 06:18:03 for IT++ by Doxygen 1.8.17