⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wib_dl_cc.c

📁 802.16e物理层下行卷积编码。严格按照802.16e实现。
💻 C
📖 第 1 页 / 共 4 页
字号:
		0x043,0x053,0x063,0x073,0x083,0x093,0x0a3,0x0b3,0x0c3,0x0d3,0x0e3,0x0f3,0x103,0x113,
		0x123,0x133,0x143,0x153,0x163,0x173,0x183,0x193,0x1a3,0x1b3,0x1c3,0x1d3,0x1e3,0x1f3,
		0x203,0x213,0x223,0x233,0x014,0x024,0x004,0x044,0x054,0x034,0x074,0x084,0x064,0x0a4,
		0x0b4,0x094,0x0d4,0x0e4,0x0c4,0x104,0x114,0x0f4,0x134,0x144,0x124,0x164,0x174,0x154,
		0x194,0x1a4,0x184,0x1c4,0x1d4,0x1b4,0x1f4,0x204,0x1e4,0x224,0x234,0x214,0x025,0x005,
		0x015,0x055,0x035,0x045,0x085,0x065,0x075,0x0b5,0x095,0x0a5,0x0e5,0x0c5,0x0d5,0x115,
		0x0f5,0x105,0x145,0x125,0x135,0x175,0x155,0x165,0x1a5,0x185,0x195,0x1d5,0x1b5,0x1c5,
		0x205,0x1e5,0x1f5,0x235,0x215,0x225,0x006,0x016,0x026,0x036,0x046,0x056,0x066,0x076,
		0x086,0x096,0x0a6,0x0b6,0x0c6,0x0d6,0x0e6,0x0f6,0x106,0x116,0x126,0x136,0x146,0x156,
		0x166,0x176,0x186,0x196,0x1a6,0x1b6,0x1c6,0x1d6,0x1e6,0x1f6,0x206,0x216,0x226,0x236,
		0x017,0x027,0x007,0x047,0x057,0x037,0x077,0x087,0x067,0x0a7,0x0b7,0x097,0x0d7,0x0e7,
		0x0c7,0x107,0x117,0x0f7,0x137,0x147,0x127,0x167,0x177,0x157,0x197,0x1a7,0x187,0x1c7,
		0x1d7,0x1b7,0x1f7,0x207,0x1e7,0x227,0x237,0x217,0x028,0x008,0x018,0x058,0x038,0x048,
		0x088,0x068,0x078,0x0b8,0x098,0x0a8,0x0e8,0x0c8,0x0d8,0x118,0x0f8,0x108,0x148,0x128,
		0x138,0x178,0x158,0x168,0x1a8,0x188,0x198,0x1d8,0x1b8,0x1c8,0x208,0x1e8,0x1f8,0x238,
		0x218,0x228,0x009,0x019,0x029,0x039,0x049,0x059,0x069,0x079,0x089,0x099,0x0a9,0x0b9,
		0x0c9,0x0d9,0x0e9,0x0f9,0x109,0x119,0x129,0x139,0x149,0x159,0x169,0x179,0x189,0x199,
		0x1a9,0x1b9,0x1c9,0x1d9,0x1e9,0x1f9,0x209,0x219,0x229,0x239,0x01a,0x02a,0x00a,0x04a,
		0x05a,0x03a,0x07a,0x08a,0x06a,0x0aa,0x0ba,0x09a,0x0da,0x0ea,0x0ca,0x10a,0x11a,0x0fa,
		0x13a,0x14a,0x12a,0x16a,0x17a,0x15a,0x19a,0x1aa,0x18a,0x1ca,0x1da,0x1ba,0x1fa,0x20a,
		0x1ea,0x22a,0x23a,0x21a,0x02b,0x00b,0x01b,0x05b,0x03b,0x04b,0x08b,0x06b,0x07b,0x0bb,
		0x09b,0x0ab,0x0eb,0x0cb,0x0db,0x11b,0x0fb,0x10b,0x14b,0x12b,0x13b,0x17b,0x15b,0x16b,
		0x1ab,0x18b,0x19b,0x1db,0x1bb,0x1cb,0x20b,0x1eb,0x1fb,0x23b,0x21b,0x22b,0x00c,0x01c,
		0x02c,0x03c,0x04c,0x05c,0x06c,0x07c,0x08c,0x09c,0x0ac,0x0bc,0x0cc,0x0dc,0x0ec,0x0fc,
		0x10c,0x11c,0x12c,0x13c,0x14c,0x15c,0x16c,0x17c,0x18c,0x19c,0x1ac,0x1bc,0x1cc,0x1dc,
		0x1ec,0x1fc,0x20c,0x21c,0x22c,0x23c,0x01d,0x02d,0x00d,0x04d,0x05d,0x03d,0x07d,0x08d,
		0x06d,0x0ad,0x0bd,0x09d,0x0dd,0x0ed,0x0cd,0x10d,0x11d,0x0fd,0x13d,0x14d,0x12d,0x16d,
		0x17d,0x15d,0x19d,0x1ad,0x18d,0x1cd,0x1dd,0x1bd,0x1fd,0x20d,0x1ed,0x22d,0x23d,0x21d,
		0x02e,0x00e,0x01e,0x05e,0x03e,0x04e,0x08e,0x06e,0x07e,0x0be,0x09e,0x0ae,0x0ee,0x0ce,
		0x0de,0x11e,0x0fe,0x10e,0x14e,0x12e,0x13e,0x17e,0x15e,0x16e,0x1ae,0x18e,0x19e,0x1de,
		0x1be,0x1ce,0x20e,0x1ee,0x1fe,0x23e,0x21e,0x22e,0x00f,0x01f,0x02f,0x03f,0x04f,0x05f,
		0x06f,0x07f,0x08f,0x09f,0x0af,0x0bf,0x0cf,0x0df,0x0ef,0x0ff,0x10f,0x11f,0x12f,0x13f,
		0x14f,0x15f,0x16f,0x17f,0x18f,0x19f,0x1af,0x1bf,0x1cf,0x1df,0x1ef,0x1ff,0x20f,0x21f,
		0x22f,0x23f
	};

