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

📄 chanawgn.cpp

📁 这个是数据打孔重传程序的源代码
💻 CPP
字号:
/**********************************************/
/* AWGN
/* struct Complex * ChanAwgnF(struct BasicParaS * ctrl, struct Complex * input, double Eb_No_dB)
/*      Written by: Ouyang Ziyue,
/*            Date: Jun 12th, 2007,
/*        Function: It generates the AWGN and adds it to the symbols
/* Input parameter:
/*        The length of symbols is included in the ctrl,
/*        The input includes all the input complex symbols,
/*        The Eb_No_dB is used to define the SNR or Eb/No.
/* Output parameter:
/*        An COMPLEX set which consists all the modulation symbols added with noise is outputed
/* Note:
/*        ctrl should be built before this function is called,
/*        The AWGN samples are generated according to Box-Muller Transform.
/**********************************************/

#include "parameter_sets.h"

const double sqrt2 = 1.414213562373095; //From Matlab 2006R

int ChanAwgnF(struct BasicParaS * ctrl, struct Complex * input, double Eb_No_dB)
{
	//////////////////////////////////////////////////////////////////////////
	//Declaration
	double sigma,sigma2;
	int i;
	
	//////////////////////////////////////////////////////////////////////////
	//Insert the Gauss Channel here
	if (ctrl->noiseMode == 0)		// Eb/No
	{
			if(ctrl->typeModu == 0){
			sigma = 1/sqrt(2*pow(10.0,(Eb_No_dB/10))/ctrl->r);
		}	else if(ctrl->typeModu == 1){
			sigma = 1/sqrt(2*pow(10.0,(Eb_No_dB/10))*2/ctrl->r);
		}	else if(ctrl->typeModu == 2){
			sigma = 1/sqrt(2*pow(10.0,(Eb_No_dB/10))*4/ctrl->r);
		}	else if(ctrl->typeModu == 3){
			sigma = 1/sqrt(2*pow(10.0,(Eb_No_dB/10))*6/ctrl->r);
		}
	}
	else							// SNR
			sigma = sqrt(pow(10.0,(-Eb_No_dB/10))/2);


	sigma2 = sigma*sigma;
	for (i=0; i<ctrl->numModuOut; i++)
	{
		if (ctrl->typeModu == 0)
		{
			//(*(input+i)).real += 0;
			(*(input+i)).real += AWGN(sigma2);
		}
		else
		{
			(*(input+i)).real += AWGN(sigma2);
			(*(input+i)).imag += AWGN(sigma2);
		}
	}

	//////////////////////////////////////////////////////////////////////////
	//DEBUG
#ifdef DEBUG
	printf("The symbols undergo the AWGN ... \n");
	int temp = 0;
	for (i=0; i<ctrl->numModuOut; i++)
	{
		printf("%.3f+j%.3f\t ", (*(input+i)).real, (*(input+i)).imag);
		temp++;
		if (temp == 4)
		{
			printf("\n");
			temp=0;
		}

	}
#endif

	return 0;
}

⌨️ 快捷键说明

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