开发者

Forward error correction with a 2d array help needed

开发者 https://www.devze.com 2023-02-13 00:54 出处:网络
I havethe task of encoding some bytes of sound in a 2d array with check sums i.e: b1b2check 1 b3b4check 2

I have the task of encoding some bytes of sound in a 2d array with check sums i.e:

 b1   b2  check 1

 b3   b4  check 2

ch3  ch4

Where check 1 and check 2 are the checksums for their rows (e.g. check 1 == b1 ^ b2) and check 3 and 4 are the checksums for their columns.

when the array is as above i get this result :

1) Checking encoder...  o.k.

    -Input block size : 4 byte(s)
    -Output block size: 9 byte(s).
    -Overhead         : +125.00%

2) Checking decoder...  o.k.

3) Checking performance of codec:

    Trying all combinations of:
        - 1 byte(s) errors:       9 /       9 recovered     o.k.
        - 2 byte(s) errors:      18 /      36 recovered     failed
        - 3 byte(s) errors:      15 /      84 recovered     failed

when it is larger 4*4:

1) Checking encoder...  o.k.

    -Input block size : 16 byte(s)
    -Output block size: 25 byte(s).
    -Overhead         : +56.25%

2) Checking decoder...  o.k.

3) Checking performance of codec:

    Trying all combinations of:
        - 1 byte(s) erro开发者_StackOverflow中文版rs:      10 /      25 recovered     failed
        - 2 byte(s) errors:      21 /     300 recovered     failed
        - 3 byte(s) errors:      27 /    2300 recovered     failed

i have done this like this:

ENCODER:

const int width = 2;
const int height = 2;
const int candwidth = 3;
const int candheight = 3;
guint8 checksum;
int h;
int w;

guint8 parity [candwidth][candheight];

while (bufin->size >= (width*height)){
    for ( h =0; h< height; h++)
        for( w = 0; w < width; w++) 
        {
            guint8 databyte = bufin->data[0];       //Pick up a byte from input buffer
            parity [w][h] = databyte;
            buffer_pop (bufin, 1);                  //Remove it from the input buffer
        }

    for ( h =0; h< height; h++)
    {
        for( w = 0; w < width-1; w++) 
        {
            checksum = parity[w][h]^parity[w+1][h]; // width check
        }  
        parity[candwidth-1][h] = checksum;
    }


    for ( w =0; w< width; w++)
    {
        for( h = 0; h < height-1; h++) 
        {
            checksum = parity[w][h]^parity[w][h+1];// height check
        }  
        parity[w][candheight-1] = checksum;
    }         

    for (h =0; h< candheight; h++)
        for(w = 0; w < candwidth; w++)        
            buffer_push_byte (bufout,parity [w][h]);    //Send it all
}
}

I then send the data and decode: DECODER: i create an error array and attempt to check the check sums for width and height if there is an error on 2 Columns i find the xor of every byte other than the one with an error and Forward error correct

void fox_decode(Buffer* bufin, Buffer* bufout, FoxDecData* algorithm_data){
    const int width = 2;
    const int height = 3;
    const int candwidth = 3;
    const int candheight = 3;
    guint8 thischecksum;
    int h;
    int w;
    int e;
    int h2;
    int w2;

// error array to check for errors
    int error [width][height];
    for ( h =0; h< height; h++)
    {
        for( w = 0; w < width; w++) 
        {
            error[w][h]=0; 
        }  

    }

    guint8 parity [candwidth][candheight];

    // Example:
    while (bufin->size >= (candwidth*candheight)){
        for ( h =0; h< candheight; h++)
            for( w = 0; w < candwidth; w++) 
            {
                guint8 databyte = bufin->data[0];       //Pick up a byte from input buffer
                parity [w][h] = databyte;
                buffer_pop (bufin, 1);                  //Remove it from the input buffer
            }

        for ( h =0; h< height; h++)
        {
            for( w = 0; w < width-1; w++) 
            {
                thischecksum = parity[w][h]^parity[w+1][h]; // width check
            }  
            if (parity[candwidth-1][h]!= thischecksum)
            {
                //printf("%i,%i\n",parity[candwidth-1][h], thischecksum);
                for( e = 0; e < width; e++)
                    error[e][h]++;
            }
        }



        for ( w =0; w< width; w++)
        {
            for( h = 0; h < height-1; h++) 
            {
                thischecksum = parity[w][h]^parity[w][h+1]; //h check
            }  
            if (parity[w][candheight-1]!= thischecksum)
            {
                // printf("%i,%i\n",parity[w][candheight-1], thischecksum);
                for( e = 0; e < height; e++)
                    error[w][e]++;
            }
        }

        for ( h =0; h< height; h++)    
            for( w = 0; w < width; w++) 
                if (error[w][h]>=2)
                {
                    thischecksum=parity[candwidth-1][h];
                    for( w2 = 0; w2 < width; w2++) 
                        if(w!=w2){
                            thischecksum = parity[w2][h]^thischecksum; // width check
                        }
                    parity[w][h]=thischecksum;
                }  







  for (h =0; h< height; h++)
    for(w = 0; w < width; w++)    
      buffer_push_byte (bufout,parity [w][h]);    //Send it all
      }

unfortunately it does not work does anyone have any ideas where i am going wrong? I do not want people to do this for me i want to learn and would like some pointers:


Examining just one of the checksum calculations:

for ( h =0; h< height; h++)
{
    for( w = 0; w < width-1; w++) 
    {
        checksum = parity[w][h]^parity[w+1][h]; // width check
    }  
    parity[candwidth-1][h] = checksum;
}

You overwrite checksums on each loop (checksum = ...), rather than adding the new value to the old. The other checksums suffer from this same problem. When you fix this, also make sure you initialize checksum before starting each summation, so the checksum from a previous row or column isn't carried over. Also make sure you update the index bounds in the inner loop (if necessary, depending on your implementation), otherwise you'll leave out the last row or column from the summation.

As for how many errors can be corrected, this particular checksum scheme can detect but not correct more than one error that occur in different rows and columns. That is this scheme can correct multiple errors only if they all occur in the same row or the same column.

0

精彩评论

暂无评论...
验证码 换一张
取 消