/*
 * *************************************************************************************
 *                                                                                     *
 *					                    CC Encoder                                     *
 *                                                                                     *
 * -------------------------------------------------------------------------------------
 */

/*
 * *************************************************************************************
 * function: convolution code module
 * parameters: 
 *          UINT8 *p_dat_in,      //
 *          UINT8 *p_dat_out      // output points.
 *          UINT16  dat_len,       // p_dat_in length in bit.
 *          UINT8  cc_pun         // 2:1/2,4:2/3,6:3/4
 * return: void
 * description: convolution code module
 * -------------------------------------------------------------------------------------
 */

int dl_cc_enc
                (
                    UINT8 *p_dat_in,      // input bit
                    UINT8 *p_dat_out,     // CC output bit
                    UINT16 dat_len,       // input bit length(p_dat_in).
                    UINT8  rate_id
                )
 
{
    UINT8   polya = 121;
    UINT8   polyb = 91;
    UINT8 cc_pun = 0x00;
    UINT8 cc_dpun = 0x00;

    UINT16  i;
    UINT16  pun_cir_len;

    UINT8   wa = 0x00;
    UINT8   wb = 0x00;
    UINT8   conv_code0 = 0x00;
    UINT8   conv_code1 = 0x00;
    UINT8   conv_shreg = 0x00;

    UINT8   *conv_code = NULL;    
    UINT8   *dat_in = NULL;
    UINT8   *dat_out = NULL;

//parameter Generate
	switch(rate_id) {
		case 0 :
			cc_pun = 0x02;
			cc_dpun = 0x02;
			break;
		case 1 :
			cc_pun = 0x06;
			cc_dpun = 0x04;
			break;
		case 2 :
			cc_pun = 0x02;
			cc_dpun = 0x02;
			break;
		case 3 :
			cc_pun = 0x06;
			cc_dpun = 0x04;
			break;
		case 4 :
			cc_pun = 0x02;
			cc_dpun = 0x02;
			break;
		case 5 :
			cc_pun = 0x04;
			cc_dpun = 0x03;
			break;
		case 6 :
			cc_pun = 0x06;
			cc_dpun = 0x04;
			break;
		default :
            printf("<<<< Error: Not a valid rate_id for CC code(dl_cc_enc)! >>>>\n");
            break;
	}
//memory malloc

    conv_code = malloc(2*dat_len*sizeof(UINT8));
    if(conv_code ==NULL) {
        printf("conv_code in dl_cc_enc malloc fail!!\n");
        return(-1);
    }
    dat_in = malloc(dat_len*sizeof(UINT8));
    if(dat_in ==NULL) {
        printf("dat_in in dl_cc_enc malloc fail!!\n");
        return(-1);
    }
    dat_out = malloc(dat_len*2*cc_dpun/cc_pun*sizeof(UINT8));
    if(dat_out ==NULL) {
        printf("dat_out in dl_cc_enc malloc fail!!\n");
        return(-1);
    }

    ByteToBit
                (
                    p_dat_in,   //Byte
                    dat_in,     //Bit
                    dat_len     //Bit length         
                );

//convencation code

//	initializing

	conv_shreg = (UINT8)(((dat_in[dat_len-6]<<1)&0x02)|((dat_in[dat_len-5]<<2)&0x04)|((dat_in[dat_len-4]<<3)&0x08)|((dat_in[dat_len-3]<<4)&0x10)|((dat_in[dat_len-2]<<5)&0x20)|((dat_in[dat_len-1]<<6)&0x40));

    for(i=0; i < dat_len; i++) {
        conv_shreg = (UINT8)(((conv_shreg >>1) & 0x3F) | ((dat_in[i] <<6) & 0x40));        
        wa = (UINT8)((conv_shreg & polya) & 0x7F);
        wb = (UINT8)((conv_shreg & polyb) & 0x7F);

        conv_code0 = (UINT8)(((wa >>6) & 0x01) ^ ((wa >>5) & 0x01) ^ ((wa >>4) & 0x01) ^ ((wa >>3) & 0x01) ^ ((wa >>2) &0x01) ^ ((wa >>1) & 0x01) ^ (wa & 0x01)); 
        conv_code1 = (UINT8)(((wb >>6) & 0x01) ^ ((wb >>5) & 0x01) ^ ((wb >>4) & 0x01) ^ ((wb >>3) & 0x01) ^ ((wb >>2) &0x01) ^ ((wb >>1) & 0x01) ^ (wb & 0x01));

        conv_code[2*i+1] = (UINT8)(conv_code1 & 0x01);
        conv_code[2*i] = (UINT8)(conv_code0 & 0x01);
    }

//puncturing

    pun_cir_len = (UINT16)(2 * dat_len / cc_pun);

    for(i=0; i < pun_cir_len; i++) {
        switch(cc_pun) {
            case 2 : 
                dat_out[i*2] = conv_code[i*cc_pun];
                dat_out[i*2 +1] = conv_code[i*cc_pun +1];
                break;
            case 4 :
                    dat_out[i*3] = conv_code[i*cc_pun];
                    dat_out[i*3 +1] = conv_code[i*cc_pun +1];
                    dat_out[i*3 +2] = conv_code[i*cc_pun +3];
                break;
            case 6 :
                    dat_out[i*4] = conv_code[i*cc_pun];
                    dat_out[i*4 +1] = conv_code[i*cc_pun +1];
                    dat_out[i*4 +2] = conv_code[i*cc_pun +3];
                    dat_out[i*4 +3] = conv_code[i*cc_pun +4];
                break;
        }
    }

    BitToByte
                (
                    dat_out,  //Bit
                    p_dat_out, //Byte
                    (UINT16)(dat_len*2*cc_dpun/cc_pun) //Bit length         
                );

   if(conv_code !=NULL) {
       free(conv_code);      
   }
   if(dat_in !=NULL) {
       free(dat_in);      
   }
   if(dat_out !=NULL) {
       free(dat_out);      
   }
    return (0);
}


