📄 pn2.cpp
字号:
#include "stdlib.h"
#include "math.h"
#include "malloc.h"
#include "stdio.h"
#include "mex.h"
//int PNGen(int * p_RegStateI, int * p_RegStateQ,int * OutPNBufferI,int * OutPNBufferQ)
int PNGen( short int * OutPNBufferI,short int * OutPNBufferQ,short int order)
{
unsigned short int PN_PolynI=9;//[0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1]
unsigned short int PN_PolynQ=27;//[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1]
unsigned short int RegStateI = 16;
unsigned short int RegStateQ = 16;
int i,j;
int wy;
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|16;
n_Sum=0;
n_temp = RegStateQ & PN_PolynQ;
for(j=0; j<wy; j++)
{
n_Sum ^= ((n_temp>>j)&1);//( (n_temp&(1<<j))? 1:0);
}
OutPNBufferQ[i]=(RegStateQ&1)*2-1;
RegStateQ>>=1;
if(n_Sum) RegStateQ=RegStateQ|16;
}
//*p_RegStateI = RegStateI;
//*p_RegStateQ = RegStateQ;
return i;
}
/*
void main()
{
short int * OutPNBufferI, short int * OutPNBufferQ,i,j;
OutPNBufferI=(short int*)malloc(64);
OutPNBufferQ=(short int*)malloc(64);
i=PNGen(OutPNBufferI,OutPNBufferQ,5);
printf("%d ",i);
printf("\n");
printf("I:");
for(j=0; j<32-1; j++)
printf("%d ",OutPNBufferI[j]);
printf("\n");
printf("Q:");
for(j=0; j<32-1; j++)
printf("%d ",OutPNBufferQ[j]);
printf("\n");
}
*/
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -