📄 razzaq.cpp
字号:
#include <stdlib.h>
#include <math.h>
#include <stdlib.h>
#include <fstream.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
double gengauss(double);
const int sz=100000;
double pi=3.14;
void main()
{
double Gg1,P,r0,r1,N=sz, Gg2,R0c, R0s,r11c,r11s;
int i,j,Es=1,k,Ang=0,Ero=0,decision;
int decod[sz];
double snr,sg,gssn,G=1.0;
ofstream outfile("C:\\data.txt");
for(j=1;j<=15;j=j+1)
{
snr=pow(10.0,(j/10.0));
sg=sqrt(Es/(2.0*snr));
for(k=1;k<=N;k++)
{gssn=(double)rand()/(RAND_MAX+1); if(gssn<0.5) decod[k]=0; else decod[k]=1;
}
int Ero=0;
for (k=1;k<=N;k++)
{
if (decod[k]==0) { Gg1=G*cos(Ang); Gg2=G*sin(Ang); R0c=sqrt(Es)*Gg1+gengauss(sg);
R0s=sqrt(Es)*Gg2+gengauss(sg);
r11c=gengauss(sg);
r11s=gengauss(sg);
}
else
{
Gg1=G*cos(Ang); Gg2=G*sin(Ang); R0c=gengauss(sg); R0s=gengauss(sg);
r11c=sqrt(Es)*Gg1+gengauss(sg);
r11s=sqrt(Es)*Gg2+gengauss(sg);
}
r0=pow(R0c,2)+pow(R0s,2); r1=pow(r11c,2)+pow(r11s,2);
if (r0>r1) decision=0;
else
decision=1;
if (decision!=decod[k])
{ Ero=Ero+1; }
} P=Ero/N;
}double SNR=0.0,Theo=0.0,l=1.0; for(l=1;l<=15;l=l+1)
{
snr=pow(10.0,(l/10.0));
sg=sqrt(2*Es/snr);
Theo=(1/(2+(2*(sg*snr))));
cout<<snr<<"\t"<<Theo<<endl;
outfile<<l<<"\t"<<Theo<<endl;
}
cout<<"\n\n\t"<<"Simulation Complete"<<endl;
getche();
}
double gengauss(double sig)
{
double gn1,gn2,u,z; u=(double)rand()/(RAND_MAX+1); z=sig*(sqrt(2*log(1/(1-u))));u=(double)rand()/(RAND_MAX+1);
gn1=z*cos(2*pi*u);
gn2=z*sin(2*pi*u);
return gn1, gn2 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -