• 大小: 0.01M
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: 其他
  • 标签: 其他  

资源简介

GOLAY.c

资源截图

代码片段和文件信息

#include

void golay_enc(u16* golay_enc_in u16* golay_enc_out);

int golay_dec(u16* golay_dec_in u16* golay_dec_out);

/**************************************************************************
 * Function: Golay(24128) Encoder and Decoder for DMR standard.         *
 * Reference:                                                             *
 *   1: DMR standard ts_10236101v010405p.pdf page 128.                   *
 *   2: Error Control Coding/Second Edition/Lin Shu/Ch04.pdf/page 27.     *
 *   3: Generator polynomial: g(X)=X^11+X^10+X^6+X^5+X^4+X^2+1=6165_oct   *
 *   4: There are two different generator polynomials.                    *
 *                                                                        *
 *************************************************************************/

//===== Bit Struct ====
//|<-    Info    ->|<-  Parity ->|
//________________________________
//|23|22| ...|13|12|11|10|...|1|0|
//----------------------------

//===== golay table ======
// G = [I_12 P]
// H = [Q I_12]
static const u16 P[] =
{
    0xc75  // 1100_0111_0101
    0x63b  // 0110_0011_1011
    0xf68  // 1111_0110_1000
    0x7b4  // 0111_1011_0100

    0x3da  // 0011_1101_1010
    0xd99  // 1101_1001_1001
    0x6cd  // 0110_1100_1101
    0x367  // 0011_0110_0111

    0xdc6  // 1101_1100_0110
    0xa97  // 1010_1001_0111
    0x93e  // 1001_0011_1110
    0x8eb   // 1000_1110_1011
};

static const u16 Q[] =     // Q = P‘ = inv(P)
{
    0xa4f  // 1010_0100_1111
    0xf68  // 1111_0110_1000
    0x7b4  // 0111_1011_0100
    0x3da  // 0011_1101_1010

    0x1ed  // 0001_1110_1101
    0xab9  // 1010_1011_1001
    0xf13  // 1111_0001_0011
    0xdc6  // 1101_1100_0110

    0x6e3  // 0110_1110_0011
    0x93e  // 1001_0011_1110
    0x49f  // 0100_1001_1111
    0xc75   // 1100_0111_0101
};

//===== golay_enc() ======
// function: Golay(24128) encoder.
// input:   u16 golay_enc_in;
// output:  u16 golay_enc_out[2];
//          golay_enc_out[0] is info golay_enc_out[1] is parity.
// Both use low 12 bits. [golay_enc_out[0] golay_enc_out[1]] = golay_enc_in * G.
// No return value.
//#pragma CODE_SECTION (golay_enc “.text1“)
void golay_enc(u16* golay_enc_in u16* golay_enc_out)
{
    u16 i j;

    golay_enc_out[0] = *golay_enc_in;
    golay_enc_out[1] = 0;
    for(i = 0; i < 12; i++)
    {
        j = golay_enc_out[0] & Q[i];
        j = (j & 0xff) ^ (j >> 8);
        j = (j & 0x0f) ^ (j >> 4);
        j = (j & 0x03) ^ (j >> 2);
        j = (j & 0x01) ^ (j >> 1);
        golay_enc_out[1] = (golay_enc_out[1] << 1) ^ j;
    }
}

//===== golay_dec() ======
// function: Golay(24128) decoder.
// input:   u16 golay_dec_in[2];
// output:  u16 golay_dec_out;
//          golay_dec_in[0] 

评论

共有 条评论