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

📄 main_lfsr.c

📁 这个文件包括wimax中所有的编解码源代码
💻 C
字号:
/*****************************************************************************//*   FIle Name : main_turbo.c                                                *//*   Description : Main routine to Test FEC  Type2                           *//*   author : miffie                                                         *//*   Date   : sep/26/05                                                      *//*   Copyright (c) 2005 miffie   All rights reserved.                        *//*****************************************************************************/#include <math.h>#include <stdio.h>#include <stdlib.h>//Global variableschar   print_on = 1 ;#define  PRINTF if (print_on) printf#define  FPRINTF if (print_on) fprintf#include "../env/binaryset.c"#include "../env/utility.c"#define mm  8           /* RS code over GF(2**4) - change to suit *///Parity calculation with LinearFeedbackShiftRegisterchar lfsr ( char type , char datain, char shifter ) {char check , tmp1 ;     if(type==3)  { //x^6+x+1             tmp1 = ((datain^(shifter>>5)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x3f ;     } //x^6+x+1     else if (type==2) { //x^5+x^2+1             tmp1 = ((datain^(shifter>>4)) &0x1) ;             check = (tmp1) ? ((shifter^0x02)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x1f ;     }  //x^5+x^2+1     else if (type==1) { //x^4+x^1+1             tmp1 = ((datain^(shifter>>3)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x0f ;     //printf("shifter=%x datain=%x check=%x\n", shifter, datain , check ) ;     }  //x^4+x^1+1     else { //x^3+x^1+1             tmp1 = ((datain^(shifter>>2)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x07 ;     }  //x^3+x^1+1     return ( check ) ;} //lfsr//#include "turboproduct.c"#include "viterbi_turbo1.c"#include "viterbi_turbo2.c"//#include "turbo_decoder.c"main(){  static int NN = 255 ;  register int ii , jj, kk ;  char num_erasure ;  char fail  ;  short  KK  , shifter , noise1 , noise2 , tmp1  ;  struct  binaryset bset, exp , bset0, bset1,  metric;  unsigned char     data[64] ;  char row = 44 ;  char rowtype=3 ;  char sum , pp , nn, parity ;    //multiple tests  for  (jj=0;jj<100;jj++) { //each test    ////////////////////////////////////////////////////////////////    //Encoding    //make a binary set    row = (rowtype==3) ? int_random(26) +32 :          (rowtype==2) ?  int_random(11)+16 :          (rowtype==1) ?  int_random(4)+8  : int_random(2)+2 ;    pp= (rowtype==3) ?  6 :        (rowtype==2) ?  5 :         (rowtype==1) ?  4 : 3 ; //lfsr length    nn= (rowtype==3) ?  0x3f :         (rowtype==2) ?  0x1f :        (rowtype==1) ?  0x0f : 0x07 ; //lfsr length    for  (ii=0; ii<row; ii++)   data[ii] = int_random(2) ;    bset.format = 0 ;    bset.data = &data[0] ;    bset.size = row ;    ////////////////////////////////////////////////////////////////    //check calculation         shifter = 0 ; //Linear Feedback Shift Register         //data         for(ii=0;ii<row;ii++) { //each bit           shifter = lfsr(rowtype, bset.data[ii], shifter ) ;         } //each bit         //checks append         for(ii=0;ii<pp;ii++) { //each bit           bset.data[ii+row] = (shifter>>(pp-1-ii)) & 0x1 ;         } //each bit         //parity         parity = 0 ;         for(ii=0;ii<(row+pp);ii++) { //each bit           parity ^= bset.data[ii] ;         } //each bit         bset.data[row+pp] = parity ;    bset.size = row + pp + 1 ;    print_binaryset(bset) ;    exp = copy_binaryset(bset) ;         shifter = 0 ; //Linear Feedback Shift Register         for(ii=0;ii<bset.size-1;ii++) { //each bit           shifter = lfsr(rowtype, bset.data[ii], shifter ) ;           printf("%d good %d shifter=%x\n",ii, bset.data[ii], shifter ) ;         } //each bit    ////////////////////////////////////////////////////////////////    for(ii=0;ii<bset.size;ii++) { //each bit         bset.data[ii] = (bset.data[ii]) ? 9+int_random(7)  : int_random(7) ;    } //each bit    //noise append    for(ii=0;ii<2;ii++) {      noise1 = int_random(bset.size) ;      bset.data[noise1] = (bset.data[noise1]>=8) ? 0x6  : 0x9 ;      printf(" noise1=%d\n",   noise1 ) ;    }     print_binaryset(bset) ;    // checking         shifter = 0 ; //Linear Feedback Shift Register         for(ii=0;ii<bset.size-1;ii++) { //each bit           tmp1 = (bset.data[ii]>=8) ? 1 : 0 ;           shifter = lfsr(rowtype, tmp1, shifter ) ;           printf("%d received %d shifter=%x\n",ii, tmp1, shifter ) ;         } //each bit    // checking         shifter = 0 ; //Linear Feedback Shift Register         for(ii=0;ii<bset.size-1;ii++) { //each bit           tmp1 = ((bset.data[ii]>=8) &  (exp.data[ii]==0)) ? 1 :                    ((bset.data[ii]<8) &  (exp.data[ii]==1)) ? 1 :  0 ;           shifter = lfsr(rowtype, tmp1, shifter ) ;           printf("%d error %d shifter=%x\n",ii, tmp1 , shifter ) ;         } //each bit    ////////////////////////////////////////////////////////////////    //Decoder    metric = viterbi_turbo1( rowtype, bset ,  &parity) ;    bset =  viterbi_turbo2( rowtype, bset ,  metric ,  &parity) ;    print_binaryset(bset) ;    for(ii=0;ii<bset.size;ii++)       bset.data[ii] = (bset.data[ii]>=8) ? 1 : 0 ;    fail = compare_binaryset(exp, bset) ;  } //each test}

⌨️ 快捷键说明

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