📄 msequence.cpp
字号:
#include <math.h>
#include <complex>
using namespace std;
#ifndef PI
#define PI 3.1415926535897932
#endif
double PeriodAutoCorrelation(int sequence[],int length,int t)
{
int i;
double x;
x=0;
for (i=0;i<length;i++)
{
x=x+sequence[i]*sequence[(i+t)%length];
}
x=x/length;
return x;
}
double AperiodAutoCorrelation(int sequence[],int length,int t)
{
int i;
double x;
x=0;
for (i=0;i<length-t;i++)
{
x=x+sequence[i]*sequence[i+t];
}
x=x/length;
return x;
}
complex<double> PeriodAutoCorrelation(complex<double> sequence[],int length,int t)
{
int i;
complex<double> x,length1;
x=complex<double>(0.0,0.0);
for (i=0;i<length;i++)
{
x=x+sequence[i]*conj(sequence[(i+t)%length]);
}
length1=complex<double>(length,0);
x=x/length1;
return x;
}
complex<double> AperiodAutoCorrelation(complex<double> sequence[],int length,int t)
{
int i;
complex<double> x,length1;
x=complex<double>(0.0,0.0);
for (i=0;i<length-t;i++)
{
x=x+sequence[i]*conj(sequence[i+t]);
}
length1=complex<double>(length,0);
x=x/length1;
return x;
}
double distance(complex<double> x,complex<double> y)
{
double a,b,c;
a=x.real()-y.real();
b=x.imag()-y.imag();
c=sqrt(a*a+b*b);
return c;
}
complex<double> map(int x)
{
complex<double> y;
if (x==0) y=complex<double> (0.0,0.0);
if (x==1) y=complex<double> (1.0,0.0);
if ((x==2)||(x==3)) y=complex<double> (polar(1.0,2*PI*(x-1)/3));
return y;
}
int InverseMap(complex<double> c)
{
int x;
if (c==complex<double> (0.0,0.0)) x=0;
if (c==complex<double> (1.0,0.0)) x=1;
if (c==complex<double> (polar(1.0,2*PI/3))) x=2;
if (c==complex<double> (polar(1.0,4*PI/3))) x=3;
return x;
}
complex<double> plastic(complex<double> x)
{
int i;
double d;
complex<double> a[10],y;
a[0]=complex<double> (0.0,0.0);
a[1]=complex<double> (1.0,0.0);
a[2]=complex<double> (polar(1.0,2*PI/3));
a[3]=complex<double> (polar(1.0,4*PI/3));
a[4]=complex<double> (-1.0,0.0);
a[5]=complex<double> (polar(1.0,PI/3));
a[6]=complex<double> (polar(1.0,-PI/3));
a[7]=complex<double> (2.0,0.0);
a[8]=complex<double> (polar(2.0,2*PI/3));
a[9]=complex<double> (polar(2.0,4*PI/3));
for (i=0;i<4;i++)
{
d=distance(x,a[i]);
if (d<0.001)
y=a[i];
}
d=distance(x,a[4]);
if (d<0.001) y=a[1];
d=distance(x,a[5]);
if (d<0.001) y=a[3];
d=distance(x,a[6]);
if (d<0.001) y=a[2];
d=fabs(abs(x)-2);
if (d<0.001) y=a[0];
return y;
}
int convert(int a)
{
int b;
switch (a)
{
case 5: b=0;
break;
case 7: b=1;
break;
case 11: b=2;
break;
case 13: b=3;
break;
case 17: b=4;
break;
case 19: b=5;
break;
case 23: b=6;
break;
case 29: b=7;
break;
case 31: b=8;
break;
default : b=0;
}
return b;
}
void mSequence(int p,int m,int sequence[])
{
int i,j,k,mSeqLength,mPrimitive[3][101][101],mPrimitive1[9][9][9];
//double x;
complex<double> complex1,ComplexPrimitive[101],ComplexSequence[1000],SequenceMapping[1000];
//Initialization-the coefficients of primitive polynomials(2-4)
for (i=0;i<=2;i++)
for (j=0;j<=100;j++)
for (k=0;k<=100;k++)
mPrimitive[i][j][k]=0;
//the coefficients of primitive polynomials(binary)
for (i=1;i<=100;i++)
{mPrimitive[0][i][0]=1;
mPrimitive[0][i][i]=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -