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
dB. The received signal is then decoded and the number of bit errors are calculated.
using std::cout;
using std::endl;
int main()
{
int N;
double N0;
bvec bits, dec_bits;
vec symbols, rec;
BPSK bpsk;
BERC berc;
N = 500000;
N0 = 1;
bpsk.modulate_bits(bits, symbols);
bpsk.demodulate_bits(rec, dec_bits);
berc.count(bits, dec_bits);
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;
return 0;
}
vec erfc(const vec &x)
Complementary error function.
vec sqrt(const vec &x)
Square root of the elements.
void RNG_randomize()
Set a random seed for all Random Number Generators in the current thread.
bin randb(void)
Generates a random bit (equally likely 0s and 1s)
double randn(void)
Generates a random Gaussian (0,1) variable.
Include file for the IT++ communications module.
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