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

📄 rayleigh_fade.c

📁 好东西
💻 C
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Fri Mar 24 11:31:37 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 "rayleigh_fade.h"
#include "libmatlbm.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
static mxArray * _mxarray2_;
static mxArray * _mxarray3_;
static mxArray * _mxarray4_;
static mxArray * _mxarray5_;
static mxArray * _mxarray6_;

void InitializeModule_rayleigh_fade(void) {
    _mxarray0_ = mclInitializeDouble(25.0);
    _mxarray1_ = mclInitializeDouble(0.0);
    _mxarray2_ = mclInitializeDouble(1.0);
    _mxarray3_ = mclInitializeDouble(2.0);
    _mxarray4_ = mclInitializeDouble(3.14159265);
    _mxarray5_ = mclInitializeDouble(4.0);
    _mxarray6_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
}

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

static mxArray * Mrayleigh_fade(int nargout_,
                                mxArray * nsamp,
                                mxArray * tstp,
                                mxArray * fd,
                                mxArray * counter);

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

/*
 * The function "mlfRayleigh_fade" contains the normal interface for the
 * "rayleigh_fade" M-function from file
 * "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\rayleigh_fade.m" (lines 1-59).
 * This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfRayleigh_fade(mxArray * nsamp,
                           mxArray * tstp,
                           mxArray * fd,
                           mxArray * counter) {
    int nargout = 1;
    mxArray * ray_chann = NULL;
    mlfEnterNewContext(0, 4, nsamp, tstp, fd, counter);
    ray_chann = Mrayleigh_fade(nargout, nsamp, tstp, fd, counter);
    mlfRestorePreviousContext(0, 4, nsamp, tstp, fd, counter);
    return mlfReturnValue(ray_chann);
}

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

/*
 * The function "Mrayleigh_fade" is the implementation version of the
 * "rayleigh_fade" M-function from file
 * "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\rayleigh_fade.m" (lines 1-59).
 * 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 ray_chann=rayleigh_fade(nsamp,tstp,fd,counter)
 */
