A
A
Alexander Semykin2016-12-23 16:36:06
Programming
Alexander Semykin, 2016-12-23 16:36:06

Multiplication of bit matrices. Where is the mistake?

There is a message encoded with a linear code (16,7). There may be errors in the code, and in order to determine them, I need to find the syndrome. This is done as follows: S = Ri x Ht, where:
- Ri is the received message vector, 16 bits long.
- Ht - 16x9 transposed check matrix of a linear code.
If there are no errors in the received word, the syndrome should be 0. After doing the calculations in SageMath, I made sure that everything works fine. With a zero error vector, the syndrome is 0; with two errors, the syndrome allows them to be corrected.
The problems start when I try to implement the algorithm in C code:

static const uint16_t qr_16_7_check_matrix_T[16] = {
    0x4F,  // [0 0 1 0 0 1 1 1 1]
    0x11E, // [1 0 0 0 1 1 1 1 0]
    0x1B7, // [1 1 0 1 1 0 1 1 1]
    0x1E2, // [1 1 1 1 0 0 0 1 0]
    0x1C9, // [1 1 1 0 0 1 0 0 1]
    0xE5,  // [0 1 1 1 0 0 1 0 1]
    0x73,  // [0 0 1 1 1 0 0 1 1]
    0x100, // [1 0 0 0 0 0 0 0 0]
    0x80,  // [0 1 0 0 0 0 0 0 0]
    0x40,  // [0 0 1 0 0 0 0 0 0]
    0x20,  // [0 0 0 1 0 0 0 0 0]
    0x10,  // [0 0 0 0 1 0 0 0 0]
    0x8,   // [0 0 0 0 0 1 0 0 0]
    0x4,   // [0 0 0 0 0 0 1 0 0]
    0x2,   // [0 0 0 0 0 0 0 1 0]
    0x1,   // [0 0 0 0 0 0 0 0 1]
};

uint16_t qr_16_7_get_syndrome(uint16_t received_data) {
    uint16_t syndrome = 0x0;
    bool syndrome_bit = false;
    bool data_bit = false;
    bool matrix_bit = false;

    for (uint8_t cols = 0; cols < 9; cols++) {
        for (uint8_t rows = 0; rows < 16; rows++) {
            data_bit = (received_data >> rows) & 0x01;
            matrix_bit = (qr_16_7_check_matrix_T[rows] >> cols) & 0x01;
            syndrome_bit ^= data_bit & matrix_bit;
        }

        if (syndrome_bit) {
            syndrome |= (1 << cols);
        } else {
            syndrome &= ~(1 << cols);
        }
        syndrome_bit = false;
    }
    return syndrome & 0x01ff;
}

static const uint16_t qr_16_7_encoder[] = {
    0x0,    0x273,  0x4E5,  0x696,  0x9C9,  0xBBA,  0xD2C,  0xF5F,  0x11E2,
    0x1391, 0x1507, 0x1774, 0x182B, 0x1A58, 0x1CCE, 0x1EBD, 0x21B7, 0x23C4,
    0x2552, 0x2721, 0x287E, 0x2A0D, 0x2C9B, 0x2EE8, 0x3055, 0x3226, 0x34B0,
    0x36C3, 0x399C, 0x3BEF, 0x3D79, 0x3F0A, 0x411E, 0x436D, 0x45FB, 0x4788,
    0x48D7, 0x4AA4, 0x4C32, 0x4E41, 0x50FC, 0x528F, 0x5419, 0x566A, 0x5935,
    0x5B46, 0x5DD0, 0x5FA3, 0x60A9, 0x62DA, 0x644C, 0x663F, 0x6960, 0x6B13,
    0x6D85, 0x6FF6, 0x714B, 0x7338, 0x75AE, 0x77DD, 0x7882, 0x7AF1, 0x7C67,
    0x7E14, 0x804F, 0x823C, 0x84AA, 0x86D9, 0x8986, 0x8BF5, 0x8D63, 0x8F10,
    0x91AD, 0x93DE, 0x9548, 0x973B, 0x9864, 0x9A17, 0x9C81, 0x9EF2, 0xA1F8,
    0xA38B, 0xA51D, 0xA76E, 0xA831, 0xAA42, 0xACD4, 0xAEA7, 0xB01A, 0xB269,
    0xB4FF, 0xB68C, 0xB9D3, 0xBBA0, 0xBD36, 0xBF45, 0xC151, 0xC322, 0xC5B4,
    0xC7C7, 0xC898, 0xCAEB, 0xCC7D, 0xCE0E, 0xD0B3, 0xD2C0, 0xD456, 0xD625,
    0xD97A, 0xDB09, 0xDD9F, 0xDFEC, 0xE0E6, 0xE295, 0xE403, 0xE670, 0xE92F,
    0xEB5C, 0xEDCA, 0xEFB9, 0xF104, 0xF377, 0xF5E1, 0xF792, 0xF8CD, 0xFABE,
    0xFC28, 0xFE5B};

I can't find the error in the code, but the values ​​it gives are incorrect. In theory, for any value from the dictionary above, the syndrome should be equal to 0. SageMath demonstrates just such results. It's not like that in half of the cases. For example, for the words 0x1EBD or 0x2C9B, the syndrome value is 0x4E.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-12-23
@vagrantnotes

Your rows numbering is definitely mixed up, i.e. You consider the matrix from 0 to 15, and you must apply from 15 to 0. As for cols, I have not figured it out yet.
PS And in general, why do you perform operations bit by bit? After all, XOR will be perfectly executed 9 bits at a time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question