📄 signal_process.h
字号:
#include "mfsk_data.h"
int dec_to_gf[16]; // globe parameters; store the gf_exp (see figure 1)
int p_vect[80]; // arrays for transforming form GF to Dec and Dec
int gf_to_dec[16]; // to GF. they initial in funciont initial().
int ss[6];
int g[6];
//int code[15];
int EncodeOut[15];
int RSout[24];
int CountMfsk=0; //mfsk编码次数
int pow_2(int j)
{ int i;
int pow2;
if(j==0)
pow2=1;
else
{ pow2=1;
for(i=1;i<=j;i++)
pow2=pow2*2;
}
return pow2;
}
void initial(int m) // when you want to use RS prog , this one must run first.
{
//生成函数 f(D)=D^3+D+1; GF(2^3)
// for different m there are different f(D).
int gd[8][5]={{0,1,3},{0,1,4},{0,2,5},{0,1,6},{0,3,7},{0,2,3,4,8},{0,4,9},{0,3,10}};
//本原多项式
int gd_len[8]={3,3,3,3,3,5,3,3};
int pow2=16;
int gf_vect[16],gf_exp[16]; // 用矢量表示。
int i,j;
int gf_temp[80]; // 存放多项式[000],按二进制表示。1表示此系数有=[pow2][m+1]
int h;
int sum;
int k;
// allocate the memory
// for example
// when m=3
// index = 0,1,2
// the gf_temp ={1,0,0
// 0,1,0
// 0,0,1
// 1,1,0
// ...}
//gf_temp=(int *)calloc(pow2*(m+1),sizeof(int));
//gf_vect=(int *)calloc(pow2,sizeof(int));
//gf_exp= (int *)calloc(pow2,sizeof(int));
// THE GF(2^3)
// gf_exp gf_temp
// ═══╤═══╤═════╤═══
// i │gf_exp│polynomial│vector
// ───┼───┼─────┼───
// 0 │ a^0 │ 1 │ 001
// 1 │ a^1 │ a │ 010
// 2 │ a^2 │ a^2 │ 100
// 3 │ a^3 │ a +1 │ 011
// 4 │ a^4 │ a^2 +a │ 110
// 5 │ a^5 │ a^2 +a+1 │ 111
// 6 │ a^6 │ a^2 +1 │ 101
// 7 │ a^7 │ 0 │ 000
// ═══╧═══╧═════╧═══
// figure 1
// there are the py's coefficient stored in gf_temp[][],for example
//if shi vecotor expression is [001] then gf_temp[][]={1,0,0,0}
// the gf_temp[][m+1] is to judge if the expression is exceed the
// GF(2^3), for an instance ,if the gf_temp[][]={0,0,0,1},this is
//to say that it is exceed the domain of GF, the max bit 1 should
//be replaced by 1+a, the program should to adjust this instance.
//becasue a^3=a+1(it is depended on the f(D)=D^3+D+1),so the gf_temp[][]
//={0,0,0,1} should be rewritted as gf_temp[][]={1,1,0,0};
// initial the array gf_temp.
gf_temp[0]=1;
for(j=1;j<4+1;j++)
{
gf_temp[j]=0;
}
for(i=1;i<pow2;i++)
{
gf_temp[4*i+0]=0;
// the LSB is initial to 0;
// then we left shift 1 bit.that is equal to multiply by 2
// the now value is equal to the last value mult by 2
// for example the last valuse is 010,the now value should be 100,
// all those are expressed by vector.
for (j=4+1;j>0;j--)
{
if (i!=pow2-1) gf_temp[4*i+j]=gf_temp[(i-1)*4+j-1];
else gf_temp[4*i+j]=0;
}
// just as tell above , when the value is exceed the GF domain
// we shoud adjust this value.
h=0;
if (gf_temp[4*i+4]==1)
{
for(k=0;k<4;k++)
{
if(k==gd[4-3][h] && h!=gd_len[4-3])
{
gf_temp[4*i+k]=(1+gf_temp[4*i+k]) % 2;
h++;
}
}
}
}
sum=0;
// now the importance process is completed
// this step is just to count the decimal value.
for(i=0;i<pow2;i++)
{
for (j=0;j<4;j++)
sum +=gf_temp[4*i+j]*pow_2(j);
gf_vect[i]=sum;
gf_exp[sum]=i;
if ( sum==0)
gf_exp[sum]=pow2-1;
sum=0;
}
for(i=0;i<16;i++)
dec_to_gf[i]=gf_exp[i];
for(i=0;i<80;i++)
p_vect[i]=gf_temp[i];
for(i=0;i<16;i++)
gf_to_dec[i]=gf_vect[i];
}
void Encode(int data[], int g[],int m ,int N,int L)
{
int i, j;
int a,GiMultInput;
// int shang1,shang2,shang3;
int R[6];
// int EncodeOut[15];
//int *R,*EncodeOut;
//R=(int *)calloc(N-L,sizeof(int)); // in form of exponent.a^(pow2-1)=000.
//EncodeOut=(int *)calloc(N,sizeof(int));
// initial the array R
for (i=0;i<N-L;i++)
R[i]=N;
for (j=0;j<L;j++)
{
a=AddInGf(R[N-L-1],data[j],m); // a^i +a ^j N+data[j]
//cout<<a<<endl;
for(i=N-L-1;i>0;i--)
{
// a^i * a^j = a^(i+j)
GiMultInput=MultInGf(g[i],a,N);
R[i]=AddInGf(GiMultInput ,R[i-1],m);
}
R[0]=MultInGf(g[0],a,N);
}
for(i=0;i<N;i++)
{
if (i<N-L)
EncodeOut[i]=R[i];
else
EncodeOut[i]=data[N-i-1];
}
for(i=3;i>=0;i--)
{
RSout[i]=(*(EncodeOut))%2;
(*(EncodeOut))=(*(EncodeOut))/2;
RSout[i+4]=(*(EncodeOut+1))%2;
(*(EncodeOut+1))=(*(EncodeOut+1))/2;
RSout[i+8]=(*(EncodeOut+2))%2;
(*(EncodeOut+2))=(*(EncodeOut+2))/2;
RSout[i+12]=(*(EncodeOut+3))%2;
(*(EncodeOut+3))=(*(EncodeOut+3))/2;
RSout[i+16]=(*(EncodeOut+13))%2;
(*(EncodeOut+13))=(*(EncodeOut+13))/2;
RSout[i+20]=(*(EncodeOut+14))%2;
(*(EncodeOut+14))=(*(EncodeOut+14))/2;
// RSout[k++]=EncodeOut[j]%2;
// shang1=EncodeOut[j]/2;
/// RSout[k++]=shang1%2;
// shang2=shang1/2;
// RSout[k++]=shang2%2;
// shang3=shang2/2;
// RSout[k++]=shang3%2;
}
}
int AddInGf(int TheDataWantToAddA,int TheDataWantToAddB,int m) //GF域的加法
{
int sumret[4];
int i;
//int pow2;
int sum=0;
//sumret=(int*)calloc(m,sizeof(int));
//pow2=pow(2,m);
for (i=0;i<m;i++)
{
sumret[i]=(p_vect[m*TheDataWantToAddA+i]+p_vect[TheDataWantToAddB*m+i]) % 2;
}
for (i=0;i<m;i++)
{
sum+=sumret[i]*pow_2(i);
}
return dec_to_gf[sum]; //dec_to_gf=gf_exp; gf_exp[sum]=i
}
int MultInGf(int dataA, int dataB, int N) // GF 域的乘法
{
int GiMultInput;
if (dataA!=N && dataB!=N)
GiMultInput=(dataA+dataB) % N; // a^i * a^j = a^(i+j)
else
GiMultInput=N;
return GiMultInput;
}
int DivInGf(int dataA,int dataB, int N /* N=2^m */)
{
int sign,result;
sign=dataA-dataB;
if(sign>=0)
result=sign;
else
result=N+sign;
return result;
}
void GenGx(int m,int N,int L) //generation polynomial.(m=4,N=15;L=9)
{
int d=N-L+1;
//int *gx=(int *)calloc((d-1)*2,sizeof(int));
int gx[14];
int Row=2;
//int *addtemp=(int *) calloc(d,sizeof(int));
int addtemp[7];
//int *multtemp=(int *) calloc(d,sizeof(int));
int multtemp[7];
//int *temp=(int *) calloc(d,sizeof(int));
int temp[7];
int i,j;
for (i=0;i<d-1 ;i++ ) //d
{
gx[Row*i]=i+1;
gx[Row*i+1]=0;
temp[i]=N;
}
temp[d-1]=N;
temp[0]=gx[0];
temp[1]=gx[1];
for(i=1;i<d-1;i++)
{
for(j=1;j<=d-1;j++) //(a+x)(a^2+x)=a(a^2+x)+x(a^2+x)
{
addtemp[j]=MultInGf(gx[Row*i],temp[j],N); ///a(a^2+x)
multtemp[j]=temp[j-1];
}
addtemp[0]=MultInGf(gx[Row*i],temp[0],N);
multtemp[0]=N;
for(j=0;j<=d-1;j++)
{
temp[j]=AddInGf(addtemp[j],multtemp[j],m);
}
}
//return temp;
for(i=0;i<7;i++)
g[i]=temp[i];
}
void CountSi(int R[], int m,int N /* N= 2^m-1*/,int t) // count the 伴随多项式 S(i)
{
int i,j;
int s[2];
for(j=0;j<2*t;j++)
{
s[0]=R[0];
for( i=1;i<N;i++)
{
s[1]=MultInGf(R[i],(i*(j+1))%N,N); //R[a^i]
s[1]=AddInGf(s[1],s[0],m);
s[0]=s[1];
}
ss[j]=s[1];
}
//return result;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -