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

📄 realmultipath.c

📁 rake接收机matlab实现 完成相关接受的信道相关估计算法
💻 C
字号:
/*
 * realmutipath.c: Basic 'C' template for a level 2 S-function.
 *
 *  -------------------------------------------------------------------------
 *  | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
 *  -------------------------------------------------------------------------
 *
 * Copyright 1990-2002 The MathWorks, Inc.
 * $Revision: 1.27 $
 */

#define S_FUNCTION_NAME  realmultipath
#define S_FUNCTION_LEVEL 2

#include "simstruc.h"
#include <stdlib.h>
/*----------------------------------------------------------*/
/* 1st parameter: sample time */ 

#define SAMPLE_TIME_PARAM(S) ssGetSFcnParam(S,0)       

/*--------------------------------------------------------------*/
#define MDL_CHECK_PARAMETERS
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)

static void mdlCheckParameters(SimStruct *S)
  {
      /* Check the parameter: Sample Time parameter */
        real_T *pr;
        int_T   el;
        int_T   nEls;
	    if (	mxIsEmpty(    ssGetSFcnParam(S,0)) ||
              	mxIsComplex(  ssGetSFcnParam(S,0)) ||
              	!mxIsDouble(   ssGetSFcnParam(S,0)) )
			{
              		ssSetErrorStatus(S,"Parameters must be real number");
              		return;
          	}
		pr   = mxGetPr(ssGetSFcnParam(S,0));
        nEls = mxGetNumberOfElements(ssGetSFcnParam(S,0));
		for (el = 0; el < nEls; el++)
		{
           if (!mxIsFinite(pr[el])) 
				{
                  ssSetErrorStatus(S,"Parameters must be real finite number");
                  return;
				}
        }
       if (mxGetNumberOfElements(SAMPLE_TIME_PARAM(S)) != 1 || mxGetPr(SAMPLE_TIME_PARAM(S))[0] <= 0.0) 
		{
          ssSetErrorStatus(S,"Invalid sample time specified");
          return;
      	}		
}
#endif /* MDL_CHECK_PARAMETERS */


/*-----------------------------------------------------------------*/
static void mdlInitializeSizes(SimStruct *S)
{
    
    ssSetNumSFcnParams(S, 1);  /* Number of expected parameters */
    /*---------------------------------*/
    #if defined(MATLAB_MEX_FILE)
    	if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S))
	 {
        	mdlCheckParameters(S);
        	if (ssGetErrorStatus(S) != NULL) 
			{
           	 return;
       		 }
    } 
	else
		{
       		 return; /* Parameter mismatch will be reported by Simulink. */
		}
	#endif

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 1);

    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);

    
	ssSetInputPortDirectFeedThrough(S, 0, 0);


    if (!ssSetNumOutputPorts(S, 5)) return;
    ssSetOutputPortWidth(S, 0, 1);
	ssSetOutputPortWidth(S, 1, 1);
	ssSetOutputPortWidth(S, 2, 1);
	ssSetOutputPortWidth(S, 3, 1);
    ssSetOutputPortWidth(S, 4, 1);

    ssSetNumSampleTimes(S, 1);

    ssSetNumRWork(S, DYNAMICALLY_SIZED);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);
}


/*-----------------------------------------------------------*/
#if defined(MATLAB_MEX_FILE)
#define MDL_SET_WORK_WIDTHS
static void mdlSetWorkWidths(SimStruct*S)
{
	ssSetNumRWork(S,ssGetInputPortWidth(S,0));
	
}
#endif
/*---------------------------------------------------------*/

/*-----------------------------------------------*/
#if  defined(MATLAB_MEX_FILE)
#define MDL_SET_INPUT_PORT_WIDTH
static void mdlSetInputPortWidth(SimStruct*S,int_T port,int_T inputPortWidth)
{
    ssSetInputPortWidth(S,port,inputPortWidth);
}
#endif
/*-------------------------------------------------------------*/
#if  defined(MATLAB_MEX_FILE)
#define MDL_SET_OUTPUT_PORT_WIDTH
static void mdlSetOutputPortWidth(SimStruct*S,int_T port,int_T outputPortWidth)
{
	ssSetOutputPortWidth(S, 0, 1);
	ssSetOutputPortWidth(S, 1, 1);
	ssSetOutputPortWidth(S, 2, 1);
	ssSetOutputPortWidth(S, 3, 1);
	ssSetOutputPortWidth(S, 4, 1);

   
}
#endif

