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

📄 rscore.c

📁 Proakis《contemporarycommunication systems using matlab》matlab源代码
💻 C
字号:
/*============================================================================
 *  Syntax: [msg, err, ccode] = rscore(code, k, tp, dim, pow_dim)
 *RSCORE The core function in Reed-Solomon decode.
 *      MSG = RSCORE(CODE, K, TP, M, POW_M, T2) decodes a single codeword
 *      vector CODE using Reed-Solomon decoding technique. The message length
 *      is K. The complete (and correct) list of all members in GF(2^M) is
 *      in TP. The code word length is provided in POW_M, which equals to
 *      2^M - 1. The decoding result is provided in the output variable MSG.
 *
 *      [MSG, ERR] = RSCORE(CODE, K, TP, M, POW_M, T2) outputs the error 
 *      detected in the decoding.
 *
 *      [MSG, ERR, CCODE] = RSCORE(CODE, K, TP, M, POW_M, T2) outputs the
 *      corrected codeword in CCODE.
 *
 *      NOTE. Different from all of the other encoding/decoding functions,
 *      this function takes the exponential input instead of regular input for
 *      processing. For example [-Inf, 0, 1, 2, ...] represents
 *      [0 1 alpha, alpha^2, ...] in GF(2^m). There are 2^M elements in
 *      GF(2^M). Hence, the input CODE represents 2^M * (2^M - 1) bits of
 *      information. The decoded MSG represents 2^M * K bits of information.
 *      For speeding computation, no error-check is placed in this function,
 *      all input variables must be presented.
 *
 *  See also: errlocp, bchcore
 *============================================================================
 *     Original designed by Wes Wang,
 *     Jun Wu,     The Mathworks, Inc.
 *     Dec-12, 1995
 *
 *     Copyright (c) 1995-96 by The MAthWorks, Inc.
 *     All Rights Reserved
 *     $Revision: 1.1 $  $Date: 1996/04/01 18:14:46 $
 *==========================================================================
 */
#include <math.h>
#include "mex.h"
#include "gflib.c"
void mexFunction(int nlhs, Matrix *plhs[], int nrhs, Matrix *prhs[])
{
  int     i, np, mp, pow_dim, dim, k;
  int     *code, *pp, *Iwork, *ccode, *err;
  double  *Msg, *Err, *CCode;
  
  np = mxGetM(prhs[2]);
  mp = mxGetN(prhs[2]);
  pow_dim = (int)mxGetPr(prhs[4])[0];
  code = (int *)mxCalloc(pow_dim,sizeof(int));
  for(i=0; i<pow_dim; i++)
    code[i] = (int)mxGetPr(prhs[0])[i];
  k = (int)mxGetPr(prhs[1])[0];
  pp = (int *)mxCalloc(np*mp,sizeof(int));
  for(i=0; i< np*mp; i++)
    pp[i] = (int)mxGetPr(prhs[2])[i];
  dim = (int)mxGetPr(prhs[3])[0];
  if ( nrhs < 5 || k <= 0 || dim != mp || pow_dim < (np-1) || mxGetM(prhs[0])*mxGetN(prhs[0]) != pow_dim ){
    mexErrMsgTxt("Not Correct Input Argument! Input again!");        
    return;
  }
  
  /* set up a integer working space (int *)Iwork. */
  Iwork = (int *)mxCalloc( (pow_dim-2*k+5*dim+19)*pow_dim+3*dim+k*(k-13)+28, sizeof(int));
  err = Iwork;
  err[0] = 0;
  ccode = Iwork + 1;
  for(i=0; i<pow_dim; i++)
    ccode[i] = 0;
  rscore(code, k, pp, dim, pow_dim, Iwork+1+pow_dim, err, ccode);
  
  Msg = mxGetPr(plhs[0] = mxCreateFull(1, k, 0));
  Err = mxGetPr(plhs[1] = mxCreateFull(1, 1, 0));
  CCode = mxGetPr(plhs[2] = mxCreateFull(1, pow_dim, 0));
  for(i=0; i < pow_dim; i++)
    CCode[i] = (double)ccode[i];
  for(i=pow_dim-k; i < pow_dim; i++)
    Msg[i-pow_dim+k] = CCode[i];
  Err[0] = (double)err[0];
  return;
}
/* end of rscore.c */
 

⌨️ 快捷键说明

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