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

📄 pn.cpp

📁 walsh和pn码的生成程序
💻 CPP
字号:
#include "stdlib.h"
#include "math.h"
#include "malloc.h"
#include "stdio.h"
#include "mex.h"

int PNGen(short int * OutPNBufferI, short int * OutPNBufferQ,short int order)
//int PNGen(short int * OutPNBufferI,short int order)
{
//short int * OutPNBufferQ;

unsigned short int PN_PolynI=021641; //[0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1]  
unsigned short int PN_PolynQ=016171; //[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1]
unsigned short int RegStateI = 1;
unsigned short int RegStateQ = 1;

int wy;
int i,j;
unsigned short int n_Sum=0;
unsigned short int n_temp=0;
if((!RegStateI)||(!RegStateQ))
{
puts("PNGen: All zeros register state is NOT allowed!");
exit(0);
}

wy=order;
for(i=0; i<(1<<wy)-1; i++)
{
n_Sum=0;
n_temp = RegStateI & PN_PolynI;
for(j=0; j<wy; j++)
{
n_Sum ^= ((n_temp>>j)&1);
}
OutPNBufferI[i]=(RegStateI&1)*2-1;
RegStateI>>=1;
if(n_Sum) RegStateI = RegStateI | 040000;


n_Sum=0;
n_temp = RegStateQ & PN_PolynQ;
for(j=0; j<wy; j++)
{
n_Sum ^= ((n_temp>>j)&1);
}
OutPNBufferQ[i]=(RegStateQ&1)*2-1;
RegStateQ>>=1;
if(n_Sum) RegStateQ = RegStateQ | 040000;
}

return i;
}


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

	/* output parameters */
	short int * OutPNBufferI;
    short int * OutPNBufferQ;

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

	/* check to make sure the input argument is a scalar */
	
 
	/* Get the input parameters */
	order= (short int)mxGetScalar(prhs[0]);



    /* Create  matrix for the return argument */ 
	plhs[0] = mxCreateNumericMatrix(1, (1<<order)-1,mxINT16_CLASS, mxREAL);
    plhs[1] = mxCreateNumericMatrix(1, (1<<order)-1,mxINT16_CLASS, mxREAL);
	
	/* Assign pointers to the various parameters */ 
	OutPNBufferI = (short int*)mxGetPr(plhs[0]);
	OutPNBufferQ = (short int*)mxGetPr(plhs[1]);

//	PNGen(OutPNBufferI,order);
	PNGen(OutPNBufferI,OutPNBufferQ,order);	
}


/*
void main()
{
  short int * OutPNBufferI,short int * OutPNBufferQ,j;
  OutPNBufferI=(short int*)malloc(1024*64);
  OutPNBufferQ=(short int*)malloc(1024*64);
  PNGen(OutPNBufferI,OutPNBufferQ);
  printf("I信道:"); 
  for(j=0; j<1024*32-1; j++)
    printf("%d  ",OutPNBufferI[j]);
  printf("\n"); printf("\n");printf("\n");
 printf("Q信道:");
  for(j=0; j<1024*32-1; j++)
    printf("%d  ",OutPNBufferQ[j]);
  printf("\n"); 
}*/

⌨️ 快捷键说明

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