static mxArray * Mrayleigh_fade(int nargout_,
                                mxArray * nsamp,
                                mxArray * tstp,
                                mxArray * fd,
                                mxArray * counter) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_rayleigh_fade);
    mxArray * ray_chann = NULL;
    mxArray * cwmt = NULL;
    mxArray * cwn = NULL;
    mxArray * nn = NULL;
    mxArray * ic = NULL;
    mxArray * xs = NULL;
    mxArray * xc = NULL;
    mxArray * paino = NULL;
    mxArray * wmts = NULL;
    mxArray * ts = NULL;
    mxArray * n = NULL;
    mxArray * wm = NULL;
    mxArray * pai = NULL;
    mxArray * as0 = NULL;
    mxArray * ac0 = NULL;
    mxArray * no = NULL;
    mclCopyArray(&nsamp);
    mclCopyArray(&tstp);
    mclCopyArray(&fd);
    mclCopyArray(&counter);
    /*
     * 
     * %****************** variables *************************
     * % idata  : input Ich data     
     * % qdata  : input Qch data     
     * % iout   : output Ich data
     * % qout   : output Qch data
     * % ramp   : Amplitude contaminated by fading
     * % rcos   : Cosine value contaminated by fading
     * % rsin   : Cosine value contaminated by fading
     * % nsamp  : Number of samples to be simulated       
     * % tstp   : Minimum time resolution                    
     * % fd     : maximum doppler frequency               
     * % no     : number of waves in order to generate fading   
     * % counter  : fading counter                          
     * % flat     : flat fading or not 
     * % (1->flat (only amplitude is fluctuated),0->nomal(phase and amplitude are fluctutated)    
     * %******************************************************
     * no=25;
     */
    mlfAssign(&no, _mxarray0_);
    /*
     * if fd ~= 0.0  
     */
    if (mclNeBool(mclVa(fd, "fd"), _mxarray1_)) {
        /*
         * ac0 = sqrt(1.0 ./ (2.0.*(no + 1)));   % power normalized constant(ich)
         */
        mlfAssign(
          &ac0,
          mlfSqrt(
            mclRdivide(
              _mxarray2_,
              mclTimes(_mxarray3_, mclPlus(mclVv(no, "no"), _mxarray2_)))));
        /*
         * as0 = sqrt(1.0 ./ (2.0.*no));         % power normalized constant(qch)
         */
        mlfAssign(
          &as0,
          mlfSqrt(
            mclRdivide(_mxarray2_, mclTimes(_mxarray3_, mclVv(no, "no")))));
        /*
         * %ic0 = counter;                        % fading counter
         * 
         * pai = 3.14159265;   
         */
        mlfAssign(&pai, _mxarray4_);
        /*
         * wm = 2.0.*pai.*fd;
         */
        mlfAssign(
          &wm,
          mclTimes(mclTimes(_mxarray3_, mclVv(pai, "pai")), mclVa(fd, "fd")));
        /*
         * n = 4.*no + 2;
         */
        mlfAssign(
          &n, mclPlus(mclTimes(_mxarray5_, mclVv(no, "no")), _mxarray3_));
        /*
         * ts = tstp;
         */
        mlfAssign(&ts, mclVa(tstp, "tstp"));
        /*
         * wmts = wm.*ts;
         */
        mlfAssign(&wmts, mclTimes(mclVv(wm, "wm"), mclVv(ts, "ts")));
        /*
         * paino = pai./no;                        
         */
        mlfAssign(&paino, mclRdivide(mclVv(pai, "pai"), mclVv(no, "no")));
        /*
         * 
         * xc=zeros(1,nsamp);
         */
        mlfAssign(&xc, mlfZeros(_mxarray2_, mclVa(nsamp, "nsamp"), NULL));
        /*
         * xs=zeros(1,nsamp);
         */
        mlfAssign(&xs, mlfZeros(_mxarray2_, mclVa(nsamp, "nsamp"), NULL));
        /*
         * ic=[1:nsamp]+counter;
         */
        mlfAssign(
          &ic,
          mclPlus(
            mlfColon(_mxarray2_, mclVa(nsamp, "nsamp"), NULL),
            mclVa(counter, "counter")));
        /*
         * 
         * for nn = 1: no
         */
        {
            int v_ = mclForIntStart(1);
            int e_ = mclForIntEnd(mclVv(no, "no"));
            if (v_ > e_) {
                mlfAssign(&nn, _mxarray6_);
            } else {
                /*
                 * cwn = cos( cos(2.0.*pai.*nn./n).*ic.*wmts );
                 * xc = xc + cos(paino.*nn).*cwn;
                 * xs = xs + sin(paino.*nn).*cwn;
                 * end
                 */
                for (; ; ) {
                    mlfAssign(
                      &cwn,
                      mlfCos(
                        mclTimes(
                          mclTimes(
                            mlfCos(
                              mclRdivide(
                                mclTimes(
                                  mclTimes(_mxarray3_, mclVv(pai, "pai")),
                                  mlfScalar(v_)),
                                mclVv(n, "n"))),
                            mclVv(ic, "ic")),
                          mclVv(wmts, "wmts"))));
                    mlfAssign(
                      &xc,
                      mclPlus(
                        mclVv(xc, "xc"),
                        mclTimes(
                          mlfCos(
                            mclTimes(mclVv(paino, "paino"), mlfScalar(v_))),
                          mclVv(cwn, "cwn"))));
                    mlfAssign(
                      &xs,
                      mclPlus(
                        mclVv(xs, "xs"),
                        mclTimes(
                          mlfSin(
                            mclTimes(mclVv(paino, "paino"), mlfScalar(v_))),
                          mclVv(cwn, "cwn"))));
                    if (v_ == e_) {
                        break;
                    }
                    ++v_;
                }
                mlfAssign(&nn, mlfScalar(v_));
            }
        }
        /*
         * 
         * cwmt = sqrt(2.0).*cos(ic.*wmts);
         */
        mlfAssign(
          &cwmt,
          mclTimes(
            mlfSqrt(_mxarray3_),
            mlfCos(mclTimes(mclVv(ic, "ic"), mclVv(wmts, "wmts")))));
        /*
         * xc = (2.0.*xc + cwmt).*ac0;
         */
        mlfAssign(
          &xc,
          mclTimes(
            mclPlus(mclTimes(_mxarray3_, mclVv(xc, "xc")), mclVv(cwmt, "cwmt")),
            mclVv(ac0, "ac0")));
        /*
         * xs = 2.0.*xs.*as0;
         */
        mlfAssign(
          &xs,
          mclTimes(mclTimes(_mxarray3_, mclVv(xs, "xs")), mclVv(as0, "as0")));
        /*
         * 
         * %ramp=sqrt(xc.^2+xs.^2);   
         * %rcos=xc./ramp;
         * %rsin=xs./ramp;
         * ray_chann=sqrt(xc.^2+xs.^2);
         */
        mlfAssign(
          &ray_chann,
          mlfSqrt(
            mclPlus(
              mlfPower(mclVv(xc, "xc"), _mxarray3_),
              mlfPower(mclVv(xs, "xs"), _mxarray3_))));
    /*
     * %ray_chann=xc+xs*sqrt(-1);
     * 
     * 
     * 
     * else  
     */
    } else {
        /*
         * ray_chann=ones(1,nsamp);
         */
        mlfAssign(&ray_chann, mlfOnes(_mxarray2_, mclVa(nsamp, "nsamp"), NULL));
    /*
     * end
     */
    }
    mclValidateOutput(ray_chann, 1, nargout_, "ray_chann", "rayleigh_fade");
    mxDestroyArray(no);
    mxDestroyArray(ac0);
    mxDestroyArray(as0);
    mxDestroyArray(pai);
    mxDestroyArray(wm);
    mxDestroyArray(n);
    mxDestroyArray(ts);
    mxDestroyArray(wmts);
    mxDestroyArray(paino);
    mxDestroyArray(xc);
    mxDestroyArray(xs);
    mxDestroyArray(ic);
    mxDestroyArray(nn);
    mxDestroyArray(cwn);
    mxDestroyArray(cwmt);
    mxDestroyArray(counter);
    mxDestroyArray(fd);
    mxDestroyArray(tstp);
    mxDestroyArray(nsamp);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return ray_chann;
    /*
     * 
     * % ************************end of file***********************************
     */
}

⌨️ 快捷键说明

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