📄 rserrpuncdecoding.cpp
字号:
/***************************************************************************
*
* Copyright (c) 2004, Coast Co. Ltd.
*
* All rights reserved.
*
*
* Filename:rsErrPuncDecoding.cpp
*
* File Description:
* Implementation of decoding of Reed-Solomon codes, enabling variable block sizes
* and variable error-correction capability.
* -------------------------------------------------------------
*
* Revision:2.0
* Author Hu Bo
* Date :23/12/2004
*
* Revision Details
* ----------------
*
****************************************************************************/
/*****************************************************************************
* Include Files
****************************************************************************/
#include "typedef.h"
#include "global_var.h"
#include "globalMacro.h"
#include "rsErrPuncDecoding.h"
/*****************************************************************************
* Function : calcPuncLocator
*
* Parameters:
* output: *puncLocator pointer to the array to store the coeff of the
* puncture locator polynomial.
* input : numOfPunc the number of punctures, continuous in position.
* initPuncPos the initial position that the data been punctured.
****************************************************************************/
void calcPuncLocator(Uint8 *puncLocator, Int16 numOfPunc, Int16 initPuncPos)
{
puncLocator[0] = 1;
if (numOfPunc > 0)
puncLocator[1] = AlfaOf[initPuncPos];
if (numOfPunc >= 2)
{
for (int i = 2; i <= numOfPunc; i++)
{
if (puncLocator[i-1] != 0)
{
puncLocator[i] = AlfaOf[(IndexOf[puncLocator[i-1]] + initPuncPos+i-1) % 255];
}
for (int j = i - 1; j > 0; j--)
{
if (puncLocator[j-1] != 0)
puncLocator[j] ^= AlfaOf[(IndexOf[puncLocator[j-1]] + initPuncPos+i-1) % 255];
}
}
}
}
/*****************************************************************************
* Function : calcSyndrome
*
* Parameters:
* output: *pSyndrome pointer to the pSyndrome sequnce -- pSyndrome[2*corrlen+1]
* the element pSyndrome[0] is not used.
* input : *pCodedBytes pointer to the acceived codewords.
* numOfCodedBytes the number of acceived codewords.
* maxNumOfErrToCorr the maximum number of the error occured can be corrected,
* always T = 8.
* Returns : errFlag the flag of error occured. In this implementation
* errFlag == true, if errors occured
* errFlag == false, if find no errors
****************************************************************************/
bool calcSyndrome(Uint8 *pSyndrome, Uint8 *pCodedBytes, Int16 numOfCodedBytes, Int16 rsParityBytes)
{
bool errFlag = false;
Int16 numOfSyndrome = MAX_RSPARITY_LENGTH;
for (int i = 1; i <= numOfSyndrome; i++)
{
pSyndrome[i] = 0;
for (int k = rsParityBytes; k < numOfCodedBytes + rsParityBytes; k++)
{
if (pCodedBytes[k % numOfCodedBytes])
{
int index = numOfSyndrome - 1 + numOfCodedBytes - k;
pSyndrome[i] ^= AlfaOf[(IndexOf[pCodedBytes[k % numOfCodedBytes]] + index*(i-1))%255];
}
}
errFlag |= (pSyndrome[i] > 0) ? true : false;
}
return errFlag;
}
/*****************************************************************************
* Function : amendSyndrome
*
* Parameters:
* output: *pAmendSyndrome pointer to the amended syndrome sequnce
* input : *pSyndrome pointer to the syndrome sequnce .
* puncLocator pointed to the puncture-locator-polynomial given
* by the function calcPuncLocator().
* numOfPunc the number of punctures, continuous in position.
*
* Description : the syndrome shall be amended by the puncLocator, T(j)+=deta(i)S(j-i)
****************************************************************************/
void amendSyndrome(Uint8 *pAmendSyndrome, Uint8 *pSyndrome, Uint8 *puncLocator, Int16 numOfPunc)
{
for (int i = numOfPunc + 1; i <= MAX_RSPARITY_LENGTH; i++)
{
pAmendSyndrome[i - numOfPunc] = 0;
for (int j = 0; j <= numOfPunc; j++)
{
if ((pSyndrome[i - j] != 0) & (puncLocator[j] != 0))
pAmendSyndrome[i - numOfPunc] ^= AlfaOf[(IndexOf[pSyndrome[i - j]] + IndexOf[puncLocator[j]]) % 255];
}
}
for (i = MAX_RSPARITY_LENGTH - numOfPunc + 1; i <= MAX_RSPARITY_LENGTH; i++)
{
pAmendSyndrome[i] = pSyndrome[i];
}
}
/*****************************************************************************
* Function : calcErrLocator
*
* Parameters:
* output: *errLocator point to the array to store the coefficients of
* the error locator polynomial with the maximum length 17.
* input : *pSyndrome pointer to the syndrome sequnce .
* numOfErrToCorr the maximum number of the error occured can be corrected,
* the amount is defined in BurstProfile.
*
* Description : using BM overlap.
****************************************************************************/
Int16 calcErrLocator(Uint8 *errLocator, const Uint8 *pSyndrome, Int16 numOfErrToCorr)
{
Uint8 elp [18][16]; // elp ---> error_locator_polynomials
Uint8 check [18];
Int16 deg [18]; // degrees of elps.
Int16 oweDeg[18]; // owed degree = i - deg(elp_i), for i_th elp.
// initialization
elp[0][0] = 1; // initialize the errLocator, elp_(-1)
deg[0] = 0;
oweDeg[0] = -1; // the owed degree of i_th error_locator_polynomial
check [0] = 1;
elp[1][0] = 1; // initialize the errLocator, elp_0
deg[1] = 0;
oweDeg[1] = 0;
Int16 idxOfMaxOweElp = 0; // array index of the elp with the maximum owed_degree and check !=0.
Int16 idxOfCurElp = 1; // array index of the current elp for the current computation-step.
Int16 idxOfNewElp; // array index of the new elp.
int i, j, k;
Int16 elpIndex = 0;
do
{
elpIndex++; // index of the pSyndrome.
// check the current elp
Uint8 checkValue = pSyndrome[elpIndex];
for (i = 1; i <= deg[idxOfCurElp]; i++)
{
if ((pSyndrome[elpIndex-i]!=0) & (elp[idxOfCurElp][i]!=0))
{
checkValue ^= AlfaOf[(IndexOf[pSyndrome[elpIndex - i]] + IndexOf[elp[idxOfCurElp][i]])%255];
}
// checkValue ^= pSybdrome[]*elp[][];
}
check[idxOfCurElp] = checkValue;
if (checkValue > 0) // will generate the new error locator polynomial
{
idxOfNewElp = idxOfCurElp + 1; // next row in array to store the new elp.
Uint8 coef = AlfaOf[(IndexOf[checkValue] + 255 - IndexOf[check[idxOfMaxOweElp]])%255];
// coef = checkValue / check[];
Int16 degNum = elpIndex - 1 - oweDeg[idxOfMaxOweElp];
deg[idxOfNewElp] = (deg[idxOfCurElp] > degNum) ? deg[idxOfCurElp] : degNum;
for (j = 0; j <= deg[idxOfNewElp]; j++)
{
elp[idxOfNewElp][j] = 0; // clear up, maybe need.
}
for (i = degNum, k = deg[idxOfMaxOweElp]; k >= 0; i--,k--)
{
elp[idxOfNewElp][i] = (elp[idxOfMaxOweElp][k]>0)? AlfaOf[(IndexOf[coef] + IndexOf[elp[idxOfMaxOweElp][k]])%255] : 0;
}
for (i = 0; i <= deg[idxOfCurElp]; i++)
{
elp[idxOfNewElp][i] ^= elp[idxOfCurElp][i];
}
// update the elp with maximum owed order, the previous elp may have the maximum owed-degree.
idxOfMaxOweElp = (oweDeg[idxOfCurElp] >= oweDeg[idxOfMaxOweElp])? idxOfCurElp : idxOfMaxOweElp;
// computing the owed-degree of new elp.
oweDeg[idxOfNewElp] = elpIndex - deg[idxOfNewElp]; // the index of elp is according to the index of pSyndrome.
}// end of (checkValue > 0)
else
{
idxOfNewElp = idxOfCurElp; // no change, as well as maxOweElp
oweDeg [idxOfNewElp] = oweDeg [idxOfCurElp] + 1;
}
idxOfCurElp = idxOfNewElp; // for next loop.
}while ((elpIndex < 2*numOfErrToCorr ));// && deg[idxOfNewElp] <= numOfErrToCorr );
for (i = 0; i <= deg[idxOfCurElp]; i++)
{
errLocator[i] = elp[idxOfCurElp][i];
}
return deg[idxOfCurElp];
}
/*****************************************************************************
* Function : calcErrPuncLocator
*
* Parameters:
* output: pErrPuncLocator point to the array to store the coefficients of
* the total error locator polynomial.
* input : *errLocator pointed to the error-locator-polynomial given
* by the function calcErrLocator().
* *puncLocator pointed to the puncture-locator-polynomial given
* by the function calcPuncLocator().
* numOfErr the max degree of errLocator.
* numOfPunc the max degree of puncLocator.
****************************************************************************/
void calcErrPuncLocator(Uint8 *pErrPuncLocator, Uint8 *pErrorLocator, Uint8 *puncLocator,
Int16 numOfErr, Int16 numOfPunc)
{
int i, j;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -