Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#include <itpp/itbase.h> #include <itpp/itcomm.h> #include <boost/spirit/core.hpp> #include <boost/spirit/actor/push_back_actor.hpp> #include <iostream> #include <vector> #include <string> #include "boost/smart_ptr.hpp" using namespace itpp; using namespace std; using namespace boost::spirit; typedef boost::scoped_ptr<PAM> pam; #import "ScriptController.h" @implementation ScriptController - (IBAction)okClicked:(id)sender { Hello h; bvec i = "001"; bool result = h.do_modulation(i); if(result) { string str = "1,2,3,4"; vector<double> v; [textField setStringValue:@"HELLLOOO"]; } else { [textField setStringValue:@"Failure"]; } } -(id) init { self = [super init]; if (self != nil) { } return self; } @end Hello::Hello() { } Hello::~Hello() { } bool Hello::do_modulation(bvec input) { //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 RNG_randomize(); //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; pam p(new PAM(2)); //PAM *p = new PAM(2); vec output; //modulated thing bvec demodded_out; //The following line of code simulates the transmitter end. p->modulate_bits(input,output); //The following simulates the receiver end. p->demodulate_bits(output,demodded_out); if(demodded_out == input) { return true; } return false; }
This paste will be private.
From the Design Piracy series on my blog: