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

📄 ldpcencode.c

📁 空间无线信道建模程序matlab
💻 C
字号:
/* File: LdpcEncode.c

   Description: Encodes a single LDPC codeword.  Code must be an "eIRA-LDPC" type code,
                such as the one in the DVB-S2 standard

   The calling syntax is:
   codeword    = LdpcEncode( data, H_rows)

   Where:
      codeword = the encoded codeword

      data = a row vector containing the data
      H_rows = a M-row matrix containing the indices of the non-zero rows of H.

   Copyright (C) 2006, Rohit Iyer Seshadri and Matthew C. Valenti

   Last updated on Jan. 11, 2006

   Function LdpcEncode is part of the Iterative Solutions 
   Coded Modulation Library. The Iterative Solutions Coded Modulation 
   Library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Lesser General Public License as published 
   by the Free Software Foundation; either version 2.1 of the License, 
   or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
  
   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
# include<mex.h>
# include<stdio.h>
# include<math.h>
# include<stdlib.h>

void encode(double u[],double H_rows[],double *c_in,int nldpc,int kldpc,int mldpc, int wid_Hrows)
{
	int count,i,j, k,sum,temp;
	int *x;   
	
	x=(int*)calloc((mldpc+1),sizeof(int));
    
	for (i=0;i<kldpc;i++){
		c_in[i]=u[i];
	} 
	
	for (i=0;i<mldpc;i++){
        c_in[kldpc+i]=0;
	}
	
	sum=0;	 
	
	for(i=0;i<mldpc;i++){		
		for(k=1;k<=wid_Hrows;k++){
			if(H_rows[i+mldpc*(k-1)]!=0){
				count=(int)H_rows[i+mldpc*(k-1)];
				x[i]=((int)c_in[count-1])^((int)x[i]) ;
			}
		}
		c_in[kldpc+i]=x[i]^sum; /* Differential encoding */
		sum=c_in[kldpc+i];
	}
	
    free(x);
    return;	
}


void mexFunction(int nlhs,mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
	double *u,*c_in, *H_rows;
	int index,nldpc,kldpc,mldpc,wid_Hrows;
	
	/* Error checks	*/
	if (nrhs !=2){
		mexErrMsgTxt(" 2 inputs needed\n");
	}
	else if (nlhs >1){
		mexErrMsgTxt(" only 1 output ");
	}	
	
	/* Assign the variables to corresp. mlab pointers */
	u=mxGetPr(prhs[0]);
	H_rows=mxGetPr(prhs[1]);
	
	kldpc=mxGetN(prhs[0]);
	mldpc= mxGetM(prhs[1]);
	wid_Hrows=mxGetN(prhs[1]);
	nldpc=kldpc+mldpc;
 	 
	/* create output m array */
	plhs[0]= mxCreateDoubleMatrix(1,nldpc,mxREAL);
	
	/* create output m array */
	c_in=mxGetPr(plhs[0]);
	encode(u,H_rows,c_in,nldpc,kldpc,mldpc, wid_Hrows);
}

⌨️ 快捷键说明

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