This program simulates the performance of LDPC codes on the AWGN channel. Since the channel is symmetric, the zero codeword is used.
#include <sstream>
int main(int argc, char **argv)
{
if (argc < 2) {
it_info(
"Usage: " << argv[0] <<
" codec_file.it [EbN0_dB]");
return 1;
}
int64_t Nbits = 5000000000LL;
int Nbers = 2000;
double BERmin = 1e-6;
vec EbN0db =
"0.6:0.2:5";
LDPC_Generator_Systematic G;
LDPC_Code C(argv[1], &G);
bool single_snr_mode = false;
if (argc == 3) {
istringstream ss(argv[2]);
double x;
ss >> x;
EbN0db = x;
single_snr_mode = true;
}
cout << "Running with Eb/N0: " << EbN0db << endl;
C.set_exit_conditions(2500);
cout << C << endl;
int N = C.get_nvar();
BPSK Mod;
vec s = Mod.modulate_bits(bitsin);
for (
int j = 0; j <
length(EbN0db); j++) {
double N0 =
pow(10.0, -EbN0db(j) / 10.0) / C.get_rate();
AWGN_Channel chan(N0 / 2);
BERC berc;
BLERC ferc;
ferc.set_blocksize(C.get_nvar() - C.get_ncheck());
for (int64_t i = 0; i < Nbits; i += C.get_nvar()) {
vec softbits = Mod.demodulate_soft_bits(x, N0);
C.bp_decode(C.get_llrcalc().to_qllr(softbits), llr);
berc.count(bitsin, bitsout);
ferc.count(bitsin, bitsout);
if (single_snr_mode) {
cout << "Eb/N0 = " << EbN0db(j) << " Simulated "
<< ferc.get_total_blocks() << " frames and "
<< berc.get_total_bits() << " bits. "
<< "Obtained " << berc.get_errors() << " bit errors. "
<< " BER: " << berc.get_errorrate()
<<
" FER: " << ferc.get_errorrate() << endl <<
flush;
}
else {
if (berc.get_errors() > Nbers)
break;
}
}
cout << "Eb/N0 = " << EbN0db(j) << " Simulated "
<< ferc.get_total_blocks() << " frames and "
<< berc.get_total_bits() << " bits. "
<< "Obtained " << berc.get_errors() << " bit errors. "
<< " BER: " << berc.get_errorrate()
<<
" FER: " << ferc.get_errorrate() << endl <<
flush;
if (berc.get_errorrate() < BERmin)
break;
}
return 0;
}
Vec< double > vec
Definition of double vector type.
Vec< bin > bvec
Definition of binary vector type.
#define it_info(s)
Print information message.
it_file & flush(it_file &f)
Flush operator.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
int length(const Vec< T > &v)
Length of vector.
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
Include file for the IT++ communications module.