RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads

ldpc_bersim_awgn.cpp

Go to the documentation of this file.
00001 #include <itpp/itcomm.h>
00002 
00003 using namespace std;
00004 using namespace itpp;
00005 
00006 extern int main(int argc, char **argv)
00007 { 
00008   int Nbits=1000*1000*5000;          // maximum number of bits simulated for any SNR point
00009   int Nbers=2000;                   // target number of bit errors per SNR point
00010   double BERmin=1e-6;               // BER at which to terminate simulation
00011   vec EbN0db = "0.6:0.2:5";
00012 
00013   LDPC_Code C(argv[1]);
00014   bool single_snr_mode=false;
00015   if (argc==3) {
00016     double x;
00017     sscanf(argv[2],"%lf",&x);
00018     EbN0db.set_size(1);
00019     EbN0db(0)=x;
00020     single_snr_mode=true;
00021   }
00022 
00023   cout << "Running with Eb/N0: " << EbN0db << endl;
00024 
00025   // High performance: 2500 iterations, high resolution LLR algebra
00026   C.setup_decoder("bp","2500 1 0");  
00027 
00028   // Alt. setting -- High speed: 50 iterations, logmax approximation
00029   // C.setup_decoder("bp","50 1 0",LLR_calc_unit(12,0,7));  
00030 
00031   cout << C << endl;
00032 
00033   int N = C.get_nvar();             // number of bits per codeword
00034   BPSK Mod;
00035   bvec bitsin = zeros_b(N);
00036   vec s = Mod.modulate_bits(bitsin);
00037   
00038   RNG_randomize();
00039   for (int j=0; j<length(EbN0db); j++) {
00040     // noise variance is N0/2 per dimension
00041     double N0 = pow(10.0,-EbN0db(j)/10.0) / C.get_rate();
00042     AWGN_Channel chan(N0/2);
00043     BERC berc; // counters for coded and uncoded BER
00044     BLERC ferc; // counter for coded FER
00045     ferc.set_blocksize(N);
00046     for (long int i=0; i<Nbits; i+=C.get_nvar())   {
00047       // Received data
00048       vec x = chan(s);
00049       
00050       // Demodulate
00051       vec softbits=Mod.demodulate_soft_bits(x,N0);
00052 
00053       //Decode the received bits
00054       bvec bitsout=C.decode(softbits);
00055 
00056       //Count the number of errors
00057       berc.count(bitsin,bitsout);
00058       ferc.count(bitsin,bitsout);      
00059 
00060       if (single_snr_mode) {
00061         cout << "Eb/N0=" << EbN0db(j) << "  Simulated " 
00062              << ferc.get_total_blocks() << " frames and " 
00063              << berc.get_total_bits() << " bits. " 
00064              << "Obtained " << berc.get_errors() << " bit errors. " 
00065              << " BER: " << berc.get_errorrate() 
00066              << " FER: " << ferc.get_errorrate() << endl;
00067         cout.flush();
00068       }      else       {
00069           if (berc.get_errors()>Nbers) { break;}        
00070       }
00071     }
00072 
00073     cout << "Eb/N0=" << EbN0db(j) << "  Simulated " 
00074          << ferc.get_total_blocks() << " frames and " 
00075          << berc.get_total_bits() << " bits. " 
00076          << "Obtained " << berc.get_errors() << " bit errors. " 
00077          << " BER: " << berc.get_errorrate() 
00078          << " FER: " << ferc.get_errorrate() << endl;
00079     cout.flush();
00080     if (berc.get_errorrate()<BERmin)  {  break;  }
00081   } 
00082   return 0;
00083 }
SourceForge Logo

Generated on Sat Sep 26 13:13:03 2009 for RMOL by Doxygen 1.6.1