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

📄 ctc_mapdec.c

📁 OFDMA 物理层开发的matlab 源码.飞思卡尔提供.对物理层开发的工程师有帮助!
💻 C
字号:
/* ============================================================================
   Property of Freescale
   Freescale Confidential Proprietary
   Freescale Copyright (C) 2006 All rights reserved
   ----------------------------------------------------------------------------
   $RCSfile: CTC_MAPDec.c.rca $
   Tag $Name:  $
   $Revision: 1.1 $
   $Date: Mon Jan 22 11:01:34 2007 $
   Target Processor: Matlab
============================================================================ */

#include <stdlib.h>
#include <math.h>
#include "Math_Funcs.c"
#include "mex.h"
#include "SBX_UPULSPK_CTC_MAPDec.c"
#include "prototype.c"

/* Input Arguments (not all might be used) */
#define	X1_IN	prhs[0]
#define	X2_IN	prhs[1]
#define	X3_IN	prhs[2]
#define	X4_IN	prhs[3]
#define	X5_IN	prhs[4]
#define	X6_IN	prhs[5]
#define	X7_IN	prhs[6]
#define	X8_IN	prhs[7]

/* Output Arguments (not all might be used) */
#define	Y1_OUT	plhs[0]
#define	Y2_OUT	plhs[1]
#define	Y3_OUT	plhs[2]
#define	Y4_OUT	plhs[3]
#define	Y5_OUT	plhs[4]
#define	Y6_OUT	plhs[5]
#define	Y7_OUT	plhs[6]
#define	Y8_OUT	plhs[7]
#define	Y9_OUT	plhs[8]
#define	Y10_OUT	plhs[9]

/*
  @brief    MAP Decoder main function : computes gammas, alphas, betas, extrinsic
            and a posteriori probabilities and updates a priori probbilities
                
 @param    pcInData         Pointer to input data
 @param    psiAprioriProb   Pointer to a priori probabilities
 @param    psiAposterProb   Pointer to a posteriori probabilities
 @param    psiAlpha         Pointer to alpha array
 @param    psiBeta          Pointer to beta array
 @param    psiGamma         Pointer to gamma array
 @param    usiLength        Length of input data (number of A,B,Y,W samples)
 
 
 signed long SBX_UPULSPK_CTC_MAPDec  (  signed char    *pcInData,
                                       signed short   *psiAprioriProb,
                                       signed short   *psiAposterProb,
                                       signed short   *psiAlpha,
                                       signed short   *psiBeta,
                                       signed short   *psiGamma,
                                       unsigned short usiLength
                                     )
{
 
 
    function [L_00, L_01, L_10, L_11, ln_p00, ln_p01, ln_p10, ln_p11, Alpha_out, Beta_out] = ...
    mCTC_MAPDec (rec_s, g, L_a_p00, L_a_p01, L_a_p10, L_a_p11, Alpha_in, Beta_in)
 
 rec_s      => double 1x960
 g          => not used
 L_a_p00    => double 1x240
 L_a_p01    => double 1x240
 L_a_p10    => double 1x240
 L_a_p11    => double 1x240
 Alpha_in   => double 1x8
 Beta_in    => double 1x8
 
 L_00      => double 1x240
 L_01      => double 1x240
 L_10      => double 1x240
 L_11      => double 1x240
 ln_p00    => double 1x240
 ln_p01    => double 1x240
 ln_p10    => double 1x240
 ln_p11    => double 1x240 
 Alpha_out  => double 1x8
 Beta_out   => double 1x8 
 
 */




