00001 #include <itpp/itcomm.h> 00002 00003 using namespace itpp; 00004 00005 //These lines are needed for use of cout and endl 00006 using std::cout; 00007 using std::endl; 00008 00009 int main() 00010 { 00011 //Scalars 00012 int N; 00013 double N0; 00014 00015 //Vectors 00016 bvec bits, dec_bits; 00017 vec symbols, rec; 00018 00019 //Classes 00020 BPSK bpsk; //The BPSK modulator/debodulator class 00021 BERC berc; //The Bit Error Rate Counter class 00022 00023 //Init 00024 N = 500000; //The number of bits to simulate 00025 N0 = 1; //0 dB SNR 00026 00027 //Randomize the random number generator 00028 RNG_randomize(); 00029 00030 //Generate the bits: 00031 bits = randb(N); 00032 00033 //Do the BPSK modulation 00034 bpsk.modulate_bits(bits, symbols); 00035 00036 //Add the AWGN 00037 rec = symbols + sqrt(N0/2)* randn(N); 00038 00039 //Decode the received bits 00040 bpsk.demodulate_bits(rec, dec_bits); 00041 00042 //Count the number of errors 00043 berc.count(bits,dec_bits); 00044 00045 //Print the results 00046 cout << "There were " << berc.get_errors() << " received bits in error." << endl; 00047 cout << "There were " << berc.get_corrects() << " correctly received bits." << endl; 00048 cout << "The error probability was " << berc.get_errorrate() << endl; 00049 cout << "The theoretical error probability is " << 0.5*erfc(1.0) << endl; 00050 00051 //Exit program: 00052 return 0; 00053 00054 }
Generated on Tue Apr 14 17:57:51 2009 for RMOL by Doxygen 1.5.8