#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int *spreadspectrum(int *string_spreadspectrum)
{
int *pi = (int *)malloc(384*sizeof(int));
int *pq = (int *)malloc(384*sizeof(int));
int *pi_ss = (int *)malloc((384*64)*sizeof(int)); //WALSH调制后 I信道
int *pq_ss = (int *)malloc((384*64)*sizeof(int)); //WALSH调制后 Q信道
int scode_i_generator[15]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //短码发生器初始值I
int scode_q_generator[15]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //短码发生器初始值Q
int *pn_i =(int *)malloc(384*64*sizeof(int)); //生成的短码 I
int *pn_q =(int *)malloc(384*64*sizeof(int)); //生成的短码 Q
static int string_afterss[384*64*2]; //前半为I后半为Q
int walsh[64]={1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1,
1,1,1,1,-1,-1,-1,-1};
int i=0;
int j=0;
int k=0;
int a=0;
for(i=0;i<=383;i++)
{
*(pi+i)=*(string_spreadspectrum+i);
}
for(i=0;i<=383;i++)
{
*(pq+i)=*(string_spreadspectrum+384+i);
}
for(i=0;i<=383;i++) //I-chip
{
for(j=0;j<=63;j++)
{
*(pi_ss+64*i+j)=*(pi+i) * walsh[j];
}
}
for(i=0;i<=383;i++) //Q-chip
{
for(j=0;j<=63;j++)
{
*(pq_ss+64*i+j)=*(pq+i) * walsh[j];
}
}
for(i=0;i<=768*32-1;i++) //I信道的短PN码
{
*(pn_i+i)=scode_i_generator[14]; //生成短码
a=scode_i_generator[14]; //寄存器移位
for(j=14;j>=1;j--)
{
scode_i_generator[j]=scode_i_generator[j-1];
}
scode_i_generator[0]=a;
for(j=0;j<=14;j++)
{
if(j==5||j==7||j==8||j==9||j==13) //多项式所包含项
{
scode_i_generator[j]=scode_i_generator[j]^a;
}
//多项式不包含项
}
}
for(i=0;i<=768*32-1;i++) //Q信道的短PN码
{
*(pn_q+i)=scode_q_generator[14]; //生成短码
a=scode_q_generator[14]; //寄存器移位
for(j=14;j>=1;j--)
{
scode_q_generator[j]=scode_q_generator[j-1];
}
scode_q_generator[0]=a;
for(j=0;j<=14;j++)
{
if(j==3||j==4||j==5||j==6||j==10||j==11||j==12) //多项式所包含项
{
scode_q_generator[j]=scode_q_generator[j]^a;
}
//多项式不包含项
}
}
for(i=0;i<=768*32-1;i++) //短码进行符号映射 I
{
if(*(pn_i+i)==0)
{
*(pn_i+i)=1;
}
else
{
*(pn_i+i)=-1;
}
}
for(i=0;i<=768*32-1;i++) // 短码进行符号映射 Q
{
if(*(pn_q+i)==0)
{
*(pn_q+i)=1;
}
else
{
*(pn_q+i)=-1;
}
}
for(i=0;i<=768*32-1;i++) // 复加扰
{
string_afterss[i]=*(pn_i+i) * *(pi_ss+i) - *(pn_q+i) * *(pq_ss+i);
string_afterss[i+768*32]=*(pn_q+i) * *(pi_ss+i) + *(pn_i+i) * *(pq_ss+i);
}
return (string_afterss);
}
void main()
{
int string[768]={1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,1,1,0,0,1,1,0,1,1,1,
1,0,1,1,0,0,1,1,0,1,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