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

📄 decoder.cpp

📁 介绍了一种串行LDPC码的编码器和译码器的实现形式 C++环境下编写。有些地方还需完善
💻 CPP
字号:
#include "float.h"
#include "sparse.h"
#include "decoder.h"
#include  "main.h"

/* function:   parallel decoder
   parameter:  *HParity check matrix 
               *lratio  Likelihood ratios for bits 
               *dblk    point to the Place store code decoded
               *bprb    point to the place to store bit probabilities */
unsigned prprp_decode( mod2sparse *H, double *lratio, char *dblk, double *bprb )
{   
	int  n,k;
    extern int  ERR[max_iter];
    extern char DecodedData[EncodedLength];
	extern int  InfoBit[InfoLength];
    extern int  Parity[ParityCheckNum][H_ColNum];
	extern int  infoBitsLocation[InfoLength];
	
	initprp(H,lratio,dblk,bprb);
	
	for ( n = 0 ; n< max_iter; n++)
	{   
		iterprp(H,lratio,dblk,bprb);
		
		for(k = 0; k < InfoLength; k++ )
			if( InfoBit[k] != DecodedData[infoBitsLocation[k]] )
				ERR[n]++;
	}
	
	return n;

}

/* function:  initialize probability propagation
   parameter: *H Parity check matrix 
              *lratio Likelihood ratios for bits
              *dblk point to the Place to store decoding 
              *bprb Place to store bit probabilities, 0 if not wanted */    
void initprp( mod2sparse *H, double *lratio, char *dblk, double *bprb)
{ 
	 mod2entry *e;
	 int N;
	 int j;

	 N = mod2sparse_cols(H);
	 
	 for (j = 0; j<N; j++)
	 {  
		 for (e = mod2sparse_first_in_col(H,j);!mod2sparse_at_end(e); e = mod2sparse_next_in_col(e))
		 {
			 e->pr = lratio[j];
			 e->lr = 0;
		 }

	 }
}


int sgn( double x)
{
	if( x > 0 )
		return 1;
	else if( x < 0 )
		return -1;
	else
		return 0;
}

double min( double x, double y )
{
	if( x >= y )
		return y;
	else
		return x;
}

double Basic_Calculate(double x,double y)
{	
	double z;

	z = log( ( exp(x) + exp(y) )/( 1 + exp(x+y) ) );
	
	return z;
	
}

double Clipping(double x)
{
	double temp;

	temp = x;
	if( fabs(x) > TOOLARGE )
		temp = sgn(x)*TOOLARGE;
	else if( fabs(x) < TOOSMALL )
		temp = sgn(x)*TOOSMALL;

	return temp;
}

/* function:  iteratively using probability propagation algorithm to decode
   parameter: *H Parity check matrix 
              *lratio Likelihood ratios for bits
              *dblk point to the Place to store decoding 
              *bprb Place to store bit probabilities, 0 if not wanted */ 
void iterprp( mod2sparse *H, double *lratio, char *dblk, double *bprb )
{ 
	double pr, dl;   
	mod2entry *e;
	int N, M;
	int i, j;
	M = mod2sparse_rows(H);
	N = mod2sparse_cols(H);

  /***********************************/
 /**  Horizational step            **/ 
 /**  Compute likelihood ratios    **/
 /**  using f-function.            **/
 /***********************************/

	for( i = 0;i < M;i++ )
	{   
		e = mod2sparse_first_in_row(H,i);
		dl = tanh(e->pr/2.0);
		e = mod2sparse_next_in_row(e);
		for ( ; !mod2sparse_at_end(e->right); e = mod2sparse_next_in_row(e) )
		{	 
			e->lr = dl;
			dl = dl*tanh(e->pr/2.0);
			//e->lr = Clipping(e->lr);
			//dl = Clipping(dl);
		}

		e = mod2sparse_last_in_row(H,i);
		e->lr = log((1+dl)/(1-dl));
		dl = tanh(e->pr/2.0);
		e = mod2sparse_prev_in_row(e);
		for (; !mod2sparse_at_end(e->left);e = mod2sparse_prev_in_row(e) )
		{ 
			e->lr = dl*e->lr;
			e->lr = log((1+e->lr)/(1-e->lr));
			dl = tanh(e->pr/2.0)*dl;
			//e->lr = Clipping( e->lr );
			//dl = Clipping( dl );
		}
		e->lr = log((1+dl)/(1-dl));
	}
  /***********************************/
  /**  Vertical step                **/ 
  /**  Recompute likelihood ratios. **/
  /***********************************/
  
	for( j = 0; j < N;j++ )
	{	 
		pr = lratio[j];
		
		for(e=mod2sparse_first_in_col(H,j);!mod2sparse_at_end(e); e=mod2sparse_next_in_col(e))
		{ 
			e->pr = pr;
			pr += e->lr;
			pr = Clipping( pr );
		}
		
		dblk[j] = ( pr >= 0 );
		
		pr = 0;
		
		for ( e = mod2sparse_last_in_col(H,j);!mod2sparse_at_end(e);e=mod2sparse_prev_in_col(e))
		{	
			e->pr += pr;
			pr += e->lr;
			e->pr = Clipping( e->pr );
			pr = Clipping( pr );
		}
	}

}

⌨️ 快捷键说明

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