Esempio n. 1
0
    lib::error_code client_handshake_request(request_type& req, uri_ptr uri,
            std::vector<std::string> const & subprotocols) const
    {
        req.set_method("GET");
        req.set_uri(uri->get_resource());
        req.set_version("HTTP/1.1");

        req.append_header("Upgrade", "websocket");
        req.append_header("Connection", "Upgrade");
        req.replace_header("Sec-WebSocket-Version", "13");
        req.replace_header("Host", uri->get_host_port());

        if (!subprotocols.empty())
        {
            std::ostringstream result;
            std::vector<std::string>::const_iterator it = subprotocols.begin();
            result << *it++;
            while (it != subprotocols.end())
            {
                result << ", " << *it++;
            }

            req.replace_header("Sec-WebSocket-Protocol", result.str());
        }

        // Generate handshake key
        frame::uint32_converter conv;
        unsigned char raw_key[16];

        for (int i = 0; i < 4; i++)
        {
            conv.i = m_rng();
            std::copy(conv.c, conv.c + 4, &raw_key[i * 4]);
        }

        req.replace_header("Sec-WebSocket-Key", base64_encode(raw_key, 16));

        return lib::error_code();
    }
Esempio n. 2
0
void BlockRandomizer::RandomizeChunks()
{
    // Create vector of chunk indices and shuffle them using current sweep as seed
    std::vector<size_t> randomizedChunkIndices;
    randomizedChunkIndices.reserve(m_numChunks);
    for (size_t i = 0; i < m_numChunks; i++)
    {
        randomizedChunkIndices.push_back(i);
    }

    if (m_useLegacyRandomization)
    {
        RandomShuffle(randomizedChunkIndices, m_sweep);
    }
    else
    {
        std::mt19937 m_rng((int)m_sweep);
        std::shuffle(randomizedChunkIndices.begin(), randomizedChunkIndices.end(), m_rng);
    }

    // Place randomized chunks on global time line
    m_randomizedChunks.clear();
    m_randomizedChunks.reserve(m_numChunks + 1);
    size_t chunkId, samplePosition, sequencePosition;
    for (chunkId = 0, samplePosition = m_sweepStartInSamples, sequencePosition = 0; chunkId < m_numChunks; chunkId++)
    {
        const size_t originalChunkIndex = randomizedChunkIndices[chunkId];
        const size_t numSequences =
            m_chunkInformation[originalChunkIndex + 1].m_sequencePositionStart -
            m_chunkInformation[originalChunkIndex].m_sequencePositionStart;
        const size_t numSamples =
            m_chunkInformation[originalChunkIndex + 1].m_samplePositionStart -
            m_chunkInformation[originalChunkIndex].m_samplePositionStart;
        m_randomizedChunks.push_back(RandomizedChunk{ sequencePosition, samplePosition, originalChunkIndex });
        samplePosition += numSamples;
        sequencePosition += numSequences;
    }

    // Add sentinel
    m_randomizedChunks.push_back(RandomizedChunk{ sequencePosition, samplePosition, SIZE_MAX });

    // For each chunk, compute the randomization range (w.r.t. the randomized chunk sequence)
    size_t halfWindowRange = m_randomizationRangeInSamples / 2;
    for (size_t chunkId = 0; chunkId < m_numChunks; chunkId++)
    {
        auto& chunk = m_randomizedChunks[chunkId];
        // start with the range of left neighbor
        if (chunkId == 0)
        {
            chunk.m_windowBegin = 0;
            chunk.m_windowEnd = 1;
        }
        else
        {
            chunk.m_windowBegin = m_randomizedChunks[chunkId - 1].m_windowBegin; // might be too early
            chunk.m_windowEnd = m_randomizedChunks[chunkId - 1].m_windowEnd; // might have more space
        }
        while (chunk.m_info.m_samplePositionStart - m_randomizedChunks[chunk.m_windowBegin].m_info.m_samplePositionStart > halfWindowRange)
            chunk.m_windowBegin++; // too early
        // TODO m_randomizedChunks[chunk.windowend + 1].info.samplePositionStart - m_randomizedChunks[chunk.windowbegin].info.samplePositionStart < m_randomizationRangeInSamples
        while (chunk.m_windowEnd < m_numChunks &&
            m_randomizedChunks[chunk.m_windowEnd + 1].m_info.m_samplePositionStart - chunk.m_info.m_samplePositionStart < halfWindowRange)
            chunk.m_windowEnd++; // got more space
    }
}
Esempio n. 3
0
int main(int argc, char const *argv[])
{
	// rng stuff
	std::random_device rd; // device entropy
    std::mt19937 m_rng(rd()); // initialize our mersenne twister with a random seed
    std::uniform_real_distribution<double> double_gen(1e-300,38);

	// ---------------------------------- check correctness of checkNodes computations in VariableNode --------------------------
	for(int a = 0; a < 111; ++a) {
		for(int b = 0; b < 293; ++b) {
			VariableNode node(a, b);
			for(int i = 0; i < 7; ++i) { // a*slope +    c  		
				if( ((a*slopes[node.getCheckNodes()[i].first]  + node.getCheckNodes()[i].second)%293 != b) || node.getCheckNodes()[i].second < 0) {
					if (!(node.getCheckNodes()[i].second < 0 && reverseModulo((int)ALL_COLUMNS, a*slopes[i], b) == 292)) { // c = 292 -> c = -1
						std::cout << "a = " << a << " b = " << b << " s_index = " << node.getCheckNodes()[i].first << " c = " << node.getCheckNodes()[i].second << "\n";
					}
				}

			}
		}
	}

	// ------------------------------------------- test phiTilde function for large values ----------------------------------------
	for(int i = 30; i < 40; ++i) {
		std::cout << "i = " << i << " phiTilde = " << phiTilde(i) << " isNaN? " << isnan(phiTilde(i)) << "\n";
	}

	// ----------------------------------------- test phiTilde function for very small values -------------------------------------
	for(int i = 300; i < 320; i++) {
		std::cout << "10^{-" << i << "} = " << std::pow(10, -i) << " phiTilde = " << phiTilde(std::pow(10, -i)) << "\n";
	}

	// ------------------------------------------------------ test infinity sum ---------------------------------------------------
	std::cout << "Expecting inf -> " << phiTilde(std::pow(10, -400)) + 2 << "\n";
	std::cout << "Expecting -inf -> " << -phiTilde(std::pow(10, -400)) + 2 << "\n";
	std::cout << "Expecting 2 -> " <<  phiTilde(phiTilde(std::pow(10, -400))) + 2 << "\n";

	// ---------------------------------------------------- phiTilde performances -------------------------------------------------
	const int N = 1e6;
	// create N random values
	std::array<double, N> random_array;
	for(int i = 0; i < N; ++i) {
		random_array[i] = double_gen(m_rng);
	}

	std::chrono::time_point<std::chrono::system_clock> begin = std::chrono::system_clock::now();
	double val;
	for(int i = 0; i < N; ++i) {
		val = phiTilde(random_array[i]);
	}
	std::chrono::nanoseconds duration = std::chrono::system_clock::now() - begin;
	std::cout << "Average time to compute phiTilde(x) " << (double)duration.count()/N << " ns\n";

	// ----------------------------------------- test the update LLR function on variableNode --------------------------------------
	int a = 1;
	int b = 0;
	VariableNode node(a, b);
	for(int i = 0; i < 7; ++i) {
		std::cout << slopes[node.getCheckNodes()[i].first] << " c " << node.getCheckNodes()[i].second << "\n";
	}
	// set channel LLR and propagate it
	node.setChannelLLR(6);
	for(int i = 0; i < PC_ROWS + 1; ++i) {
		std::cout << "LLR = " << node.getLLRat(i) << "\n";
	}
	
	// create checkNodesVector
	std::vector<CheckNode> *checkNodesVector = new std::vector<CheckNode>(2051);
	for(int slope_index = 0; slope_index < (int)PC_ROWS - 1; ++slope_index) { // init the first six blocks
		for(int c = 0; c < (int)ALL_COLUMNS - 1; ++c) { // with 292 valid nodes each
			checkNodesVector->at(slope_index*(int)ALL_COLUMNS + c).setLine(line(slope_index, c));
		}
	}
	// init the last block
	for(int c = 0; c < (int)ALL_COLUMNS; ++c) { // with 293 valid nodes 
		checkNodesVector->at(((int)PC_ROWS - 1)*(int)ALL_COLUMNS + c).setLine(line((int)PC_ROWS - 1, c));
	}

	// fill the LLR of the blocks for (1,0) -> 0+293, 293+291, 293*2+290, 293*3+289, 293*4+288, 293*5 + 287, 293*6+286, each at row 1
	checkNodesVector->at(293).setLLRat(3, 1); // this will not be summed, since this check node is not valid
	checkNodesVector->at(293+291).setLLRat(3, 1);
	checkNodesVector->at(293*2+290).setLLRat(2, 1);
	checkNodesVector->at(293*3+289).setLLRat(-4, 1);
	checkNodesVector->at(293*4+288).setLLRat(-1, 1);
	checkNodesVector->at(293*5+287).setLLRat(3, 1);
	checkNodesVector->at(293*6+286).setLLRat(0, 1);

	node.updateLLR(checkNodesVector);
	std::cout << "LLR = " << node.getLLRat(0) << " expecting 9\n";
	std::cout << "LLR = " << node.getLLRat(1) << " expecting 6\n";
	std::cout << "LLR = " << node.getLLRat(2) << " expecting 7\n";
	std::cout << "LLR = " << node.getLLRat(3) << " expecting 13\n";
	std::cout << "LLR = " << node.getLLRat(4) << " expecting 10\n";
	std::cout << "LLR = " << node.getLLRat(5) << " expecting 6\n";
	std::cout << "LLR = " << node.getLLRat(6) << " expecting 9\n";
	std::cout << "LLR = " << node.getLLRat(7) << " expecting 3\n";

	delete checkNodesVector;

	// ----------------------------------------- test the update LLR function on checkNode ----------------------------------------
	// Create VariableNode vector
	std::vector<VariableNode> *variableNodeVector = new std::vector<VariableNode>;
	variableNodeVector->resize(ALL_COLUMNS*ALL_ROWS);
	// Init its coordinates
	for(int node_index = 0; node_index < variableNodeVector->size(); ++node_index) {
															// row 						// column
		variableNodeVector->at(node_index).setCoordinates(node_index/(int)ALL_COLUMNS, node_index%(int)ALL_COLUMNS);
	}

	int line_index = 2;
	int node_c = 3;
	CheckNode check_node(line(line_index,node_c));
	double all_llr = -11;
	// init LLR on the corresponding nodes
	for(int a = 0; a < (int)ALL_ROWS; ++a) {
		variableNodeVector->at(a*ALL_COLUMNS + (slopes[line_index]*a + node_c)%ALL_COLUMNS).setLLRat(all_llr, line_index);
	}
	// set an LLR on a different branch to 0 and check that it does not change the results
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(0, line_index+1);

	double phiTildeNode = phiTilde(std::abs(all_llr));
	double exp_llr = (all_llr > 0) ? phiTilde(111*phiTildeNode) : -phiTilde(111*phiTildeNode);
	begin = std::chrono::system_clock::now();
	check_node.updateLLR(variableNodeVector);
	std::cout << "updateLLR time " << (double)(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - begin)).count()/1000 << " ms\n";
	std::cout << "Expecting " << exp_llr << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";

	variableNodeVector->at(110*ALL_COLUMNS + (slopes[line_index]*110 + node_c)%ALL_COLUMNS).setLLRat(-all_llr, line_index);
	phiTildeNode = phiTilde(std::abs(all_llr));
	exp_llr = (all_llr > 0) ? -phiTilde(111*phiTildeNode) : phiTilde(111*phiTildeNode);
	begin = std::chrono::system_clock::now();
	check_node.updateLLR(variableNodeVector);
	std::cout << "updateLLR time " << (double)(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - begin)).count()/1000 << " ms\n";
	std::cout << "Expecting " << exp_llr << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << -exp_llr << " computed " << check_node.getLLRat(110) <<"\n";

	variableNodeVector->at(107*ALL_COLUMNS + (slopes[line_index]*107 + node_c)%ALL_COLUMNS).setLLRat(-all_llr, line_index);
	phiTildeNode = phiTilde(std::abs(all_llr));
	exp_llr = (all_llr > 0) ? phiTilde(111*phiTildeNode) : -phiTilde(111*phiTildeNode);
	check_node.updateLLR(variableNodeVector);
	std::cout << "Expecting " << exp_llr << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << -exp_llr << " computed " << check_node.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << -exp_llr << " computed " << check_node.getLLRat(107) <<"\n";



	// set one LLR to 0 -> also the resulting llr should be 0
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(0, line_index);
	phiTildeNode = phiTilde(std::abs(all_llr));
	exp_llr = (all_llr > 0) ? phiTilde(111*phiTildeNode) : -phiTilde(111*phiTildeNode);
	check_node.updateLLR(variableNodeVector);
	std::cout << "Expecting " << 0 << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << 0 << " computed " << check_node.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << 0 << " computed " << check_node.getLLRat(107) <<"\n";
	std::cout << "For node 106, expecting " << exp_llr << " computed " << check_node.getLLRat(106) <<"\n";


	// set one LLR to infinity -> the result is given only by the other ones
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(std::numeric_limits<double>::infinity(), line_index);
	phiTildeNode = phiTilde(std::abs(all_llr));
	exp_llr = phiTilde(110*phiTildeNode);
	check_node.updateLLR(variableNodeVector);
	std::cout << "Expecting " << exp_llr << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << -exp_llr << " computed " << check_node.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << -exp_llr << " computed " << check_node.getLLRat(107) <<"\n";
	std::cout << "For node 106, expecting " << ((all_llr > 0) ? phiTilde(111*phiTildeNode) : -phiTilde(111*phiTildeNode)) << " computed " << check_node.getLLRat(106) <<"\n";


	for(int a = 0; a < (int)ALL_ROWS; ++a) {
		variableNodeVector->at(a*ALL_COLUMNS + (slopes[line_index]*a + node_c)%ALL_COLUMNS).setLLRat(std::numeric_limits<double>::infinity(), line_index);
	}
	phiTildeNode = phiTilde(std::abs(std::numeric_limits<double>::infinity()));
	exp_llr = (std::numeric_limits<double>::infinity() > 0) ? phiTilde(111*phiTildeNode) : -phiTilde(111*phiTildeNode);
	check_node.updateLLR(variableNodeVector);
	std::cout << "Expecting " << exp_llr << " computed " << check_node.getLLRat(1) << " " <<  check_node.getLLRat(2) <<"\n";

	// ----------------------------------------- test the min sum update LLR function on checkNode ----------------------------------------

	std::cout << "Min Sum test\n";
	line_index = 2;
	node_c = 3;
	CheckNode check_node_ms = CheckNode(line(line_index,node_c));
	all_llr = -11;
	// init LLR on the corresponding nodes
	for(int a = 0; a < (int)ALL_ROWS; ++a) {
		variableNodeVector->at(a*ALL_COLUMNS + (slopes[line_index]*a + node_c)%ALL_COLUMNS).setLLRat(all_llr, line_index);
	}
	// set an LLR on a different branch to 0 and check that it does not change the results
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(0, line_index+1);

	begin = std::chrono::system_clock::now();
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "updateLLR time " << (double)(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - begin)).count()/1000 << " ms\n";
	std::cout << "Expecting " << all_llr << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";

	variableNodeVector->at(110*ALL_COLUMNS + (slopes[line_index]*110 + node_c)%ALL_COLUMNS).setLLRat(-all_llr, line_index);
	exp_llr = -all_llr;
	begin = std::chrono::system_clock::now();
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "updateLLR time " << (double)(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - begin)).count()/1000 << " ms\n";
	std::cout << "Expecting " << exp_llr << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << -exp_llr << " computed " << check_node_ms.getLLRat(110) <<"\n";


	variableNodeVector->at(107*ALL_COLUMNS + (slopes[line_index]*107 + node_c)%ALL_COLUMNS).setLLRat((all_llr > 0 ? -(all_llr - 1) : -(all_llr + 1)), line_index);
	exp_llr = (all_llr > 0) ? all_llr-1 : -(all_llr-1);
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "Expecting " << (all_llr > 0 ? (all_llr - 1) : (all_llr + 1)) << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << (all_llr < 0 ? -(all_llr + 1) : -(all_llr - 1))   << " computed " << check_node_ms.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << -all_llr << " computed " << check_node_ms.getLLRat(107) <<"\n";



	// set one LLR to 0 -> also the resulting llr should be 0
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(0, line_index);
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "Expecting " << 0 << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << 0 << " computed " << check_node_ms.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << 0 << " computed " << check_node_ms.getLLRat(107) <<"\n";
	std::cout << "For node 106, expecting " << (all_llr > 0 ? (all_llr - 1) : (all_llr + 1)) << " computed " << check_node_ms.getLLRat(106) <<"\n";


	// set one LLR to infinity -> the result is given only by the other ones
	variableNodeVector->at(106*ALL_COLUMNS + (slopes[line_index]*106 + node_c)%ALL_COLUMNS).setLLRat(std::numeric_limits<double>::infinity(), line_index);
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "Expecting " << (all_llr > 0 ? (all_llr - 1) : -(all_llr + 1)) << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";
	std::cout << "For node 110, expecting " << -(all_llr > 0 ? (all_llr - 1) : -(all_llr + 1)) << " computed " << check_node_ms.getLLRat(110) <<"\n";
	std::cout << "For node 107, expecting " << (all_llr > 0 ? -all_llr : all_llr) << " computed " << check_node_ms.getLLRat(107) <<"\n";
	std::cout << "For node 106, expecting " << (all_llr > 0 ? (all_llr - 1) : (all_llr + 1)) << " computed " << check_node_ms.getLLRat(106) <<"\n";


	for(int a = 0; a < (int)ALL_ROWS; ++a) {
		variableNodeVector->at(a*ALL_COLUMNS + (slopes[line_index]*a + node_c)%ALL_COLUMNS).setLLRat(std::numeric_limits<double>::infinity(), line_index);
	}
	check_node_ms.updateLLRminSum(variableNodeVector);
	std::cout << "Expecting " << std::numeric_limits<double>::infinity() << " computed " << check_node_ms.getLLRat(1) << " " <<  check_node_ms.getLLRat(2) <<"\n";
	
	return 0;
}
Esempio n. 4
0
    /**
     * Performs validation, masking, compression, etc. will return an error if
     * there was an error, otherwise msg will be ready to be written
     *
     * TODO: tests
     *
     * @param in An unprepared message to prepare
     * @param out A message to be overwritten with the prepared message
     * @return error code
     */
    virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)
    {
        if (!in || !out) {
            return make_error_code(error::invalid_arguments);
        }

        frame::opcode::value op = in->get_opcode();

        // validate opcode: only regular data frames
        if (frame::opcode::is_control(op)) {
            return make_error_code(error::invalid_opcode);
        }

        std::string& i = in->get_raw_payload();
        std::string& o = out->get_raw_payload();

        // validate payload utf8
        if (op == frame::opcode::TEXT && !utf8_validator::validate(i)) {
            return make_error_code(error::invalid_payload);
        }

        frame::masking_key_type key;
        bool masked = !base::m_server;
        bool compressed = m_permessage_deflate.is_enabled()
                          && in->get_compressed();
        bool fin = in->get_fin();

        // generate header
        frame::basic_header h(op,i.size(),fin,masked,compressed);

        if (masked) {
            // Generate masking key.
            key.i = m_rng();

            frame::extended_header e(i.size(),key.i);
            out->set_header(frame::prepare_header(h,e));
        } else {
            frame::extended_header e(i.size());
            out->set_header(frame::prepare_header(h,e));
            key.i = 0;
        }

        // prepare payload
        if (compressed) {
            // compress and store in o after header.
            m_permessage_deflate.compress(i,o);

            // mask in place if necessary
            if (masked) {
                this->masked_copy(o,o,key);
            }
        } else {
            // no compression, just copy data into the output buffer
            o.resize(i.size());

            // if we are masked, have the masking function write to the output
            // buffer directly to avoid another copy. If not masked, copy
            // directly without masking.
            if (masked) {
                this->masked_copy(i,o,key);
            } else {
                std::copy(i.begin(),i.end(),o.begin());
            }
        }

        out->set_prepared(true);
        out->set_opcode(op);

        return lib::error_code();
    }
