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

📄 rserrpuncdecoding.cpp

📁 在vc上做的802.16d ofdm phy的仿真
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	pErrPuncLocator[0] = 1;
	for (i = (numOfErr + numOfPunc); i > numOfErr; i--)
	{
		pErrPuncLocator[i] = 0;
		if (i >= numOfPunc)
		{
		    for (j = 0; j <= (numOfErr + numOfPunc - i); j++)
			{
				if ((pErrorLocator[numOfErr-j] != 0) & (puncLocator[i+j-numOfErr] != 0))
		        pErrPuncLocator[i] ^= AlfaOf[(IndexOf[pErrorLocator[numOfErr-j]] + IndexOf[puncLocator[i+j-numOfErr]]) % 255];
			}
		}
		else
		{
			for (j = 0; j <= numOfErr; j++)
			{
				if ((pErrorLocator[numOfErr-j] != 0) & (puncLocator[i+j-numOfErr] != 0))
		        pErrPuncLocator[i] ^= AlfaOf[(IndexOf[pErrorLocator[numOfErr-j]] + IndexOf[puncLocator[i+j-numOfErr]]) % 255];
			}
		}
	}

	for (i = 1; i <= numOfErr; i++)
	{
		pErrPuncLocator[i] = 0;

		if (i <= numOfPunc)
		{
		    for (j = 0; j <= i; j++)
			{
				if ((pErrorLocator[i-j] != 0) & (puncLocator[j] != 0))
		        pErrPuncLocator[i] ^= AlfaOf[(IndexOf[pErrorLocator[i-j]] + IndexOf[puncLocator[j]]) % 255];
			}
		}
		else
		{
			for (j = 0; j <= numOfPunc; j++)
			{
				if ((pErrorLocator[i-j] != 0) & (puncLocator[j] != 0))
		        pErrPuncLocator[i] ^= AlfaOf[(IndexOf[pErrorLocator[i-j]] + IndexOf[puncLocator[j]]) % 255];
			}
		}
	}
}


/*****************************************************************************
 * Function  : chienSearch
 *
 * Parameters: 
 *     output: *pErrLocation   pointed to the estimated location of errors occurred. 
 *     input : *pErrLocator    pointed to the error-locator-polynomial given
 *							   by the function calcErrLocator().
 *             degOfElp        degree of error-locator-polynomial
 *			   checkLen        the length of sequence to be chien search.
 *
 * Description : if alfa^i(i=0~254) can make the result of errLocator be zero,
 *               then (255-i) is an error position.
 ****************************************************************************/
Int16 chienSearch(Int16 *pErrLocation, Uint8 *pErrLocator, Int16 degOfElp, Int16 searchLen)
{
	Uint8 noZeroElp[MAX_RSPARITY_LENGTH << 1];   // omit the item with zero coefficients in elp,
							                     // considering the computation efficiency of DSP implementation.
	Uint8 alfa[MAX_RSPARITY_LENGTH << 1];

	int idxCnt;
	int i;
	for (idxCnt = 0, i = 1; i <= degOfElp; i++)
	{
		if (pErrLocator[i] != 0)
		{
			noZeroElp[idxCnt] = pErrLocator[i];
			alfa[idxCnt++] = AlfaOf[i];
		}
	}
	
	Uint8 elpValue;
	Int16 errNum = -1;
	Int16 index = MAX_RSDECODING_BUFF_LENGTH - searchLen;
	for (i = 1; i <= MAX_RSDECODING_BUFF_LENGTH; i++)
	{
		elpValue = 1;
		for (int k = 0; k < idxCnt; k++)
		{
			noZeroElp[k] = AlfaOf[(IndexOf[noZeroElp[k]] + IndexOf[alfa[k]])%255];	
			elpValue ^= noZeroElp[k];
		}
		
		if ((elpValue == 0) && (i > index))
		{
			errNum++;
	    	pErrLocation[errNum] = MAX_RSDECODING_BUFF_LENGTH - i;
		}
	}

	return errNum + 1;
}

/*****************************************************************************
 * Function  : calcErrValue
 *
 * Parameters: 
 *     output: *pErrValue      pointed to the calculated error values.
 *     input : *pSyndrome      syndrome of the received codewords.
 *             *pErrLocator    pointed to the error-locator-polynomial given
 *							   by the function calcErrLocator().
 *             *pErrLocation   pointed to the estimated location of the errors
 *							   given by the function chienSearch()
 *             degOfElp        degree of error-locator-polynomial
 ****************************************************************************/
