用C语言实现LDPC的快速编码

#include
#include         //for Matlab mx and mex fuctions
#include

// 0            0  1   2
//[u]=ldpcqenc(h1j,s,cols)
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray*prhs[] )
{
    //input
    double *h1j;        //pointer variable for input matrix h1j
    double *s;          //pointer variable for input matrix s (inf bits)
    double cols;

    //output
    double *u;          //pointer variable for output matrix u (encoded bits)

    //local
    double h1num;       //p solving matrix 1's number
    double slen;        //s length

    unsigned int h1loop;
    unsigned int uloop;
    unsigned char p;

    h1j = mxGetPr(prhs[0]);     //pointer to h1j
    s = mxGetPr(prhs[1]);       //pointer to s
    cols = mxGetScalar(prhs[2]);//value of cols

    h1num = mxGetN(prhs[0]);    //number of cols of h1j
    slen = mxGetN(prhs[1]);

    plhs[0] = mxCreateDoubleMatrix(1, cols, mxREAL); //matrix for output
    u = mxGetPr(plhs[0]);       //pointer to u

    for (uloop=0; uloop     {
        u[uloop] = s[uloop];
    }

    h1loop = 0;
    for (; uloop     {
        p = 0;
        while (h1j[h1loop]<=uloop)
        {
            p = p ^ (unsigned char)u[(unsigned int)h1j[h1loop] - 1];
            h1loop++;
        }
        u[uloop] = p;
        h1loop++;
    }

}
 

你可能感兴趣的:(MATLAB,板块3:通信与信号处理,其他,LDPC)