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

📄 main_rs.c

📁 介绍关于WiMax(IEEE802.16)物理层调制解调编码等相关设计实现
💻 C
字号:
/*****************************************************************************//*   FIle Name : main_rs.c                                                   *//*   Description : Main routine to Test Reed-Solomon FEC                     *//*   author : miffie                                                         *//*   Date   : sep/23/05                                                      *//*   Copyright (c) 2005 miffie   All rights reserved.                        *//*****************************************************************************///Special thanks to original author of this code/* This program is an encoder/decoder for Reed-Solomon codes. Encoding is in   systematic form, decoding via the Berlekamp iterative algorithm.   In the present form , the constants mm, nn, tt, and kk=nn-2tt must be   specified  (the double letters are used simply to avoid clashes with   other n,k,t used in other programs into which this was incorporated!)   Also, the irreducible polynomial used to generate GF(2**mm) must also be   entered -- these can be found in Lin and Costello, and also Clark and Cain.   The representation of the elements of GF(2**m) is either in index form,   where the number is the power of the primitive element alpha, which is   convenient for multiplication (add the powers modulo 2**m-1) or in   polynomial form, where the bits represent the coefficients of the   polynomial representation of the number, which is the most convenient form   for addition.  The two forms are swapped between via lookup tables.   This leads to fairly messy looking expressions, but unfortunately, there   is no easy alternative when working with Galois arithmetic.   The code is not written in the most elegant way, but to the best   of my knowledge, (no absolute guarantees!), it works.   However, when including it into a simulation program, you may want to do   some conversion of global variables (used here because I am lazy!) to   local variables where appropriate, and passing parameters (eg array   addresses) to the functions  may be a sensible move to reduce the number   of global variables and thus decrease the chance of a bug being introduced.   This program does not handle erasures at present, but should not be hard   to adapt to do this, as it is just an adjustment to the Berlekamp-Massey   algorithm. It also does not attempt to decode past the BCH bound -- see   Blahut "Theory and practice of error control codes" for how to do this.              Simon Rockliff, University of Adelaide   21/9/89   26/6/91 Slight modifications to remove a compiler dependent bug which hadn't           previously surfaced. A few extra comments added for clarity.           Appears to all work fine, ready for posting to net!                  Notice                 --------   This program may be freely modified and/or given to whoever wants it.   A condition of such distribution is that the author's contribution be   acknowledged by his name being left in the comments heading the program,   however no responsibility is accepted for any financial or other loss which   may result from some unforseen errors or malfunctioning of the program   during use.                                 Simon Rockliff, 26th June 1991*/#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 *///#define nn  255          /* nn=2**mm -1   length of codeword *///#define tt  16         /* number of errors that can be corrected *///#define kk  223           /* kk = nn-2*tt  */int pp [mm+1] = { 1, 0, 1, 1, 1, 0, 0, 0, 1} ; /* specify irreducible polynomial coeffts */#include "encode_rs.c"#include "decode_rs.c"main(){  static int NN = 255 ;  register int ii , jj ;  char num_erasure ;  char fail  ;  char RR ;  short  KK  , num_data   ;  struct  binaryset bset, exp ;  unsigned char     data[NN] ;  char message[] = { 0xd4, 0xba, 0xa1, 0x12, 0xf2, 0x74, 0x96, 0x30,                     0x27, 0xd4, 0x88, 0x9c, 0x96, 0xe3, 0xa9, 0x52,                     0xb3, 0x15, 0xab, 0xfd, 0x92, 0x53, 0x07, 0x32,                     0xc0, 0x62, 0x48, 0xf0, 0x19, 0x22, 0xe0, 0x91,                     0x62, 0x1a, 0xc1 } ; //0x23      //multiple tests  for  (jj=0;jj<1000;jj++) { //each test    RR=int_random(17)*2 ; // 2 bytes * number of errors that can be corrected(tt)     KK= NN-RR ; //number of data inputs to encoder    /* for known data, stick a few numbers into a zero codeword. Data is in       polynomial form.    */    //make a binary set    num_data = int_random(KK+1) ; //0-KK    printf("\n %d th Test(RR=%d num_data=%d)\n\n", jj, RR, num_data ) ;    for  (ii=0; ii<num_data; ii++)   data[ii] = int_random(256)&NN ;    bset.format = 1 ;    bset.data = &data[0] ;    bset.size = num_data ;      /* encode data[] to produce parity in bb[].  Data input and parity output       is in polynomial form    */    exp = copy_binaryset(bset) ;    print_binaryset(bset) ;       bset =  encode_rs(bset, RR ) ;    print_binaryset(bset) ;      /* if you want to test the program, corrupt some of the elements of recd[]       here. This can also be done easily in a debugger. */    num_erasure = int_random((RR/2)+1) ; //0-RR    printf("..adding %d out of %d errors\n", num_erasure, num_data ) ;    for(ii=0; ii<num_erasure; ii++)       bset.data[(int_random(bset.size+1)&NN)] ^= int_random(256) ;      print_binaryset(bset) ;      /* decode recv[] */    bset = decode_rs( bset, RR ) ;         /* recd[] is returned in polynomial form */      print_binaryset(bset) ;    fail = compare_binaryset( exp , bset ) ;  } //each test}  

⌨️ 快捷键说明

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