In this example we will show how to use the convolutional encoder/decoder class in it++. The Viterbi decoder uses the soft received values.
using namespace itpp;
using std::cout;
using std::endl;
int main()
{
int constraint_length, MaxNrofErrors, Nobits, MaxIterations, p, i;
double Ec, Eb;
ivec generators;
vec EbN0dB, EbN0, N0, ber, trans_symbols, rec_symbols;
bvec uncoded_bits, coded_bits, decoded_bits;
generators.set_size(3, false);
generators(0) = 0133;
generators(1) = 0145;
generators(2) = 0175;
constraint_length = 7;
Ec = 1.0;
MaxNrofErrors = 100;
Nobits = 10000;
MaxIterations = 10;
ber.set_size(EbN0dB.length(), false);
ber.clear();
for (p = 0; p < EbN0dB.length(); p++) {
cout << "Now simulating point " << p + 1 << " out of " << EbN0dB.length() << endl;
for (i = 0; i < MaxIterations; i++) {
uncoded_bits =
randb(Nobits);
coded_bits = conv_code.
encode(uncoded_bits);
rec_symbols = channel(trans_symbols);
decoded_bits = conv_code.
decode(rec_symbols);
berc.
count(uncoded_bits, decoded_bits);
cout <<
"Breaking on point " << p + 1 <<
" with " << berc.
get_errors() <<
" errors." << endl;
break;
}
}
}
cout << "BER = " << ber << endl;
cout << "EbN0dB = " << EbN0dB << endl;
return 0;
}
When you run this program, the output will look something like this:
Now simulating point 1 out of 5
Breaking on point 1 with 3297 errors.
Now simulating point 2 out of 5
Breaking on point 2 with 781 errors.
Now simulating point 3 out of 5
Breaking on point 3 with 112 errors.
Now simulating point 4 out of 5
Now simulating point 5 out of 5
BER = [0.330858 0.0783743 0.00280983 0 0]
EbN0dB = [-2 0 2 4 6]