void calcErrValue(Uint8 *pErrValue, Uint8 *pSyndrome, Uint8 *pErrLocator, Int16 *pErrLocation, Int16 degOfElp)
{
	Uint8 errLocNum[MAX_RSPARITY_LENGTH];              // error location number
	
	for (int i = 0; i < degOfElp; i++)
	{
		errLocNum[i] = AlfaOf[pErrLocation[i]];
	}

	int degOfPuncElp = degOfElp - 1;
	Uint8 puncElp[MAX_RSPARITY_LENGTH][MAX_RSPARITY_LENGTH];

	for (i = 0; i < degOfElp; i++)
	{
		puncElp[i][0] = 1;
		for (int k = 1; k <= degOfPuncElp; k++)
		{
			puncElp[i][k] = pErrLocator[k]; 	
			if ((puncElp[i][k-1]!=0) & (errLocNum[i]!=0))
			{
				puncElp[i][k]^= AlfaOf [(IndexOf[puncElp[i][k-1]] + IndexOf[errLocNum[i]])%255];
			}
		}
	}

	Uint8 numerator, denominator, beta;
	for (int idxOfErr = 0; idxOfErr < degOfElp; idxOfErr++)
	{
		numerator = pSyndrome[degOfElp];
		for (int k = 1; k <= degOfPuncElp; k++)
		{
			if ((puncElp[idxOfErr][k]!=0) &(pSyndrome[degOfElp - k]!=0))
			{
				numerator ^= AlfaOf[(IndexOf[puncElp[idxOfErr][k]] + IndexOf[pSyndrome[degOfElp - k]])%255];
			}
		}

		beta = 1;
		denominator = 0;
		for (k = degOfPuncElp; k >= 0; k--)
		{
			if ((puncElp[idxOfErr][k]!=0) & (beta!=0))
			{
				denominator ^= AlfaOf [(IndexOf[puncElp[idxOfErr][k]] + IndexOf[beta])%255];
			}
			beta = AlfaOf [(IndexOf[beta] + IndexOf[errLocNum[idxOfErr]])%255];
		}
        pErrValue [idxOfErr] = AlfaOf [(IndexOf[numerator] + 255 - IndexOf[denominator])%255];
	}
}
/*****************************************************************************
 * Function  : rsErrPuncDecoding
 *
 * Parameters: 
 *     output: *pRsDecodingOut       pointer to the decoded bytes.
 *             rsDecodingOutLength   the number of the decoded bytes
 *			   status				 = 0, no error occured.
 *                                   = 1~8, the number of errors been corrected.
 *                                   = 0xff,the number of errors exceed the error_correct capacity.
 *
 *     input : *pRsDecodingIn        pointer to the acceived codeword  to be decoding.
 *             rsDecodingInLength    length of the infomation bytes in acceived codeword
 *       
 *             
 * Description: rs decoding, can implement variable block sizes and 
 *              variable error-correction capability.
 ****************************************************************************/
void rsErrPuncDecoding (Uint8   *pRsDecodingIn,
						Uint16  rsDecodingInLength,
						Uint16  rsParityBytes,
						Uint8   *pRsDecodingOut,
						Uint16  rsDecodingOutLength,
						Uint8   &status)
{
	Int16 numOfErrToCorr = rsParityBytes >> 1; // the maximum number of the occurred error can be corrected.
	
	Int16 numOfPunc = MAX_RSPARITY_LENGTH - rsParityBytes;

    Int16 rsDecSeqLen = rsDecodingInLength - rsParityBytes + MAX_RSPARITY_LENGTH;

	Uint8 puncLocator[17];
	calcPuncLocator(puncLocator, numOfPunc, 0);

	Uint8 syndrome[17] = {0};
	bool flagOfErrFind = false;
	flagOfErrFind = calcSyndrome(syndrome, pRsDecodingIn, rsDecodingInLength, rsParityBytes);

	Uint8 aSyndrome[17] = {0};
	amendSyndrome(aSyndrome, syndrome, puncLocator, numOfPunc);
	
	Int16 numOfErrFind = 0;
	status = 0;
	
//	*pRsDecodingOutLength = rsDecodingInLength - rsParityBytes;

	for (int i = 0; i < rsDecodingOutLength; i++)
	{
		pRsDecodingOut[i] = pRsDecodingIn[i + rsParityBytes];
	}	
	
	if (flagOfErrFind)
	{
		Uint8 errLocator[17] = {0};
		numOfErrFind = calcErrLocator(errLocator, aSyndrome, numOfErrToCorr);

		if (numOfErrFind <= numOfErrToCorr)
		{
			Uint8 errPuncLocator[17];
			calcErrPuncLocator(errPuncLocator, errLocator, puncLocator, 
						       numOfErrFind, numOfPunc);

			Int16 numOfErrPuncFind = numOfErrFind + numOfPunc;

			Int16 posOfErrPuncEst[16];
		    Int16 numOfErrPuncFixed = chienSearch(posOfErrPuncEst, errPuncLocator, numOfErrPuncFind, rsDecSeqLen);

		    if (numOfErrPuncFind != numOfErrPuncFixed)
			{	
			     status = (Int8)0x80;	// can't correct so many errors.
											    // should revise the scheme.
			}	

			Uint8 valOfErrEst[16];
		    calcErrValue (valOfErrEst, syndrome, errPuncLocator, posOfErrPuncEst, numOfErrPuncFind);

			for (i = 0; i < numOfErrFind; i++)
			{
		        if (posOfErrPuncEst[i] >= MAX_RSPARITY_LENGTH)
				{
					int index = rsDecSeqLen - 1 - posOfErrPuncEst[i];
					if (index >= 0)
		        	pRsDecodingOut[index] ^= valOfErrEst[i];      // should be revised.
				}
			}
		}			
	}	

	status = (Int8)numOfErrFind;	
}

⌨️ 快捷键说明

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