IT++ Logo
BPSK modulation over an AWGN channel

As a first example we will generate a sequence of 500000 random bits {0,1} and BPSK modulate these. Thereafter the BPSK signals will be transmitted over an AWGN channel with a signal-to-noise ratio $E_b/N_0 = 0$ dB. The received signal is then decoded and the number of bit errors are calculated.

#include <itpp/itcomm.h>
using namespace itpp;
//These lines are needed for use of cout and endl
using std::cout;
using std::endl;
int main()
{
//Scalars
int N;
double N0;
//Vectors
bvec bits, dec_bits;
vec symbols, rec;
//Classes
BPSK bpsk; //The BPSK modulator/debodulator class
BERC berc; //The Bit Error Rate Counter class
//Init
N = 500000; //The number of bits to simulate
N0 = 1; //0 dB SNR
//Randomize the random number generator
//Generate the bits:
bits = randb(N);
//Do the BPSK modulation
bpsk.modulate_bits(bits, symbols);
//Add the AWGN
rec = symbols + sqrt(N0 / 2) * randn(N);
//Decode the received bits
bpsk.demodulate_bits(rec, dec_bits);
//Count the number of errors
berc.count(bits, dec_bits);
//Print the results
cout << "There were " << berc.get_errors() << " received bits in error." << endl;
cout << "There were " << berc.get_corrects() << " correctly received bits." << endl;
cout << "The error probability was " << berc.get_errorrate() << endl;
cout << "The theoretical error probability is " << 0.5*erfc(1.0) << endl;
//Exit program:
return 0;
}

When you run this program, the output will look something like this:

There were 39224 received bits in error.
There were 460776 correctly received bits.
The error probability was 0.078448
The theoretical error probability is 0.0786496
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::BPSK
BPSK modulator with real symbols.
Definition: modulator.h:876
itpp::BERC::get_corrects
double get_corrects() const
Returns the counted number of corectly received bits.
Definition: error_counters.h:99
itpp::BPSK::demodulate_bits
void demodulate_bits(const vec &signal, bvec &output) const
Demodulate noisy BPSK symbols in complex domain into bits.
Definition: modulator.cpp:326
itpp
itpp namespace
Definition: itmex.h:36
itpp::randb
bin randb(void)
Generates a random bit (equally likely 0s and 1s)
Definition: random.h:793
itpp::randn
double randn(void)
Generates a random Gaussian (0,1) variable.
Definition: random.h:831
itpp::BERC::get_errors
double get_errors() const
Returns the counted number of bit errors.
Definition: error_counters.h:97
itpp::sqrt
vec sqrt(const vec &x)
Square root of the elements.
Definition: elem_math.h:123
itpp::BERC
Bit Error Rate Counter (BERC) Class.
Definition: error_counters.h:67
itcomm.h
Include file for the IT++ communications module.
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
itpp::erfc
vec erfc(const vec &x)
Complementary error function.
Definition: error.cpp:240
SourceForge Logo

Generated on Sat Jun 22 2019 19:10:12 for IT++ by Doxygen 1.8.17