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

📄 decoding.cpp

📁 这是校验位打孔重传的源程序
💻 CPP
字号:
#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;
	struct LinkNode * currentNode;
	double * p1 = new double[ctrl->numOutBits];
	

	// Resume those punctured or truncated bits
	if (ResumeBitsF(ctrl, input, decodeInput)) 
	{
		printf("Resume is broken!!!\n");
		exit(EXIT_FAILURE);
	}

	// Initialize the priori
	for (i=0; i<ctrl->numOutBits; i++) 
	{
		*(p1+i) = *(decodeInput+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] = *(decodeInput+i);
				currentNode->qMsg[0] = 1-(*(decodeInput+i));
				currentNode = currentNode->colPtr;
			}
		}
		if (SumProductF(ctrl, decodeOutput, p1) == 0) 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is passed ..\n");
		}
		else 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is failed ..\n");
		}
		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] = *(decodeInput+i);
				currentNode = currentNode->colPtr;
			}
		}
		if (LogSumProductF(ctrl, decodeOutput, p1) == 0) 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is passed ..\n");
		} 
		else 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is failed ..\n");
		}
		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] = *(decodeInput+i);
				currentNode = currentNode->colPtr;
			}
		}
		if (MinSumF(ctrl, decodeOutput, p1) == 0) 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is passed ..\n");
		} 
		else 
		{
			if (ctrl->mode == 1)
				printf("Parity-Checking is failed ..\n");
		}
		break;
	default:
		exit(EXIT_FAILURE);
	}

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

	if (ctrl->mode == 1)
	{
		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");
		}
	}

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

	return output;
}

⌨️ 快捷键说明

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