/*---------------------------------------------------------*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0,*mxGetPr(SAMPLE_TIME_PARAM(S)));
    ssSetOffsetTime(S, 0, 0.0);
     
}

/*-----------------------------------------------------------*/




/*----------------------------------------------------------------*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
	int_T		i;
	int_T		j;
	int_T		k;
	int_T       r;
    int_T		position[2];
    real_T		max[2]; 
    real_T		*y       = ssGetOutputPortRealSignal(S,0);
	real_T		*z       = ssGetOutputPortRealSignal(S,1);
	real_T		*v       = ssGetOutputPortRealSignal(S,2);
    real_T		*u       = ssGetOutputPortRealSignal(S,3);
	real_T      *noise   = ssGetOutputPortRealSignal(S,4);
	real_T      allpow ;  
	int_T		nx       = ssGetInputPortWidth(S,0); 
    real_T		*rwork   = ssGetRWork(S);   
	
    UNUSED_ARG(tid);
	max[0]       =*rwork;
	position[0]  =0;
	allpow      =0;

/*-------------------------------------------------------------------*/
	for(i=1;i<=(nx-1);i++)
	{  
		if(*(rwork+i)>max[0])
		{ 
			max[0]      =*(rwork+i);
            position[0] =i;
		}
	}
/*-----------------------------------------------------------------*/
	if((position[0]+2)<=(nx-1))
	{
        max[1]      =*(rwork+position[0]+2);
		position[1] =position[0]+2;
		for(j=position[0]+3;j<=(nx-1);j++)
		{
			if(*(rwork+j)>max[1])
			{
                 max[1]			=*(rwork+j);
				 position[1]	=j;
			}
		}
	}
    else
	{   
		max[1]			=*(rwork+position[0]-2);
		position[1]		=position[0]-2;	
	}
/*-------------------------------------------------------------------*/
	for(k=position[0]-2;k>=0;k--)
	{
		if(*(rwork+k)>max[1])
		{
		    max[1]		=*(rwork+k);
			position[1]	=k;
		}
	}
/*------------------------------------------------------------------*/
	for(r=0;r<=(nx-1);r++)
	{
		allpow+=*(rwork+r);
	}

    *y		=max[0];
	*z	    =position[0];
	*v		=max[1];
    *u		=position[1];
	*noise  =(allpow-max[0]-max[1])/(nx-2);
}


/*--------------------------------------------------------*/
#define MDL_UPDATE  /* Change to #undef to remove function */
#if defined(MDL_UPDATE)

  static void mdlUpdate(SimStruct *S, int_T tid)
  {
	  int_T					l;
	  InputRealPtrsType		uPtrs			=ssGetInputPortRealSignalPtrs(S,0);
	  int_T					nx				=ssGetInputPortWidth(S,0); 
	  real_T				*rwork			=ssGetRWork(S); 
	  UNUSED_ARG(tid);
     
	  for(l=0;l<=(nx-1);l++)
	  {
		  *(rwork+l)=*uPtrs[l];
	  }
  }
#endif /* MDL_UPDATE */
/*----------------------------------------------------------------------------------*/


#undef MDL_DERIVATIVES  /* Change to #undef to remove function */
#if defined(MDL_DERIVATIVES)
  /* Function: mdlDerivatives =================================================
   * Abstract:
   *    In this function, you compute the S-function block's derivatives.
   *    The derivatives are placed in the derivative vector, ssGetdX(S).
   */
  static void mdlDerivatives(SimStruct *S)
  {
  }
#endif /* MDL_DERIVATIVES */



/* Function: mdlTerminate =====================================================
 */
static void mdlTerminate(SimStruct *S)
{
}

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
#include "simulink.c"      /* MEX-file interface mechanism */
#else
#include "cg_sfun.h"       /* Code generation registration function */
#endif

⌨️ 快捷键说明

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