?? kasami2.cpp
字號:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main ()
{
clrscr();
int b0[1025],c[17],q[1048],d[1025],e[1047],ln,x,y,z,w,s,r,t,u,v,v1,v2,x1,x2,x3,x4,x6;
cout<<"enter the length of shift register ";
cin>>ln;
cout<<"enter the initial state of shift register ";
for(x=0;x<ln;x++)
{
cin>>d[x];
}
cout<<"enter the cof. of genetator polynomial in asending order ";
for(z=0;z<ln;z++)
{
cin>> c[z];
}
cout<<"generated m-sequence is " <<endl;
v=pow(2,ln)-1;
for(t=0;t<v;t++)
{ s=0;
for(w=0;w<ln;w++)
{
s=s+c[w]*d[w];
}
e[t]=d[ln-1];
for(u=ln;u>0;u--)
{
d[u]=d[u-1];
}
r=s%2;
d[0]=r;
cout<<e[t];
}
getch();
cout<<endl;
cout<<endl;
//cout<<"\n2nd time printing";
for(t=0;t<v;t++)
{
cout<<e[t];
}
v1=pow(2,(ln/2))+1;
cout<<endl;
cout<<v1;
v2=v/v1;
cout<<endl;
cout<<v2;
cout<<endl;
getch();
cout<<"q sequence is "<<endl;
cout<<endl;
for(x1=0,x6=0;x1<v;x1=x1+v1,x6++)
{
q[x6]=e[x1];
cout<<q[x6]<<" ";
}
cout<<endl;
int i1,i2,h,p,g[31][1048],g1[1048],q1;
cout<<endl;
cout<<"b sequence is "<<endl<<endl;
for(i1=0;i1<v;i1=i1+v2)
{ for(i2=0;i2<v2;i2++)
{ b0[i1+i2]=q[i2];
cout<<b0[i1+i2];
}
// cout<<endl;
}
cout<<endl;
/*kasami code generation */
for(t=0;t<v;t++)
{
g1[t]=(e[t]+b0[t])%2;
}
cout<<endl;
cout<<"kasami code generated by m-seq and b seq "<<endl<<endl;
for(p=0;p<v;p++)
{
cout<<g1[p];
}
cout<<endl;
/*for generation of shifted kasami code */
cout<<"shifted kasami codes generated are"<<endl;
int v5=pow(2,(ln/2))-1;
cout<<v5<<endl;
for(x4=0;x4<v5;x4++)
{
z=b0[v-1];
for(q1=v;q1>0;q1--)
{
b0[q1]=b0[q1-1];
}
b0[0]=z;
for(h=0;h<v;h++)
{
g[x4][h]=(e[h]+b0[h])%2;
}
for(p=0;p<v;p++)
{
cout<<g[x4][p];
}
cout<<endl;
}
int b[65][127],i,j,k,n,l,ns,m,x7;
cout<<"enter the number of bit to be assigned to TH ";
cin>>n;
x4=v-(v%n);
for(m=0,x7=0;m<v5;m++,x7++)
{
cout<<"user no" <<m+1<<" is tranamitting in time slots ";
for(j=0,k=0;j<x4;j=j+n,k++)
{ b[m][k]=0;
for(i=n-1,l=0;i>=0;i--,l++)
{
b[m][k]=b[m][k]+pow(2,l)*g[m][i+j];
}
cout<<b[m][k]<<" ";
}
cout<<endl;
if(x7>20)
{ getch();
x7=0;
}
}
/*for counting max no of user tx in all the slot*/
int b1[127],j1,k1,max,x5,b2[127];
/*cout<<"enter the sequence";
for(i=0;i<8;i++)
{
cin>>a[i];
}*/
x5=(x4/n);
for(x6=0;x6<x5;x6++)
{
for(j1=0;j1<v5;j1++)
{ k1=0;
for(i1=0;i1<v5;i1++)
{
if(b[j1][x6]==b[i1][x6])
{
k1++;
}
}
b1[j1]=k1;
}
max=0;
for(j1=0;j1<v5-1;j1++)
{
if(max<b1[j1])
{ max=b1[j1];
}
}
b2[x6]=max;
}
//cout<<"max no "<<max<<endl;
for(j=0;j<x5;j++)
{
cout<<b2[j];
}
max=0;
for(j1=0;j1<x5;j1++)
{
if(max<b2[j1])
{ max=b2[j1];
}
}
cout<<endl;
//cout<<"max no of user that can tx simultaneously in a time slot"<<max;
cout<<max;
getch();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -