#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2017
    Posts
    15
    Rep Power
    0

    Ldpc syndrome check Function Not working properly


    Hi,

    I am working with LDPC decoder.

    To check codeword is a valid codeword i added "codecheck" Function.

    For example : syndrome (s)=H'z.

    S is zero,z is a valid codeword, and the decoding stops, returning z as the decoded word.


    codecheck function showing some logical error. Any help.
    [CODE}
    #define COL 8
    #define COL_P 2
    #define ROWS_P 16
    #define ROWS_PARITYCHECKMATRIX 4

    int codecheck(int (*h)[2],int x[]) // syndrome check
    {
    int i,j,m,f; //flags
    int sum = 0;
    int y[ROWS_PARITYCHECKMATRIX];
    for (i=0;i<ROWS_PARITYCHECKMATRIX;i++)
    y[i]=0;
    m=1;
    f=-1;
    for(i=0;i<ROWS_PARITYCHECKMATRIX;i++)
    {
    for(j=0;j<ROWS_P;j++)
    {
    if(h[j][0]==i+1)
    {
    y[i]=y[i] + x[h[j][1]-1];
    f++;
    }
    }
    y[i]=y[i]%2;
    }
    for (i = 0; i < ROWS_PARITYCHECKMATRIX; ++i)
    {
    sum =sum+ y[i];
    }
    if (sum == 0)
    {
    return 1;
    }
    else
    {
    return -1;
    }
    }

    int codesum (int y[])
    {
    int sum=0;
    for(int i=0;i<COL;i++)
    sum+=y[i];

    if(sum>0)
    return 0;
    else
    return 1;
    }

    /*void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, int x[], float noise[], float L_ch[], float d, int (*h)[2], float LLR[])
    {

    int j=0; // temporary flags
    int k=0,t;
    for(int i=0;i<noOfSymbols;i++) // using randnoise function introducing noise to all zero codeword
    {
    x[j]=d;
    noise[j]=(x[j])+0.2;
    L_ch[j]= 2*noise[j]/var;
    j++;
    }
    for(int j=0;j<ROWS_P;j++)
    {
    //cout<<"enter loop"<<endl;
    //cout<< "j="<<j<<endl; //<<j<<"\t";
    t=h[j][1]-1;
    LLR[j]=L_ch[t];

    }

    }*/

    int SPADecoder(float LLR[], int (*h)[2], float LLR_ret[], float L_ch[], float L_dec[], int y[],int x[])
    {
    double temp;
    int i,j,k,z;
    for(i=0;i<ROWS_P;i++)
    {
    temp=1;
    for(j=0;j<ROWS_P;j++)
    {
    if(j!=i && h[j][0]==h[i][0])
    {
    temp=temp * tanhf(LLR[j]/2);
    }
    }
    LLR_ret[i] = log((1 + temp)/(1 - temp));

    if(LLR_ret[i] > 40)
    {
    LLR_ret[i]=40;
    }
    else if(LLR_ret[i]<-40)
    {
    LLR_ret[i]=-40;
    }
    }

    for(i=0;i<COL;i++)
    {
    L_dec[i]=L_ch[i];
    }

    for(i=1;i<COL+1;i++)
    {
    for(j=0;j<ROWS_P;j++)
    {
    if(h[j][1]==i)
    {
    L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
    }
    }

    if(L_dec[i-1]<=0)
    {
    y[i-1]=1;
    }
    else
    {
    y[i-1]=0;
    }
    }
    z=codecheck(h,x);
    if(z==1) // if decoded perfectly exit the deoding loop
    {
    return z;
    }
    for(i=0;i<ROWS_P;i++)
    {
    temp=0;
    for(j=0;j<ROWS_P;j++)
    {
    if(j!=i && h[j][1]==h[i][1])
    {
    temp=temp + LLR_ret[j];
    k=h[i][1];
    }
    }
    LLR[i] = temp+L_ch[k-1];
    }
    return z;
    }

    int main()
    {

    // flags and counters
    int z,i,N,k,s,looping,t,sum;
    float d=1;
    float rate=0.5;
    int maxTransmissions=100,decoderIterations=20,maxErrors=25,errorsAccumulated=0;
    int y[COL]; // iterations gives the maximum number of time the decoder is run for each value of SNR
    // int L,O,R,M=0;
    double var=0,snr;
    float noise[COL];//{-1.386294,1.386294,-1.386294,1.386294,-1.386294,-1.386294};
    float L_ch[COL],L_dec[COL];
    float LLR[ROWS_P],LLR_ret[ROWS_P];
    float BER[11];
    float snr_db[]={0,1,2,3,4};
    int snr_range=1,snr_count;
    int x[]= {1,0,1,1,0,1,0,0};//{1,0,1,0,1,1}; //{1,1,0,1,0,1,0,1}
    int modulationScheme = 0,noOfSymbols=6;
    int h[ROWS_P][COL_P]={{1,2},{1,4},{1,5},{1,8},{2,1},{2,2},{2,3},{2,6},{3,3},{3,6},{3,7},{3,8},{4,1},{4,4},{4,5},{4,7}};//{{1,1},{1,2},{1,3},{2,1},{2,4},{2,5},{3,2},{3,4},{3,6},{4,3},{4,5},{4,6}};{{1,2},{1,4},{1,5},{1,8},{ 2,1},{2,2},{2,3},{2,6},{3,3},{3,6},{3,7},{3,8},{4,1},{4,4},{4,5},{4,7}};{{1,1},{1,2},{1,4},{2,2},{2, 3},{2,5},{3,1},{3,5},{3,6},{4,3},{4,4},{4,6}};
    // encoder code word
    /*printf("encoder \n");
    for (L = 0; L < 204; L++)
    {
    printf("%d",x[L]);
    }
    printf("\n");

    z= codecheck(h,x);
    printf("z value=%d \n",z);*/

    int p;
    float a=0.2;
    printf("Crossover probability: ");
    for (p = 0; p < COL; p++)
    {
    if (x[p]==1)
    {
    L_ch[p]=logf(a/(1-a));
    }
    else
    {
    L_ch[p]=logf((1-a)/a);
    }
    printf("\t%f,", L_ch[p]);
    }

    for(snr_count=0;snr_count<1;snr_count++)
    {
    snr=pow(10,(snr_db[snr_count]/10));
    var=1/(2*rate*snr);
    noOfSymbols = COL;
    d=1;
    N=0;
    BER[snr_count]=0;
    errorsAccumulated=0;
    printf(" snr=%f \t var=%f \t noOfSymbols=%d \t",snr,var,noOfSymbols);

    // InitializeChannelLLR(var, modulationScheme, noOfSymbols, x, noise, L_ch, d, h, LLR);
    for(looping=0;looping<decoderIterations;looping++)
    {
    z=SPADecoder(LLR, h, LLR_ret, L_ch, L_dec, y,x);
    }
    if(z==1) // if decoded correctly BER for that codeword is zero
    {

    printf("decoded correctly \n");

    }
    else // if not decoded properly calulating the BER
    {
    printf("decoded incorrectly \n");
    }


    }

    printf("Decoded Codeword \n");
    for (i = 0; i < COL; i++)
    {
    printf("%d",y[i]);

    }
    printf("\n");
    return 0;
    }[/CODE]
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,888
    Rep Power
    509
    You haven't yet addressed this issue
    Code:
    c.c: In function ‘SPADecoder’:
    c.c: In function ‘SPADecoder’:
    c.c:LIN:COL: warning: ‘k’ may be used uninitialized in this function [-Wmaybe-uninitialized]
           LLR[i] = temp+L_ch[k-1];
    I'm not yet sure what the logic should be, although I've now spent enough time with an LDPC article to learn that it's a strategy for communicating in a noisy system.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2017
    Posts
    15
    Rep Power
    0
    Hi,

    Please help me in correcting the codes. I need to execute and complete this project within 1 or 2 days.

    I am using Sum-Product decoding Technique, algorithm which i have followed is page Number :34 of this [LINK] http://sigpromu.org/sarah/SJohnsonLDPCintro.pdf. For more reference follow : from Page 30 to 38.

IMN logo majestic logo threadwatch logo seochat tools logo