00001 #include <itpp/itcomm.h> 00002 00003 using namespace itpp; 00004 00005 //These lines are needed for use of cout and endl 00006 using std::cout; 00007 using std::endl; 00008 00009 int main() 00010 { 00011 //Scalars 00012 int constraint_length, MaxNrofErrors, Nobits, MaxIterations, p, i; 00013 double Ec, Eb; 00014 00015 //Vectors 00016 ivec generators; 00017 vec EbN0dB, EbN0, N0, ber, trans_symbols, rec_symbols; 00018 bvec uncoded_bits, coded_bits, decoded_bits; 00019 00020 //Classes 00021 BPSK bpsk; 00022 BERC berc; 00023 Convolutional_Code conv_code; 00024 AWGN_Channel channel; 00025 00026 /* 00027 Set up the convolutional encoder/decoder class: 00028 The generators are given in octal form by adding a zero in front of the numbers. 00029 In this example we will simulate a rate 1/3 code that is listed in J. G. Proakis, 00030 "Digital communications". The encoder has constraint length 7. 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 //Init: Calculate some simulation specific parameters: 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 //Randomize the random number generators. 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(); //Clear the bit error rate counter. 00058 channel.set_noise(N0(p)/2.0); //Set the noise value of the AWGN channel. 00059 00060 for (i=0; i<MaxIterations; i++) { 00061 00062 uncoded_bits = randb(Nobits); //The uncoded bits. 00063 coded_bits = conv_code.encode(uncoded_bits); //The convolutional encoder function. 00064 bpsk.modulate_bits(coded_bits, trans_symbols); //The BPSK modulator. 00065 rec_symbols = channel( trans_symbols ); //The AWGN channel. 00066 decoded_bits = conv_code.decode(rec_symbols); //The Viterbi decoder function. 00067 berc.count(uncoded_bits,decoded_bits); //Count the errors. 00068 ber(p) = berc.get_errorrate(); 00069 00070 //Break the simulation on this point if sufficient number of bit errors were observed: 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 //Print the results: 00079 cout << "BER = " << ber << endl; 00080 cout << "EbN0dB = " << EbN0dB << endl; 00081 00082 //Exit program: 00083 return 0; 00084 00085 }
Generated on Sat Jun 6 13:48:51 2009 for RMOL by Doxygen 1.5.7.1