Go to the documentation of this file.00001 #include <itpp/itcomm.h>
00002
00003 using namespace itpp;
00004
00005
00006 using std::cout;
00007 using std::endl;
00008
00009 int main()
00010 {
00011
00012 int constraint_length, MaxNrofErrors, Nobits, MaxIterations, p, i;
00013 double Ec, Eb;
00014
00015
00016 ivec generators;
00017 vec EbN0dB, EbN0, N0, ber, trans_symbols, rec_symbols;
00018 bvec uncoded_bits, coded_bits, decoded_bits;
00019
00020
00021 BPSK bpsk;
00022 BERC berc;
00023 Convolutional_Code conv_code;
00024 AWGN_Channel channel;
00025
00026
00027
00028
00029
00030
00031
00032 generators.set_size(3,false);
00033 generators(0) = 0133;
00034 generators(1) = 0145;
00035 generators(2) = 0175;
00036 constraint_length = 7;
00037 conv_code.set_generator_polynomials(generators, constraint_length);
00038
00039
00040 Ec = 1.0;
00041 EbN0dB = linspace(-2,6,5);
00042 EbN0 = inv_dB(EbN0dB);
00043 Eb = Ec / conv_code.get_rate();
00044 N0 = Eb * pow(EbN0,-1);
00045 MaxNrofErrors = 100;
00046 Nobits = 10000;
00047 MaxIterations = 10;
00048 ber.set_size(EbN0dB.length(),false);
00049 ber.clear();
00050
00051
00052 RNG_randomize();
00053
00054 for (p=0; p<EbN0dB.length(); p++) {
00055
00056 cout << "Now simulating point " << p+1 << " out of " << EbN0dB.length() << endl;
00057 berc.clear();
00058 channel.set_noise(N0(p)/2.0);
00059
00060 for (i=0; i<MaxIterations; i++) {
00061
00062 uncoded_bits = randb(Nobits);
00063 coded_bits = conv_code.encode(uncoded_bits);
00064 bpsk.modulate_bits(coded_bits, trans_symbols);
00065 rec_symbols = channel( trans_symbols );
00066 decoded_bits = conv_code.decode(rec_symbols);
00067 berc.count(uncoded_bits,decoded_bits);
00068 ber(p) = berc.get_errorrate();
00069
00070
00071 if (berc.get_errors()>MaxNrofErrors) {
00072 cout << "Breaking on point " << p+1 << " with " << berc.get_errors() << " errors." << endl; break;
00073 }
00074
00075 }
00076 }
00077
00078
00079 cout << "BER = " << ber << endl;
00080 cout << "EbN0dB = " << EbN0dB << endl;
00081
00082
00083 return 0;
00084
00085 }