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

📄 demodulating.cpp

📁 这是校验位打孔重传的源程序
💻 CPP
字号:
#include "parameter_sets.h"

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

	double * output = new double[ctrl->codeN];
	double currentI, currentQ;
	double temp[6];
	double inv_sigma2;
	int i, j;

	// Set the parameter about the noise
	if (ctrl->noiseMode == 0) 
	{
		inv_sigma2 = ctrl->r*pow(10.0, Eb_No_dB/10);
	} else 
	{
		inv_sigma2 = pow(10.0, Eb_No_dB/10);
	}

	switch (ctrl->typeDecode) 
	{
	case 0: // SPA
		switch (ctrl->typeModu) 
		{
		case 0: // BPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+i) = 1/(1+exp(2*inv_sigma2*currentI)); // the probability of 1
			}
			break;
		case 1: // QPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+2*i) = 1/(1+exp(4*inv_sigma2*currentI));
				*(output+2*i+1) = 1/(1+exp(4*inv_sigma2*currentQ));
			}
			break;
		case 2: // 16QAM
			printf("SPA is not supported in 16QAM!\n");
			exit(EXIT_FAILURE);
			break;
		case 3: // 64QAM
			printf("SPA is not supported in 64QAM!\n");
			exit(EXIT_FAILURE);
			break;
		default: // unsupported modulation types
			exit(EXIT_FAILURE);
		}
		break;
	case 1: // LSPA
		switch (ctrl->typeModu) 
		{
		case 0: // BPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+i) = 2*currentI*inv_sigma2; // the logarithm of probability of 0/1
			}
			break;
		case 1: // QPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+2*i) = 4*currentI*inv_sigma2;
				*(output+2*i+1) = 4*currentQ*inv_sigma2;
			}
			break;
		case 2: // 16QAM
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				if (MaxLogDeMap(0, 2, currentI, temp) != 0)
					exit(EXIT_FAILURE);
				if (MaxLogDeMap(2, 2, currentQ, temp) != 0)
					exit(EXIT_FAILURE);
				for (j=0; j<ctrl->bitsPerSym; j++) 
				{
					*(output+ctrl->bitsPerSym*i+j) = *(temp+j);
				}
			}
			break;
		case 3: // 64QAM
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				if (MaxLogDeMap(0, 3, currentI, temp) != 0)
					exit(EXIT_FAILURE);
				if (MaxLogDeMap(2, 3, currentQ, temp) != 0)
					exit(EXIT_FAILURE);
				for (j=0; j<ctrl->bitsPerSym; j++) 
				{
					*(output+ctrl->bitsPerSym*i+j) = *(temp+j);
				}
			}
			break;
		default: // unsupported modulation types
			exit(EXIT_FAILURE);
		}
		break;
	case 2: // MSA
		switch (ctrl->typeModu) 
		{
		case 0 : // BPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+i) = 2*currentI*inv_sigma2;
			}
			break;
		case 1: // QPSK
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				// calculate the soft output
				*(output+2*i) = 4*currentI*inv_sigma2;
				*(output+2*i+1) = 4*currentQ*inv_sigma2;
			}
			break;
		case 2: // 16QAM
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				if (MaxLogDeMap(0, 2, currentI, temp) != 0)
					exit(EXIT_FAILURE);
				if (MaxLogDeMap(2, 2, currentQ, temp) != 0)
					exit(EXIT_FAILURE);
				for (j=0; j<ctrl->bitsPerSym; j++) 
				{
					*(output+ctrl->bitsPerSym*i+j) = *(temp+j);
				}
			}
			break;
		case 3: // 64QAM
			for (i=0; i<ctrl->numSymOut; i++) 
			{
				currentI = (*(input+i)).real;
				currentQ = (*(input+i)).imag;
				if (MaxLogDeMap(0, 3, currentI, temp) != 0)
					exit(EXIT_FAILURE);
				if (MaxLogDeMap(2, 3, currentQ, temp) != 0)
					exit(EXIT_FAILURE);
				for (j=0; j<ctrl->bitsPerSym; j++) 
				{
					*(output+ctrl->bitsPerSym*i+j) = *(temp+j);
				}
			}
			break;
		default: // unsupported modulation types
			exit(EXIT_FAILURE);
		}
		break;
	default: // unsupported decoding algorithms
		exit(EXIT_FAILURE);
	}

	return output;
}

⌨️ 快捷键说明

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