📄 walsh.cpp
字号:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <iostream.h>
#define SF 4
int DSpreadCode[SF][SF];
void GENERATE_WALSH_SPREADCODE(void) /* Generate Walsh spreading sequences */
{
/* Purpose: Generate Walsh spreading sequences*/
/* Output parameters: DSpreadCode[SpreadTotle][SpreadTotle]*/
int k, x, y;
int k_length;
DSpreadCode[0][0] = 1;
// The define of Ik should according to the length of SpreadTotle
// It should statisfy that: pow(2, Ik) = SpreadTotle
k_length = (int)(log10(SF+0.5)/log10(2));
for(k = 1; k <= k_length; k++)
{
for(x = 0; x < (int)pow(2.0, k); x++)
{
for(y = 0; y < (int)pow(2.0, k); y++)
{
if (x < (int)(pow(2.0, k-1)))
{
if(y < (int)(pow(2.0, k-1))) {DSpreadCode[x][y] = DSpreadCode[x][y]; }
else {DSpreadCode[x][y] = DSpreadCode[x][y-(int)(pow(2.0, k-1))];}
}
else
{
if(y < (int)(pow(2.0, k-1))) {DSpreadCode[x][y] = DSpreadCode[x-(int)(pow(2.0, k-1))][y];}
else {DSpreadCode[x][y] = (-1) * DSpreadCode[x-(int)(pow(2.0, k-1))][y - (int)(pow(2.0, k-1))];}
}//if
}//y
}//x
}//k
}
void main()
{
int i, j;
GENERATE_WALSH_SPREADCODE();
for(i = 0; i < SF; i++) {
for(j = 0; j < SF; j++) {
printf("%d\t", DSpreadCode[i][j]);
}
printf("\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -