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

📄 decoding.cpp

📁 这个是数据打孔重传程序的源代码
💻 CPP
字号:
/**********************************************/
/* LDPC Decoder
/* int  DecodingF(struct BasicParaS * ctrl, double * input) 
/*      Written by: Ouyang Ziyue,
/*            Date: Dec 21st, 2007,
/*        Function: It decodes the input LLR according to the type of LDPC code selected ahead.
/* Input parameter:
/*        The length of symbols is included in the ctrl,
/*        The input includes all the input LLRs
/* Output parameter:
/*        The input of LLRs are updated,
/*        The return value is a flag to indicate that whether decoding is executed successfully.
/* Note:
/*        ctrl should be built before this function is called,
/*        The length of the input is ctrl->numOutBits .
/**********************************************/
#include "parameter_sets.h"

int  DecodingF(struct BasicParaS * ctrl, double * input) 
{
	
//	int * output = new int[ctrl->codeK];
//	int * decodeOutput = new int[ctrl->numInBits];
//	double * decodeInput = new double[ctrl->numOutBits];
	int i,m;
	struct LinkNode * currentNode;
	double * p1 = new double[ctrl->numOutBits];
	
//	if (ctrl->typeDecode==0)
//	{
//		for (i=0; i<ctrl->numOutBits; i++)
//		{
//			*(decodeInput+i) = 0.5;
//		}
//	}
//	else
//	{
//		for (i=0; i<ctrl->numOutBits; i++)
//		{
//			*(decodeInput+i) = 0;
//		}
//	}
//
//	// Resume those punctured or truncated bits
//	if (ResumeBitsF(ctrl, input, decodeInput))
//	{
//		printf("Resume is broken!!!\n");
//		exit(0);
//	}
//
//#ifdef DEBUG
//	printf("The decodeInput is...\n");
//	int h=0;
//	for (i=0;i<ctrl->numOutBits;i++)
//	{
//		printf(" %2f", *(decodeInput+i));
//		h++;
//		h%=8;
//		if (h==0)
//		{
//			printf("\n");
//			h=0;
//		}
//
//	}
//#endif

	// Initialize the priori
	for (i=0; i<ctrl->numOutBits; i++) {
		*(p1+i) = *(input+i);
	}

	// Choose the algorithm
	switch (ctrl->typeDecode) {
	case 0: // SPA
		for (i=0; i<ctrl->numOutBits; i++) {
			currentNode = *(ctrl->colLink+i);
			while (currentNode != NULL) {
				currentNode->qMsg[1] = *(input+i);
				currentNode->qMsg[0] = 1-(*(input+i));
				currentNode = currentNode->colPtr;
			}
		}
		if ((m=SumProductF(ctrl, p1)) == 0) {
#ifdef DEBUG
			printf("Parity-Checking is passed ..\n");
#endif			
		} else {
#ifdef DEBUG
			printf("Parity-Checking is failed ..\n");
#endif				
		}
		break;
	case 1: // LSPA
		for (i=0; i<ctrl->numOutBits; i++) {
			currentNode = *(ctrl->colLink+i);
			while (currentNode != NULL) {
				currentNode->qMsg[1] = 0;
				currentNode->qMsg[0] = *(input+i);
				currentNode = currentNode->colPtr;
			}
		}
		if ((m=LogSumProductF(ctrl, p1)) == 0){
#ifdef DEBUG
			printf("Parity-Checking is passed ..\n");
#endif				
		} else {
#ifdef DEBUG
			printf("Parity-Checking is failed ..\n");
#endif				
		}
		break;
	case 2: // MSA
		for (i=0; i<ctrl->numOutBits; i++) {
			currentNode = *(ctrl->colLink+i);
			while (currentNode != NULL) {
				currentNode->qMsg[1] = 0;
				currentNode->qMsg[0] = *(input+i);
				currentNode = currentNode->colPtr;
			}
		}
		if ((m=(MinSumF(ctrl, p1)) == 0)) {
#ifdef DEBUG
			printf("Parity-Checking is passed ..\n");
#endif				
		} else {
#ifdef DEBUG
			printf("Parity-Checking is failed ..\n");
#endif				
		}
		break;
	default:
		exit(EXIT_FAILURE);
	}

	// Extract the info bits
//	for (i=0; i<ctrl->codeK; i++) {
//		*(output+i) = *(decodeOutput+ctrl->numInBits-ctrl->codeK+i);
//	}

//#ifdef DEBUG
//	printf("This is the cross link per row ..\n");
//		for (i=0; i<ctrl->numChk; i++) {
//			currentNode = *(ctrl->rowLink+i);
//			while (currentNode != NULL) {
//				printf("(%d,%d,q0=%.2f,q1=%.2f)->", currentNode->rowIdx, currentNode->colIdx, 
//					currentNode->qMsg[0], currentNode->qMsg[1]);
//				currentNode = currentNode->rowPtr;
//			}
//			printf("End of Row\n");
//		}
//
//		printf("This is the cross link per col ..\n");
//		for (i=0; i<ctrl->numOutBits; i++) {
//			currentNode = *(ctrl->colLink+i);
//			while (currentNode != NULL) {
//				printf("(%d,%d,q0=%.2f,q1=%.2f)->", currentNode->rowIdx, currentNode->colIdx, 
//					currentNode->qMsg[0], currentNode->qMsg[1]);
//				currentNode = currentNode->colPtr;
//			}
//			printf("End of Col\n");
//		}
//#endif
		

	for (i=0; i<ctrl->numOutBits;i++)
	{
		* (input+i) = * (p1+i);
	}

//	delete [] decodeInput;
//	delete [] decodeOutput;
	delete [] p1;

	return m;
}

⌨️ 快捷键说明

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