void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
    
    /* Matlab input interface (not all might be used) */

    
    /*Matlab output interface (not all might be used) */
    double *temp_out1,*temp_out2,*temp_out3,*temp_out4,*temp_out5 ;
    double *temp_out6,*temp_out7,*temp_out8,*temp_out9,*temp_out10;
    
    /*C parameters */
    signed char    *pcInData;
    signed short   *psiAprioriProb;
    signed short   *psiAposterProb;
    signed short   *psiAlpha;
    signed short   *psiBeta;
    signed short   *psiGamma;
    unsigned short usiLength;
    
    
    /* Others */
    int i;
    double *temp1;
    double *temp2_00,*temp2_01,*temp2_10,*temp2_11;
    double *temp3;
    double *temp4;
    
    
    
    /* Matlab input dimensions (not all might be used) */
    unsigned long mx1,nx1;
    unsigned long mx3,nx3;
    unsigned long mx4,nx4;
    unsigned long mx5,nx5;
    unsigned long mx6,nx6;
    unsigned long mx7,nx7;
    unsigned long mx8,nx8;
    
    /* Matlab output dimensions (not all might be used) */
    unsigned long my1,ny1;
    unsigned long my2,ny2;
    unsigned long my3,ny3;
    unsigned long my4,ny4;
    unsigned long my5,ny5;
    unsigned long my6,ny6;
    unsigned long my7,ny7;
    unsigned long my8,ny8;
    unsigned long my9,ny9;
    unsigned long my10,ny10;
    
    
    /* Check for proper number of arguments */
    if (nlhs != 10)
    {mexErrMsgTxt("Error: 10 output arguments required.");    }
    if (nrhs != 8)
    {mexErrMsgTxt("Error: 8 input arguments required.");    }
    
    /* Check the input format */
    if ( (!mxIsDouble(X1_IN) || mxIsComplex(X1_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }
    

    
    if ( (!mxIsDouble(X3_IN) || mxIsComplex(X3_IN)   ) )
    { mexErrMsgTxt("Error: Input 3 data must be real of class 'double'."); }   
    if ( (!mxIsDouble(X4_IN) || mxIsComplex(X4_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }
    if ( (!mxIsDouble(X5_IN) || mxIsComplex(X5_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }
    if ( (!mxIsDouble(X6_IN) || mxIsComplex(X6_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }
    if ( (!mxIsDouble(X7_IN) || mxIsComplex(X7_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }
    if ( (!mxIsDouble(X8_IN) || mxIsComplex(X8_IN)   ) )
    { mexErrMsgTxt("Error: Input 1 data must be real of class 'double'."); }    
    
    /* get input dimensions (not all might be used) */
    mx1=mxGetM(X1_IN); nx1=mxGetN(X1_IN);
    mx3=mxGetM(X3_IN); nx3=mxGetN(X3_IN);
    mx4=mxGetM(X4_IN); nx4=mxGetN(X4_IN);
    mx5=mxGetM(X5_IN); nx5=mxGetN(X5_IN);
    mx6=mxGetM(X6_IN); nx6=mxGetN(X6_IN);
    mx7=mxGetM(X7_IN); nx7=mxGetN(X7_IN);
    mx8=mxGetM(X8_IN); nx8=mxGetN(X8_IN);
    
/*mexPrintf("test2 \n");*/

/*mexPrintf("mx1=%d, nx1=%d \n",mx1,nx1);
mexPrintf("mx3=%d, nx3=%d \n",mx3,nx3);
mexPrintf("mx4=%d, nx4=%d \n",mx4,nx4);
mexPrintf("mx5=%d, nx5=%d \n",mx5,nx5);
mexPrintf("mx6=%d, nx6=%d \n",mx6,nx6);
mexPrintf("mx7=%d, nx7=%d \n",mx7,nx7);
mexPrintf("mx7=%d, nx7=%d \n",mx8,nx8);*/

    /* Check arguments are col vectors */
    if ( mx1!=1 )
    { mexErrMsgTxt("Error: Input 1 data must be a col vector.");}
    if ( mx3!=1 )
    { mexErrMsgTxt("Error: Input 3 data must be a col vector.");}    
    if ( mx4!=1 )
    { mexErrMsgTxt("Error: Input 4 data must be a col vector.");}
    if ( mx5!=1 )
    { mexErrMsgTxt("Error: Input 5 data must be a col vector.");}    
    if ( mx6!=1 )
    { mexErrMsgTxt("Error: Input 6 data must be a col vector.");}
    if ( mx7!=1 )
    { mexErrMsgTxt("Error: Input 7 data must be a col vector.");}
    if ( mx8!=1 )
    { mexErrMsgTxt("Error: Input 8 data must be a col vector.");}
    
    /* Get data */ 
    /* pcInData */
    pcInData = mxMalloc(sizeof(signed char*)*mx1*nx1);
    temp1 = mxGetPr(X1_IN);
    for (i=0;i<nx1;i++){
        pcInData[i] = temp1[i];
        //mexPrintf("pcInData[%d]=%d \n",i,pcInData[i]);
    }

    /* psiAprioriProb */
    psiAprioriProb = mxMalloc(sizeof(signed short*)*mx3*nx3*4);
    temp2_00 = mxGetPr(X3_IN);
    temp2_01 = mxGetPr(X4_IN);
    temp2_10 = mxGetPr(X5_IN);
    temp2_11 = mxGetPr(X6_IN);
    for (i=0;i<nx3;i++){
        psiAprioriProb[4*i  ] = temp2_00[i];
        psiAprioriProb[4*i+1] = temp2_01[i];
        psiAprioriProb[4*i+2] = temp2_10[i];
        psiAprioriProb[4*i+3] = temp2_11[i];
        
        /*if (i==nx3-1) {
        mexPrintf("psiAprioriProb[%d]=%d \n",4*i  ,psiAprioriProb[4*i  ]);
        mexPrintf("psiAprioriProb[%d]=%d \n",4*i+1,psiAprioriProb[4*i+1]);
        mexPrintf("psiAprioriProb[%d]=%d \n",4*i+2,psiAprioriProb[4*i+2]);
        mexPrintf("psiAprioriProb[%d]=%d \n",4*i+3,psiAprioriProb[4*i+3]);}*/
    }

    /* psiAlpha */
    psiAlpha = mxMalloc(sizeof(signed short*)*mx7*nx7*(1+nx3));
    temp3 = mxGetPr(X7_IN);
    for (i=0;i<nx7;i++){
        psiAlpha[i  ] = temp3[i];
       /* mexPrintf("psiAlpha[%d]=%d \n",i,psiAlpha[i]);*/
    }
    
    /* psiBeta */
    psiBeta = mxMalloc(sizeof(signed short*)*mx8*nx8*(1+nx3));
    temp4 = mxGetPr(X8_IN);
    for (i=0;i<nx8;i++){
        psiBeta[nx8*nx3+i] = temp4[i];
       /* mexPrintf("psiBeta[%d]=%d \n",nx3+i,psiBeta[nx3+i]);*/
    }
    
    /* usiLength */
    usiLength = nx1/4 ;
    /*mexPrintf("usiLength = %d\n",usiLength); */
    
    /* psiAposterProb */
    psiAposterProb = mxMalloc(sizeof(signed short*)*mx3*nx3*4);
    
    /* psiGamma */
    psiGamma = mxMalloc(sizeof(signed short*)*mx3*nx3*8);
    
    
    /* Call to main function  */
    SBX_UPULSPK_CTC_MAPDec  (  pcInData,
                                       psiAprioriProb,
                                       psiAposterProb,
                                       psiAlpha,
                                       psiBeta,
                                       psiGamma,
                                       usiLength
                                     );
   

    /* Output collection */
    my1=1; ny1=nx3 ;
    my2=1; ny2=nx3 ;
    my3=1; ny3=nx3 ;
    my4=1; ny4=nx3 ;
    my5=1; ny5=nx3 ;
    my6=1; ny6=nx3 ;
    my7=1; ny7=nx3 ;
    my8=1; ny8=nx3 ;  
    Y1_OUT = mxCreateNumericMatrix(my1, ny1, mxDOUBLE_CLASS, mxREAL);
    Y2_OUT = mxCreateNumericMatrix(my2, ny2, mxDOUBLE_CLASS, mxREAL);
    Y3_OUT = mxCreateNumericMatrix(my3, ny3, mxDOUBLE_CLASS, mxREAL);
    Y4_OUT = mxCreateNumericMatrix(my4, ny4, mxDOUBLE_CLASS, mxREAL);
    Y5_OUT = mxCreateNumericMatrix(my5, ny5, mxDOUBLE_CLASS, mxREAL);
    Y6_OUT = mxCreateNumericMatrix(my6, ny6, mxDOUBLE_CLASS, mxREAL);
    Y7_OUT = mxCreateNumericMatrix(my7, ny7, mxDOUBLE_CLASS, mxREAL);
    Y8_OUT = mxCreateNumericMatrix(my8, ny8, mxDOUBLE_CLASS, mxREAL);
    my9=1; ny9=mx7*nx7 ;
    my10=1;ny10=mx7*nx7 ;     
    Y9_OUT = mxCreateNumericMatrix(my9, ny9, mxDOUBLE_CLASS, mxREAL);
    Y10_OUT= mxCreateNumericMatrix(my10,ny10,mxDOUBLE_CLASS, mxREAL);
    
    temp_out1 = (double*)mxGetPr(Y1_OUT);
    temp_out2 = (double*)mxGetPr(Y2_OUT);
    temp_out3 = (double*)mxGetPr(Y3_OUT);
    temp_out4 = (double*)mxGetPr(Y4_OUT);
    temp_out5 = (double*)mxGetPr(Y5_OUT);
    temp_out6 = (double*)mxGetPr(Y6_OUT);
    temp_out7 = (double*)mxGetPr(Y7_OUT);
    temp_out8 = (double*)mxGetPr(Y8_OUT);
    temp_out9 = (double*)mxGetPr(Y9_OUT);
    temp_out10 = (double*)mxGetPr(Y10_OUT);
    
    /* psiAprioriProb */
    for (i=0;i<ny1;i++){
        temp_out1[i] = (double)psiAposterProb[4*i  ] ;
        temp_out2[i] = (double)psiAposterProb[4*i+1] ;
        temp_out3[i] = (double)psiAposterProb[4*i+2] ;
        temp_out4[i] = (double)psiAposterProb[4*i+3] ;
        
        temp_out5[i] = (double)psiAprioriProb[4*i  ] ;
        temp_out6[i] = (double)psiAprioriProb[4*i+1] ;
        temp_out7[i] = (double)psiAprioriProb[4*i+2] ;
        temp_out8[i] = (double)psiAprioriProb[4*i+3] ;
        
        /*if ((i==ny1-1) || (i==ny1-2) ){
             mexPrintf("psiAposterProb[%d]=%d \n",4*i   ,psiAprioriProb[4*i   ]);
             mexPrintf("psiAposterProb[%d]=%d \n",4*i+1 ,psiAprioriProb[4*i+1 ]);
             mexPrintf("psiAposterProb[%d]=%d \n",4*i+2 ,psiAprioriProb[4*i+2 ]);
             mexPrintf("psiAposterProb[%d]=%d \n",4*i+3 ,psiAprioriProb[4*i+3 ]);
 
             mexPrintf("psiAprioriProb[%d]=%d \n",4*i   ,psiAprioriProb[4*i   ]);
             mexPrintf("psiAprioriProb[%d]=%d \n",4*i+1 ,psiAprioriProb[4*i+1 ]);
             mexPrintf("psiAprioriProb[%d]=%d \n",4*i+2 ,psiAprioriProb[4*i+2 ]);
             mexPrintf("psiAprioriProb[%d]=%d \n",4*i+3 ,psiAprioriProb[4*i+3 ]);         
        }*/
    }

    /* psiAlpha & psiBeta */
    for (i=0;i<ny9;i++){
        temp_out9[i]  = (double)psiAlpha[i+ ny9*(nx3)];   
        temp_out10[i] = (double)psiBeta[i];
    }
    
    
    return;
}









⌨️ 快捷键说明

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