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

📄 walshgen.c

📁 walsh和pn码的生成程序
💻 C
字号:
/***********************************************************************/
/* To Generate the arbitrary row of WALSH matrix of arbitrary order!   */
/* 				                                                       */
/* 	Input Parameters:								                   */
/* 	1st   Order, the order of the WALSH Matrix;			               */
/* 	2nd   Index, the index of row in the WALSH Matrix;                 */
/* 				                                                       */
/* 	Output Parameters:                                                 */
/* 	the corresponding Index-th row of the WALSH Matrix.                */
/* 				                                                       */
/* 	Programed by HuaHan, 2003                                          */
/* 				                                                       */
/***********************************************************************/



#include "stdlib.h"
#include "math.h"
#include "malloc.h"
#include "mex.h"

int walsh_gen(double* OutWhash, int order, int index)
{
	int i, j;
	int nOrderLength;
	int sign;

	OutWhash[0] = 1;
	for(i=0; i<order; i++)
	{
		nOrderLength = 1<<i;
		sign = ( (index & nOrderLength)==0 )? 1:-1;
		for(j=0; j<nOrderLength; j++)
		{
			OutWhash[nOrderLength+j] = sign*OutWhash[j];
		}
	}

	return nOrderLength<<1;
}


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	/* input parameters */
	int Order;
	int	Index;
	

	/* output parameters */
	double *OutReal;

	/* local data */
	int outlength;
	
	
	/* Check for the proper number of arguments */
	if ( nrhs != 2 )
		mexErrMsgTxt("Incorrect number of inputs. ");
	if ( nlhs != 1)
		mexErrMsgTxt("Incorrect number of outputs. ");

	/* check to make sure the input argument is a scalar */
	if( !mxIsDouble(prhs[0]) || mxGetN(prhs[0])*mxGetM(prhs[0])!=1 )
	{
		mexErrMsgTxt("Input Order must be a scalar.");
	}
 	if( !mxIsDouble(prhs[1]) || mxGetN(prhs[1])*mxGetM(prhs[1])!=1 )
	{
		mexErrMsgTxt("Input Index must be a scalar.");
	}
 
	/* Get the input parameters */
	Order = (int)mxGetScalar(prhs[0]);
	Index = (int)mxGetScalar(prhs[1]);

	outlength = 1<<Order;

    /* Create  matrix for the return argument */ 
	plhs[0] = mxCreateDoubleMatrix(1, outlength, mxREAL);
	/* Assign pointers to the various parameters */ 
	OutReal = mxGetPr(plhs[0]);

	walsh_gen(OutReal, Order, Index);	
}

⌨️ 快捷键说明

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