chanawgn.cpp

来自「这是校验位打孔重传的源程序」· C++ 代码 · 共 49 行

CPP
49
字号
#include "parameter_sets.h"
#include "wuzhanji_random.h"

const double MAX = RAND_MAX;
const double Pi = 3.141592653589793; //From Matlab 2006R
const double sqrt2 = 1.414213562373095; //From Matlab 2006R

struct Complex * ChanAwgnF(struct BasicParaS * ctrl, struct Complex * input, double Eb_No_dB) 
{

	// insert the Gauss channel here ..
	int i, temp;

	double sigma,sigma2;
	
	if (ctrl->noiseMode == 0) { // Eb/No
		sigma = 1/sqrt(ctrl->r*pow(10.0, Eb_No_dB/10));
	} else { // SNR
		sigma = 1/(2* pow(10.0, -Eb_No_dB/10));
	}

    sigma2=sigma*sigma;
	for (i=0; i<ctrl->numSymOut; i++) {
		// Using Box-Muller Transform
		if (ctrl->typeModu == 0)
			(*(input+i)).real += AWGN(sigma2);
		else {
			(*(input+i)).real += AWGN(sigma2)/sqrt2;
			(*(input+i)).imag += AWGN(sigma2)/sqrt2;
		}
	}

	temp = 0;

	if (ctrl->mode == 1) {
		printf("The symbols undergo the AWGN ..\n");
		temp = 0;
		for (i=0; i<ctrl->numSymOut; i++) {
			printf(" %.3f+j%.3f", (*(input+i)).real, (*(input+i)).imag);
			temp++;
			if (temp == 4) {
				printf("\n");
				temp = 0;
			}
		}
	}

	return input;
}

⌨️ 快捷键说明

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