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

📄 extract.c

📁 用于LDPC编码译码的仿真实现。包括随机生成校验矩阵、由校验矩阵产生生成矩阵、编码、加随机噪声、译码等内容。原作者是老外
💻 C
字号:
/* EXTRACT.C - Extract message bits from coded blocks. */
//从编码比特中提取消息比特
/* Copyright (c) 2000, 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "mod2sparse.h"
#include "rcode.h"
#include "alloc.h"
#include "extract.h"


void extract(char *gen_file,int *decoded_data,int *decoded_source)
{
  int i;



  /* Read generator matrix file, up to the point of finding out which
     are the message bits. */
  
  read_gen(gen_file,1,1); //在没有读校验矩阵的情况下读生成矩阵,并且只读排序的列

  for (i = M; i<N; i++)
  { 
	decoded_source[i-M]=decoded_data[cols[i]];
  }

    free(cols);//lxh
    free(rows);//lxh
  
}

joint_source(mod2sparse *H,char *gen_file, int *decoded_data, int *decoded_source,double *LLR,double *table,double *extr_source)
{

	int i,pre_deci=0;
	int temp=1;

	int M,N;

   M = mod2sparse_rows(H);
  N = mod2sparse_cols(H);

	read_gen(gen_file,1,1);
	for (i = M; i<N; i++)
	{
		decoded_source[i-M]=decoded_data[cols[i]];
	}

	for (i=0;i<3;i++)
	{
		pre_deci=pre_deci << 1;
		pre_deci=pre_deci | decoded_source[i];
		if (fabs(LLR[cols[M+i]])<1.5)
			temp=0;
	}
    for (i=M+3;i<N;i++)
	{
	/*	if (temp=0)
			extr_source[cols[i]]=0;
		else*/
			extr_source[cols[i]]=table[pre_deci];

        pre_deci=pre_deci << 1;
        pre_deci=pre_deci & 6;
        pre_deci=pre_deci | decoded_source[i-M];
		if (fabs(LLR[cols[i]])<0.8)
			temp=0;
		else
			temp=1;
	}

    free(cols);//lxh
    free(rows);//lxh
}

markov_decode(mod2sparse *H,char *gen_file, int *decoded_data, double p,int *decoded_source,double *extr_source,double *LLR)
{

	int i;

	int M,N;

   M = mod2sparse_rows(H);
   N = mod2sparse_cols(H);

	read_gen(gen_file,1,1);
	
	for (i = M; i<N; i++)
	{
		decoded_source[i-M]=decoded_data[cols[i]];
	}
   
    for (i=M+1;i<N;i++)
	{
		if (fabs(LLR[cols[i]])>2.5)
		{
			if (decoded_source[i-1]==0)
				extr_source[cols[i]]=log((1-p)/p);
		    else
				extr_source[cols[i]]=log(p/(1-p));
		}
		else
			extr_source[cols[i]]=0;

	}

    free(cols);//lxh
    free(rows);//lxh
}


⌨️ 快捷键说明

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