⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 awgn.cpp

📁 有关卷积编码的维特比算法,是硬判决的啊,希望大家
💻 CPP
字号:
#include "AWGN.h"

AWGN::AWGN()
{

}

AWGN::~AWGN()
{

}
	
void AWGN::attn(double *ich,double *qch,int ebn0,double factor1,int factor2,int count,double &attn)
{
	//------------attenuation calculation------------------------
	double spow,temp1,temp2,attn1;
	spow=0;
	attn1=0;

	for(i=0;i<count;i++)
	{	
		temp1=ich[i];
		temp2=qch[i];
		spow=spow+(pow(temp1,2)+pow(temp2,2));
	}

	spow=spow/count*factor1;//factor1:code rate
	//cout<<"spow:"<<spow<<endl;
	attn1=0.5*spow*(1.0/factor2)*pow(10,-ebn0/10.0);//1.0/2(modulation level)//factor2:modulation rate
	attn=sqrt(attn1);
	//cout<<"attn:"<<attn<<endl;
}

void AWGN::aw(double *ich,double *qch,int count,double &attn)
{
	//cout<<attn<<endl;
	//-------------AWGN noise add--------------------------------
	for (i=0; i<count; i++)
	{
		*(ich+i)=*(ich+i)+(Rand()*attn);	
		*(qch+i)=*(qch+i)+(Rand()*attn);
	}
}


//---------------randn-------------------------------------------
void AWGN::Rnd521(void)
{
	int i;
	for (i=0;i<32;i++) x1[i] ^=x1[i+489];
	for (i=32;i<521;i++) x1[i] ^=x1[i-32];
}

void AWGN::InitRnd(unsigned long seed)              /* initize random number */
{
	int i,j;
	unsigned long u;

	u=0;
	for (i=0;i<=16;i++){
		for (j=0;j<32;j++){
			seed=seed*(unsigned long)1566083941+1;
			u=(u>>1)|(seed & ((unsigned long)1 <<31));
		}
		x1[i]=u;
	}
	x1[16]=M32(x1[16]<<23)^(x1[0]>>9)^x1[15];
	for (i=17;i<=520;i++)
		x1[i]=M32(x1[i-17]<<23)^(x1[i-16]>>9)^x1[i-1];
	Rnd521();
	Rnd521();
	Rnd521();
	jrnd =520;
}

unsigned long AWGN::iRnd(void)
{
	if (++jrnd >=521) {Rnd521();jrnd=0; }
	return x1[jrnd];
}

double AWGN::UniRnd(void)                       /* Uniform random number */
{
	return (1.0/((((unsigned long) 1 << 32)-1)+1.0))*iRnd();
}

double AWGN::Rand(void)                      /* Gaussian random number */
{
	static int sw=0;
	static double r1, r2, s;

	if (sw==0) {
		sw=1;
		do {
			r1 = 2*UniRnd()-1;
			r2 = 2*UniRnd()-1;
			s=r1*r1 + r2*r2;
		}while ( s>1 || s==0);
		s=sqrt(-2*log(s)/s);
		return r1*s;
	}
	else{
		sw=0;
		return r2*s;
	}
		
}


int AWGN::SeqGen(void)
{
		if(UniRnd()>0.5)
			return (1);
		else
			return (-1);
}
//---------------------the end------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -