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

📄 multipath_chann.c

📁 好东西
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Fri Mar 24 11:31:36 2006
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-m" "-W" "main" "-L"
 * "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib"
 * "adptive_bitpow_allocate_systems" 
 */
#include "multipath_chann.h"
#include "libmatlbm.h"
#include "rayleigh_fade.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
static mxArray * _mxarray2_;
static mxArray * _mxarray3_;
static mxArray * _mxarray4_;
static mxArray * _mxarray5_;
static mxArray * _mxarray6_;

void InitializeModule_multipath_chann(void) {
    _mxarray0_ = mclInitializeDouble(10.0);
    _mxarray1_ = mclInitializeDouble(1.0);
    _mxarray2_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
    _mxarray3_ = mclInitializeDouble(0.0);
    _mxarray4_ = mclInitializeDouble(-1.0);
    _mxarray5_ = mclInitializeDouble(2.0);
    _mxarray6_ = mclInitializeDouble(3.141592653589793);
}

void TerminateModule_multipath_chann(void) {
    mxDestroyArray(_mxarray6_);
    mxDestroyArray(_mxarray5_);
    mxDestroyArray(_mxarray4_);
    mxDestroyArray(_mxarray3_);
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray1_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Mmultipath_chann(mxArray * * Hk,
                                  int nargout_,
                                  mxArray * input_sig,
                                  mxArray * num,
                                  mxArray * var_pow,
                                  mxArray * delay,
                                  mxArray * fd,
                                  mxArray * t_interval,
                                  mxArray * counter,
                                  mxArray * count_begin,
                                  mxArray * cp_n);

_mexLocalFunctionTable _local_function_table_multipath_chann
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfMultipath_chann" contains the normal interface for the
 * "multipath_chann" M-function from file
 * "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\multipath_chann.m" (lines
 * 1-74). This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfMultipath_chann(mxArray * * Hk,
                             mxArray * input_sig,
                             mxArray * num,
                             mxArray * var_pow,
                             mxArray * delay,
                             mxArray * fd,
                             mxArray * t_interval,
                             mxArray * counter,
                             mxArray * count_begin,
                             mxArray * cp_n) {
    int nargout = 1;
    mxArray * output_sig = NULL;
    mxArray * Hk__ = NULL;
    mlfEnterNewContext(
      1,
      9,
      Hk,
      input_sig,
      num,
      var_pow,
      delay,
      fd,
      t_interval,
      counter,
      count_begin,
      cp_n);
    if (Hk != NULL) {
        ++nargout;
    }
    output_sig
      = Mmultipath_chann(
          &Hk__,
          nargout,
          input_sig,
          num,
          var_pow,
          delay,
          fd,
          t_interval,
          counter,
          count_begin,
          cp_n);
    mlfRestorePreviousContext(
      1,
      9,
      Hk,
      input_sig,
      num,
      var_pow,
      delay,
      fd,
      t_interval,
      counter,
      count_begin,
      cp_n);
    if (Hk != NULL) {
        mclCopyOutputArg(Hk, Hk__);
    } else {
        mxDestroyArray(Hk__);
    }
    return mlfReturnValue(output_sig);
}

/*
 * The function "mlxMultipath_chann" contains the feval interface for the
 * "multipath_chann" M-function from file
 * "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\multipath_chann.m" (lines
 * 1-74). The feval function calls the implementation version of
 * multipath_chann through this function. This function processes any input
 * arguments and passes them to the implementation version of the function,
 * appearing above.
 */
void mlxMultipath_chann(int nlhs,
                        mxArray * plhs[],
                        int nrhs,
                        mxArray * prhs[]) {
    mxArray * mprhs[9];
    mxArray * mplhs[2];
    int i;
    if (nlhs > 2) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: multipath_chann Line: 1 Colum"
            "n: 1 The function \"multipath_chann\" was called wi"
            "th more than the declared number of outputs (2)."),
          NULL);
    }
    if (nrhs > 9) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: multipath_chann Line: 1 Colum"
            "n: 1 The function \"multipath_chann\" was called wi"
            "th more than the declared number of inputs (9)."),
          NULL);
    }
    for (i = 0; i < 2; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 9 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 9; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(
      0,
      9,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6],
      mprhs[7],
      mprhs[8]);
    mplhs[0]
      = Mmultipath_chann(
          &mplhs[1],
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3],
          mprhs[4],
          mprhs[5],
          mprhs[6],
          mprhs[7],
          mprhs[8]);
    mlfRestorePreviousContext(
      0,
      9,
      mprhs[0],
      mprhs[1],
      mprhs[2],
      mprhs[3],
      mprhs[4],
      mprhs[5],
      mprhs[6],
      mprhs[7],
      mprhs[8]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 2 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 2; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

/*
 * The function "Mmultipath_chann" is the implementation version of the
 * "multipath_chann" M-function from file
 * "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\multipath_chann.m" (lines
 * 1-74). It contains the actual compiled code for that M-function. It is a
 * static function and must only be called from one of the interface functions,
 * appearing below.
 */
/*
 * function [output_sig,Hk]=multipath_chann(input_sig,num,var_pow,delay,fd,t_interval,counter,count_begin,cp_n)
 */
static mxArray * Mmultipath_chann(mxArray * * Hk,
                                  int nargout_,
                                  mxArray * input_sig,
                                  mxArray * num,
                                  mxArray * var_pow,
                                  mxArray * delay,
                                  mxArray * fd,
                                  mxArray * t_interval,
                                  mxArray * counter,
                                  mxArray * count_begin,
                                  mxArray * cp_n) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(
          &_local_function_table_multipath_chann);
    mxArray * output_sig = NULL;
    mxArray * output_sig_serial = NULL;
    mxArray * f = NULL;
    mxArray * delay_sig = NULL;
    mxArray * input_sig_serial = NULL;
    mxArray * ll = NULL;
    mxArray * sum1 = NULL;
    mxArray * ii = NULL;
    mxArray * kk = NULL;
    mxArray * selec_ray_channew = NULL;
    mxArray * N_ofdm = NULL;
    mxArray * N_carrier = NULL;
    mxArray * atts = NULL;
    mxArray * k = NULL;
    mxArray * total_pow_allchan = NULL;
    mxArray * pow_per_channel = NULL;
    mxArray * selec_ray_chan = NULL;
    mxArray * chann_l = NULL;
    mxArray * l = NULL;
    mxArray * nl = NULL;
    mxArray * t_shift = NULL;
    mclCopyArray(&input_sig);
    mclCopyArray(&num);
    mclCopyArray(&var_pow);
    mclCopyArray(&delay);
    mclCopyArray(&fd);
    mclCopyArray(&t_interval);
    mclCopyArray(&counter);
    mclCopyArray(&count_begin);
    mclCopyArray(&cp_n);
    /*
     * %input_sig输入信号矩阵,加了cp后的信号,大小为NL×(子载波个数+cp长度lp);
     * %num多径数;
     * %var_pow各径相对主径的平均功率,单位dB;
     * %delay各径延时,单位s;
     * %fd最大dopple频率;
     * %t_interval为离散信道抽样时间间隔,等于OFDM符号长度/(子载波个数+cp长度lp);
     * %output_sig为经过多径信道的输出信号矢量
     * %counter各径间隔记录
     * %count_begin本次产生信道开始记录的初始位置
     * 
     * t_shift=round(delay/t_interval);%归一化各径延时
     */
    mlfAssign(
      &t_shift,
      mlfRound(
        mclMrdivide(mclVa(delay, "delay"), mclVa(t_interval, "t_interval"))));
    /*
     * %theta_shift=2*pi*fc*delay;
     * [nl,l]=size(input_sig);
     */
    mlfSize(mlfVarargout(&nl, &l, NULL), mclVa(input_sig, "input_sig"), NULL);
    /*
     * output_sig=zeros(size(input_sig));
     */
    mlfAssign(
      &output_sig,
      mlfZeros(
        mlfSize(mclValueVarargout(), mclVa(input_sig, "input_sig"), NULL),
        NULL));
    /*
     * 
     * chann_l=nl*l;%信道采样点数,若一个调制符号采样一个信道点,则信道采样点数等于输入信号中的调制符号个数
     */
    mlfAssign(&chann_l, mclMtimes(mclVv(nl, "nl"), mclVv(l, "l")));
    /*
     * selec_ray_chan=zeros(num,chann_l);%初始化频率选择性信道,径数=num
     */
    mlfAssign(
      &selec_ray_chan,
      mlfZeros(mclVa(num, "num"), mclVv(chann_l, "chann_l"), NULL));
    /*
     * pow_per_channel=10.^(var_pow/10);%各径功率线性化,从dB转变成线性
     */
    mlfAssign(
      &pow_per_channel,
      mlfPower(_mxarray0_, mclMrdivide(mclVa(var_pow, "var_pow"), _mxarray0_)));
    /*
     * total_pow_allchan=sum(pow_per_channel(1:num));%各径功率之和
     */
    mlfAssign(
      &total_pow_allchan,
      mlfSum(
        mclArrayRef1(
          mclVv(pow_per_channel, "pow_per_channel"),
          mlfColon(_mxarray1_, mclVa(num, "num"), NULL)),
        NULL));
    /*
     * %以下for循环产生相互独立的num条rayleigh信道
     * for k=1:num
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclVa(num, "num"));
        if (v_ > e_) {
            mlfAssign(&k, _mxarray2_);
        } else {
            /*
             * atts=sqrt(pow_per_channel(k));
             * selec_ray_chan(k,:)=atts*rayleigh_fade(chann_l,t_interval,fd,count_begin+k*counter)/sqrt(total_pow_allchan);
             * %selec_ray_chan(k,:)=atts*rayleigh_filtered(fd,t_interval,chann_l)/sqrt(total_pow_allchan);
             * end
             */
            for (; ; ) {
                mlfAssign(
                  &atts,
                  mlfSqrt(
                    mclIntArrayRef1(
                      mclVv(pow_per_channel, "pow_per_channel"), v_)));
                mclArrayAssign2(
                  &selec_ray_chan,
                  mclMrdivide(
                    mclMtimes(
                      mclVv(atts, "atts"),
                      mlfRayleigh_fade(
                        mclVv(chann_l, "chann_l"),
                        mclVa(t_interval, "t_interval"),
                        mclVa(fd, "fd"),
                        mclPlus(
                          mclVa(count_begin, "count_begin"),
                          mclMtimes(
                            mlfScalar(v_), mclVa(counter, "counter"))))),
                    mlfSqrt(mclVv(total_pow_allchan, "total_pow_allchan"))),
                  mlfScalar(v_),
                  mlfCreateColonIndex());
                if (v_ == e_) {
                    break;
                }

⌨️ 快捷键说明

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