www.pudn.com > ldpca.zip > decodeBits.c
//Author: David Varodayan (varodayan@stanford.edu) //Date: May 8, 2006 #include "mex.h" #include#include #define max(a,b) (((a)>(b))?(a):(b)) //C-MEX wrapper void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *LLR_intrinsic, *accumulatedSyndrome, *source, *decoded, *rate, *numErrors; char ladderFile[50]; FILE *fp; int n; LLR_intrinsic = mxGetPr(prhs[0]); accumulatedSyndrome = mxGetPr(prhs[1]); source = mxGetPr(prhs[2]); mxGetString(prhs[3], ladderFile, 50); fp = fopen(ladderFile, "r"); fscanf(fp, "%d", &n); fscanf(fp, "%d", &n); fclose(fp); plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL); decoded = mxGetPr(plhs[0]); plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL); rate = mxGetPr(plhs[1]); plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL); numErrors = mxGetPr(plhs[2]); decodeBits(LLR_intrinsic, accumulatedSyndrome, source, ladderFile, decoded, rate, numErrors); } //decodeBits() finds the minimum rate for which the decoded bitstream matches //the transmitted portion of the accumulated syndrome. //The number of residual bit errors is also calculated. void decodeBits(double *LLR_intrinsic, double *accumulatedSyndrome, double *source, char *ladderFile, double *decoded, double *rate, double *numErrors) { FILE *fp; int n, m, nzmax, *ir, *jc; int numCodes, totalNumInc, numInc, *txSeq; int code, k, currIndex, prevIndex; double *syndrome; fp = fopen(ladderFile, "r"); fscanf(fp, "%d", &numCodes); fscanf(fp, "%d", &n); fscanf(fp, "%d", &nzmax); fscanf(fp, "%d", &totalNumInc); ir = mxCalloc(nzmax, sizeof(int)); jc = mxCalloc(n+1, sizeof(int)); txSeq = mxCalloc(totalNumInc, sizeof(int)); //actual length: numInc syndrome = mxCalloc(n, sizeof(double)); //actual length: m for(k=0; k