int main(int argc, char const *argv[])
{
	// rng stuff
	std::random_device rd; // device entropy
    std::mt19937 m_rng(rd()); // initialize our mersenne twister with a random seed
    std::uniform_int_distribution<int> bit_generator(0,0);
    std::normal_distribution<double> noise_generator(0,1);

	//create information word
	InfoWord infoword;
	for(int bit_index = 0; bit_index < (int)INFO_BIT; ++bit_index) { 
		infoword[mapJtoK(bit_index)] = (bit_generator(m_rng)==1);
	}

	// encode
	LdpcEncoder encoder = LdpcEncoder();
	std::cout << "LdpcEncoder created\n";
	// import matrix
	if(encoder.setup() == 0) {std::cout << "File opened and read successfully\n";}
	else {std::cout << "Error in opening matrix file, abort\n"; return 2;}
	CodeWord codeword = encoder.encode(infoword);

	// add noise
	double ebn0 = atof(argv[1]);
	double sigma_w = 1/std::sqrt(2*std::pow(10, (ebn0/10)) * INFO_BIT/CODE_WORD);
	std::cout << "sigma_w " << sigma_w << "\n";
	std::vector<double> *received_signal = new std::vector<double>;
	received_signal->resize(ALL_COLUMNS*ALL_ROWS, -1);

	// copy the first 120 bit of the codeword, then skip 173 zeros
	int cw_bit_index = 0;
	for(; cw_bit_index < ALL_COLUMNS - INIT_ZERO_BIT; cw_bit_index++) {
		received_signal->at(cw_bit_index) = ((codeword[cw_bit_index] == 0) ? -1:1)  + sigma_w*noise_generator(m_rng);
	}
	int all_offset = (int)INIT_ZERO_BIT;
	// copy up to						30765 - 1, which is bit 30592 - 1 in the codeword
	for(; cw_bit_index + all_offset < (int)ALL_INFO_BIT; cw_bit_index++) { 
		received_signal->at(cw_bit_index + all_offset) = ((codeword[cw_bit_index] == 0) ? -1:1) + sigma_w*noise_generator(m_rng);
	}
	// skip 3 zeros in the codeword, but not in all_bit
	cw_bit_index += 3;
	all_offset -= 3;
	for(int i = 1; i < 7; ++i) {
		for(; cw_bit_index + all_offset < (int)ALL_INFO_BIT + (i)*(int)ALL_COLUMNS - 1; cw_bit_index++) { 
		// skip bit 31057, 31350, 31643, 31936, 32229, 32522 in all_bits
			received_signal->at(cw_bit_index + all_offset) = ((codeword[cw_bit_index] == 0) ? -1:1) + sigma_w*noise_generator(m_rng);
		}
		all_offset += 1; 
	}
	// copy the last 293 bit
	for(; cw_bit_index + all_offset < (int)ALL_INFO_BIT + 7*(int)ALL_COLUMNS; cw_bit_index++) { // up to the last bit 
		received_signal->at(cw_bit_index + all_offset) = ((codeword[cw_bit_index] == 0) ? -1:1) + sigma_w*noise_generator(m_rng);
	}

	// decode
	LdpcDecoder decoder = LdpcDecoder();
	std::chrono::time_point<std::chrono::system_clock> begin = std::chrono::system_clock::now();
	std::vector<bool> *decoded_symbols = decoder.decode(received_signal, std::pow(sigma_w, 2));
	std::chrono::microseconds duration = std::chrono::system_clock::now() - begin;
	std::cout << "Decoding time " << (double)duration.count()/1000 << " ms\n";

	// check
	int num_error = 0;
	for(int i = 0; i < 120; i++) {
		if(!(decoded_symbols->at(i) == infoword[i])) {
			//std::cout << "Index " << i << " " << decoded_symbols[i] << " while info_bit " << infoword[i] << " codeword " << codeword[i] << " received_signal " << received_signal->at(i) << "\n";
			num_error++;
		}
	}
	for(int i = 293; i < 30765; i++) {
		if(!(decoded_symbols->at(i) == (bool)infoword[i])) {
			//std::cout << "Index " << i << " " << decoded_symbols[i] << " while info_bit " << infoword[i+173] << " codeword " << codeword[i] << " received_signal " << received_signal->at(i + 173) << "\n";
			num_error++;
		}
	}
	std::cout << "BER " << (double)num_error/INFO_BIT << "\n";
	std::cout << "Numerror " << (double)num_error << "\n";

	return 0;
}
Esempio n. 6
0
 //! generate a random number
 DINLINE
 typename T_Rng::result_type
 operator()()
 {
     return m_rng( *m_acc );
 }