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 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;
EbN0dB = linspace(-2, 6, 5);
EbN0 = inv_dB(EbN0dB);
N0 = Eb * pow(EbN0, -1);
MaxNrofErrors = 100;
Nobits = 10000;
MaxIterations = 10;
ber.set_size(EbN0dB.length(), false);
ber.clear();
RNG_randomize();
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;
}
Ordinary AWGN Channel for cvec or vec inputs and outputs.
void set_noise(double noisevar)
Set noise variance (for complex-valued channels the sum of real and imaginary parts)
Bit Error Rate Counter (BERC) Class.
void clear()
Clears the bit error counter.
double get_errors() const
Returns the counted number of bit errors.
double get_errorrate() const
Returns the estimated bit error rate.
void count(const bvec &in1, const bvec &in2)
Cumulative error counter.
BPSK modulator with real symbols.
void modulate_bits(const bvec &bits, vec &output) const
Modulate bits into BPSK symbols in complex domain.
Binary Convolutional rate 1/n class.
virtual double get_rate(void) const
Return rate of code (not including the rate-loss)
void set_generator_polynomials(const ivec &gen, int constraint_length)
Set generator polynomials. Given in Proakis integer form.
virtual void decode(const bvec &coded_bits, bvec &decoded_bits)
Decode a bvec of coded data.
virtual void encode(const bvec &input, bvec &output)
Encode an input binary vector using specified method (Tail by default)
Include file for the IT++ communications module.
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]