⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sumproduct.cpp

📁 这个是数据打孔重传程序的源代码
💻 CPP
字号:
#include "parameter_sets.h"

int SumProductF(struct BasicParaS * ctrl,  double * prob1) {

	int iter, i, sum, flag;
	struct LinkNode * currentNode, * iterNode;
	int M = ctrl->numChk;
	int N = ctrl->numVar;
	double temp0, temp1, K;
	double p0, p1;
	int * varbits = new int[N];
	double * prob = new double[N];

	// Iterate to flood the message throughout the whole graph
	for (iter = 0; iter<ctrl->maxIter; iter++) {
#ifdef DEBUG
		printf("Iterate to decode .. %d\n", iter);
#endif			
		// Horizontal step, for each check node
		for (i=0; i<M; i++) {
			currentNode = *(ctrl->rowLink+i);
			// Update Rji message for each variable node
			while (currentNode != NULL) {
				// Calculate the Rji for the current variable node
				temp1 = 1;
				iterNode = *(ctrl->rowLink+i); // iter from the first node in the same row
				while (iterNode != NULL) {
					if (iterNode != currentNode)
						temp1 *= 1-2*iterNode->qMsg[1];
					iterNode = iterNode->rowPtr; // move to the next node in the same row
				}
				currentNode->rMsg[0] = 0.5+temp1/2; // update the r0 message
				currentNode->rMsg[1] = 1-currentNode->rMsg[0]; // update the r1 message
				currentNode = currentNode->rowPtr; // move to the next node in the same row
			}
		}

		// Vertical step, for each variable node
		for (i=0; i<N; i++) {
			currentNode = *(ctrl->colLink+i);
			// Update Qij message for each check node
			while (currentNode != NULL) {
				// Calculate the Qij for the current check node
				temp0 = 1;
				temp1 = 1;
				iterNode = *(ctrl->colLink+i); // iter from the first node in the same col
				while (iterNode != NULL) {
					if (iterNode != currentNode) {
						temp0 *= iterNode->rMsg[0];
						temp1 *= iterNode->rMsg[1];
					}
					iterNode = iterNode->colPtr; // move to the next node in the same col
				}
				p1 = *(prob1+i);
				p0 = 1 - p1;
				K = 1/(p0*temp0+p1*temp1); // K is the normalization factor
				currentNode->qMsg[0] = K*p0*temp0; // update the q0 message
				currentNode->qMsg[1] = K*p1*temp1; // update the q1 message
				currentNode = currentNode->colPtr; // move to the next node in the same col
			}
		}

		// Calculte the Q for each variable node and Decision
		for (i=0; i<N; i++) {
			temp0 = 1;
			temp1 = 1;
			iterNode = *(ctrl->colLink+i);
			while (iterNode != NULL) {
				temp0 *= iterNode->rMsg[0];
				temp1 *= iterNode->rMsg[1];
				iterNode = iterNode->colPtr; // move to the next node in the same col
			}
			p1 = *(prob1+i);
			p0 = 1 - p1;
			K = 1/(p0*temp0+p1*temp1); // K is the normalization factor
			temp1 = K*p0*temp0;
			* (prob + i) = temp1;
			if (temp1>0.5) {
				*(varbits+i) = 0;
			} else {
				*(varbits+i) = 1;
			}
		}

		// Check whether the current output is currect
		flag = 0;
		for (i=0; i<M; i++) {
			sum = 0;
			iterNode = *(ctrl->rowLink+i);
			while (iterNode != NULL) {
				sum += *(varbits+iterNode->colIdx);
				sum %= 2;
				iterNode = iterNode->rowPtr;
			}
			if (sum != 0)
				flag++;
		}
		if (flag == 0)
		{
			ctrl->numIter += (iter+1); 
			break;
		}
	}

	
		for(i=0; i<N; i++)
			*(prob1+i) = *(prob+i);

//	for (i=0; i<ctrl->numInBits; i++) {
//		*(output+i) = *(varbits+i);
//	}

#ifdef DEBUG
			iter = 0;
		printf("The output of decoding are ..\n");
		for (i=0; i<N; i++) {
			printf(" %d", *(varbits+i));
			iter++;
			if (iter == 24) {
				iter = 0;
				printf("\n");
			}
		}

#endif



	delete [] varbits;
	delete [] prob;

	if (flag == 0) 
		return 0;
	else
	{
		ctrl->numIter += ctrl->maxIter;
		return 1;
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -