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

📄 check.c

📁 用于LDPC编码译码的仿真实现。包括随机生成校验矩阵、由校验矩阵产生生成矩阵、编码、加随机噪声、译码等内容。原作者是老外
💻 C
字号:
/* CHECK.C - Compute parity checks and other stats on decodings. */

/* Copyright (c) 2001 by Radford M. Neal 
 * 
 * Permission is granted for anyone to copy, use, or modify this program 
 * for purposes of research or education, provided this copyright notice 
 * is retained, and note is made of any changes that have been made. 
 *
 * This program is distributed without any warranty, express or implied.
 * As this program was written for research purposes only, it has not been
 * tested to the degree that would be advisable in any important application.
 * All use of this program is entirely at the user's own risk.
 */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "mod2sparse.h"
#include "check.h"
#include "rcode.h"



/* COMPUTE PARITY CHECKS.  Returns the number of parity checks violated by
   dblk.  The results of all the parity checks are stored in pchk. */
//计算码字dblk是否满足校验矩阵,即计算校验向量,返回校验向量中的非零元素的个数
int check
( mod2sparse *H,	/* Parity check matrix */
  int *dblk,		/* Guess for codeword */
  int *pchk		/* Place to store parity checks */
)
{
  int M, i, c;

 
  M = mod2sparse_rows(H);

  mod2sparse_mulvec(H, dblk, pchk);

  c = 0;
  for (i = 0; i<M; i++) 
  { c += pchk[i];
  }

  return (c);
}


/* COUNT HOW MANY BITS HAVED CHANGED FROM BIT INDICATED BY LIKELIHOOD.  The
   simple decoding based on likelihood ratio is compared to the given decoding.
   A bit for which the likelihood ratio is exactly one counts as half a 
   change, which explains why the result is a double rather than an int.????
 */

double changed
( double *lratio,	/* Likelihood ratios for bits */
  int *dblk,		/* Candidate decoding */
  int N			/* Number of bits */
)
{ 
  double chaged;
  int j;

  chaged = 0;
  for (j = 0; j<N; j++)
  { chaged += lratio[j]==0 ? 0.5 : dblk[j] != (lratio[j]>0); 
  }

  return (chaged);
}




/* COMPUTE ENTROPY FROM BIT PROBABILITIES.  Computes the entropy of the
   distribution given by the bit probabilities, on the assumption that
   bits are independent.
 */

/*double entropy 
( double *bpr,		/* Bit probabilities */
/*  int N			/* Length of codeword */
/*)
{
  double e;
  int j;

  e = 0;
  for (j = 0; j<N; j++)
  { if (bpr[j]>0 && bpr[j]<1)
    { e -= bpr[j]*log(bpr[j]) + (1-bpr[j])*log(1-bpr[j]);
    }
  }

  return e/log(2.0);
}*/

⌨️ 快捷键说明

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