IT++ Logo
Simulation of LDPC codes the AWGN channel

This program simulates the performance of LDPC codes on the AWGN channel. Since the channel is symmetric, the zero codeword is used.

#include <itpp/itcomm.h>
#include <sstream>
using namespace std;
using namespace itpp;
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; // maximum number of bits simulated
// for each SNR point
int Nbers = 2000; // target number of bit errors per SNR point
double BERmin = 1e-6; // BER at which to terminate simulation
vec EbN0db = "0.6:0.2:5";
LDPC_Generator_Systematic G; // for codes created with ldpc_gen_codes since generator exists
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;
// High performance: 2500 iterations, high resolution LLR algebra
C.set_exit_conditions(2500);
// Alternate high speed settings: 50 iterations, logmax approximation
// C.set_llrcalc(LLR_calc_unit(12,0,7));
cout << C << endl;
int N = C.get_nvar(); // number of bits per codeword
BPSK Mod;
bvec bitsin = zeros_b(N);
vec s = Mod.modulate_bits(bitsin);
for (int j = 0; j < length(EbN0db); j++) {
// Noise variance is N0/2 per dimension
double N0 = pow(10.0, -EbN0db(j) / 10.0) / C.get_rate();
AWGN_Channel chan(N0 / 2);
BERC berc; // Counters for coded and uncoded BER
BLERC ferc; // Counter for coded FER
ferc.set_blocksize(C.get_nvar() - C.get_ncheck());
for (int64_t i = 0; i < Nbits; i += C.get_nvar()) {
// Received data
vec x = chan(s);
// Demodulate
vec softbits = Mod.demodulate_soft_bits(x, N0);
// Decode the received bits
QLLRvec llr;
C.bp_decode(C.get_llrcalc().to_qllr(softbits), llr);
bvec bitsout = llr < 0;
// bvec bitsout = C.decode(softbits); // (only systematic bits)
// Count the number of errors
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;
}

To simulate the code "RU_10000.it" over a range of SNR (see Generation of LDPC codes for how to generate codec)

./ldpc_bersim_awgn RU_10000.it

To simulate at Eb/N0=1.1 dB

./ldpc_bersim_awgn RU_10000.it 1.1
itpp::BLERC::get_total_blocks
double get_total_blocks() const
Returns the total number of block processed.
Definition: error_counters.h:152
itpp::BERC::get_errorrate
double get_errorrate() const
Returns the estimated bit error rate.
Definition: error_counters.h:103
itpp::RNG_randomize
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
Definition: random.cpp:254
itpp::zeros_b
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
itpp::BLERC::count
void count(const bvec &in1, const bvec &in2)
Calculate the number of block errors between in1 and in2.
Definition: error_counters.cpp:175
itpp::LDPC_Generator_Systematic
Systematic LDPC Generator class.
Definition: ldpc.h:570
itpp::BLERC::get_errorrate
double get_errorrate() const
Returns the block error rate.
Definition: error_counters.h:154
itpp::BPSK
BPSK modulator with real symbols.
Definition: modulator.h:876
itpp::flush
it_file & flush(it_file &f)
Flush operator.
Definition: itfile.h:409
itpp
itpp namespace
Definition: itmex.h:36
itpp::LDPC_Code
Low-density parity check (LDPC) codec.
Definition: ldpc.h:731
itpp::AWGN_Channel
Ordinary AWGN Channel for cvec or vec inputs and outputs.
Definition: channel.h:1088
itpp::BERC::get_total_bits
double get_total_bits() const
Returns the total number of bits processed.
Definition: error_counters.h:101
itpp::BLERC::set_blocksize
void set_blocksize(int inblocksize, bool clear=true)
Set the block size.
Definition: error_counters.cpp:165
itpp::BPSK::demodulate_soft_bits
virtual void demodulate_soft_bits(const vec &rx_symbols, double N0, vec &soft_bits, Soft_Method method=LOGMAP) const
Soft demodulator for AWGN channel.
Definition: modulator.cpp:342
itpp::length
int length(const Vec< T > &v)
Length of vector.
Definition: matfunc.h:51
itpp::pow
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
Definition: log_exp.h:176
itpp::BLERC
Class for counting block error rates.
Definition: error_counters.h:131
itpp::BERC::get_errors
double get_errors() const
Returns the counted number of bit errors.
Definition: error_counters.h:97
itpp::BERC
Bit Error Rate Counter (BERC) Class.
Definition: error_counters.h:67
itcomm.h
Include file for the IT++ communications module.
it_info
#define it_info(s)
Print information message.
Definition: itassert.h:136
itpp::BERC::count
void count(const bvec &in1, const bvec &in2)
Cumulative error counter.
Definition: error_counters.cpp:49
itpp::BPSK::modulate_bits
void modulate_bits(const bvec &bits, vec &output) const
Modulate bits into BPSK symbols in complex domain.
Definition: modulator.cpp:310

Generated on Mon Apr 25 2022 14:03:04 for IT++ by Doxygen 1.8.17