/*
 * *************************************************************************************
 *                                                                                     *
 *					                    CC Interleaver                                 *
 *                                                                                     *
 * -------------------------------------------------------------------------------------
 */
 /*
 * *************************************************************************************
 * function: dl_interleave module
 * parameters: 
 *          UINT8  *p_dat_in,  // block data input (byte)
 *          UINT8  *p_dat_out, // block data output(CC interleave result,bit)
 *          UINT16  blocksize, // block size
 *          UINT8   rate_id
 * description: CC interleave module
 * Author : caolin
 * -------------------------------------------------------------------------------------
 */

int dl_interleave
				(
					UINT8  *p_dat_in,  // block data input (byte)
					UINT8  *p_dat_out, // block data output(CC interleave result,bit)
					UINT16  blocksize, // block size
					UINT8   rate_id    
				)
{
	UINT16 i=0;

    UINT8  mod_type = 0x00;
 
    UINT8   *dat_in = NULL;
    UINT8   *dat_out = NULL;

//parameter Generate
	switch(rate_id) {
		case 0 :
		case 1 :
			mod_type = 0x02;
			break;
		case 2 :
		case 3 :
			mod_type = 0x04;
			break;
		case 4 :
		case 5 :
		case 6 :
			mod_type = 0x06;
			break;
		default :
            printf("<<<< Error: Not a valid rate_id for CC interleave(dl_interleave)! >>>>\n");
            break;
	}
//memory malloc    

    dat_in = malloc(blocksize*sizeof(UINT8));
    if(dat_in == NULL) {
        printf("data_in in dl_interleave module malloc fail!!\n");
        return(-1);
    }
    dat_out = malloc(blocksize*sizeof(UINT8));
    if(dat_out == NULL) {
        printf("dat_out in dl_interleave module malloc fail!!\n");
        return(-1);
    }

    ByteToBit
                (
                    p_dat_in,   //Byte
                    dat_in,     //Bit
                    blocksize     //Bit length         
                );

	switch(mod_type) {
		case 2 : //QPSK
			switch(blocksize) {
				case 96 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_96[i]];
					}
					break;
				case 192 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_192[i]];
					}
					break;
				case 288 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_288[i]];
					}
					break;
				case 384 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_384[i]];
					}
					break;
				case 480 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_480[i]];
					}
					break;
				case 576 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_QPSK_576[i]];
					}
					break;
				default :
					printf("ERROR: No such block size(QPSK-Intlver)!");
					break;
			}
			break;
		case 4 : //16QAM
			switch(blocksize) {
				case 192 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_16QAM_192[i]];
					}
					break;
				case 384 :
					for(i=0; i < blocksize; i++) {
						dat_out[i] = dat_in[addint_CC_16QAM_384[i]];
					}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -