Требуется прямое исправление ошибок с помощью 2d массива - PullRequest
0 голосов
/ 21 февраля 2011

У меня есть задача кодировать некоторые байты звука в 2d массиве с контрольными суммами, т.е.:

 b1   b2  check 1

 b3   b4  check 2

ch3  ch4

Где проверка 1 и проверка 2 - это контрольные суммы для их строк (например, проверка 1 == b1 ^ b2), а проверки 3 и 4 - это контрольные суммы для их столбцов.

когда массив такой, как указано выше, я получаю такой результат:

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

когда оно больше 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) errors:      10 /      25 recovered     failed
        - 2 byte(s) errors:      21 /     300 recovered     failed
        - 3 byte(s) errors:      27 /    2300 recovered     failed

Я сделал это так:

ДАТЧИК:

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
}
}

Затем я отправляю данные и декодирую: ДЕШИФРАТОР: я создаю массив ошибок и пытаюсь проверить контрольные суммы для ширины и высоты если есть ошибка в 2 столбцах, я нахожу xor каждого байта, отличного от того, с ошибкой и ошибкой прямого пересылки

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
      }

к сожалению, это не работает, у кого-нибудь есть идеи, где я иду не так? Я не хочу, чтобы люди делали это для меня, я хочу учиться и хотел бы несколько указателей:

1 Ответ

3 голосов
/ 21 февраля 2011

Проверка только одного из вычислений контрольной суммы:

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;
}

Вы перезаписываете контрольные суммы в каждом цикле (checksum = ...), а не добавляете новое значение к старому. Другие контрольные суммы страдают от этой же проблемы. Когда вы исправите это, также убедитесь, что вы инициализируете checksum перед началом каждого суммирования, чтобы контрольная сумма из предыдущей строки или столбца не переносилась. Также убедитесь, что вы обновляете границы индекса во внутреннем цикле (при необходимости, в зависимости от вашей реализации), иначе вы пропустите последнюю строку или столбец из суммы.

Что касается количества ошибок, которые можно исправить, эта конкретная схема контрольной суммы может обнаруживать, но не исправлять более одной ошибки, возникающей в разных строках и столбцах. То есть эта схема может исправлять несколько ошибок только в том случае, если они все встречаются в одной строке или в одном столбце.

...