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

📄 cellmappingtable.cpp

📁 Dream.exe soft source (Visual C++)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************\
 * Technische Universitaet Darmstadt, Institut fuer Nachrichtentechnik
 * Copyright (c) 2001
 *
 * Author(s):
 *	Volker Fischer
 *
 * Description:
 *	Table of the mapping of OFDM cells.
 *	We build a table of one super-frame where we set flags for each cell to
 *	identify the symbol for this place. E.g. if the flag "CM_MSC" is set for
 *	one table entry this is the cell for a MSC-symbol. The name of the table
 *	is matiMapTab.
 *	We use the table "matcPilotCells" for storing the complex values for the
 *	pilots. For simplicity we allocate memory for all blocks but only the
 *	pilot positions are used.
 *
 ******************************************************************************
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
\******************************************************************************/

#include "../GlobalDefinitions.h"
#include "CellMappingTable.h"


/* Implementation *************************************************************/
void CCellMappingTable::MakeTable(ERobMode eNewRobustnessMode,
								  ESpecOcc eNewSpectOccup)
{
	int				iNoMSCDummyCells; /* Number of MSC dummy cells */
	int				iNumTimePilots; /* Number of time pilots per frame */
	CScatPilots		ScatPilots;
	int				iSym;
	int				iFrameSym;
	int				iCar;
	int				iTimePilotsCounter;
	int				iFreqPilotsCounter;
	int				iScatPilotsCounter;
	int				iFACCounter;
	int				iScatPilPhase;
	int				iCarArrInd;
	int				iSpecOccArrayIndex;
	/* Tables */
	const int*		piTableFAC;
	const int*		piTableTimePilots;
	const int*		piTableFreqPilots;


	/* Set Parameters and pointers to the tables ******************************/
	switch (eNewSpectOccup)
	{
	case SO_0:
		iSpecOccArrayIndex = 0;
		break;

	case SO_1:
		iSpecOccArrayIndex = 1;
		break;

	case SO_2:
		iSpecOccArrayIndex = 2;
		break;

	case SO_3:
		iSpecOccArrayIndex = 3;
		break;

	case SO_4:
		iSpecOccArrayIndex = 4;
		break;

	case SO_5:
		iSpecOccArrayIndex = 5;
		break;
	}

	/* The robust mode defines all other parameters */
	switch (eNewRobustnessMode)
	{
	case RM_ROBUSTNESS_MODE_A:
		iCarrierKmin = iTableCarrierKmin[iSpecOccArrayIndex][0];
		iCarrierKmax = iTableCarrierKmax[iSpecOccArrayIndex][0];
		
		iFFTSizeN = RMA_FFT_SIZE_N;
		RatioTgTu.iEnum = RMA_ENUM_TG_TU;
		RatioTgTu.iDenom = RMA_DENOM_TG_TU;

		iNumSymPerFrame = RMA_NUM_SYM_PER_FRAME;
		iNumSymbolsPerSuperframe = iNumSymPerFrame * NUM_FRAMES_IN_SUPERFRAME;
		piTableFAC = &iTableFACRobModA[0][0];
		iNumTimePilots = RMA_NUM_TIME_PIL;
		piTableTimePilots = &iTableTimePilRobModA[0][0];
		piTableFreqPilots = &iTableFreqPilRobModA[0][0];
		iScatPilTimeInt = RMA_SCAT_PIL_TIME_INT;
		iScatPilFreqInt = RMA_SCAT_PIL_FREQ_INT;

		/* Scattered pilots phase definition */
		ScatPilots.piConst = iTableScatPilConstRobModA;
		ScatPilots.iColSizeWZ = SIZE_COL_WZ_ROB_MOD_A;
		ScatPilots.piW = &iScatPilWRobModA[0][0];
		ScatPilots.piZ = &iScatPilZRobModA[0][0];
		ScatPilots.iQ = iScatPilQRobModA;

		ScatPilots.piGainTable = &iScatPilGainRobModA[iSpecOccArrayIndex][0];
		break;

	case RM_ROBUSTNESS_MODE_B:
		iCarrierKmin = iTableCarrierKmin[iSpecOccArrayIndex][1];
		iCarrierKmax = iTableCarrierKmax[iSpecOccArrayIndex][1];

		iFFTSizeN = RMB_FFT_SIZE_N;
		RatioTgTu.iEnum = RMB_ENUM_TG_TU;
		RatioTgTu.iDenom = RMB_DENOM_TG_TU;

		iNumSymPerFrame = RMB_NUM_SYM_PER_FRAME;
		iNumSymbolsPerSuperframe = iNumSymPerFrame * NUM_FRAMES_IN_SUPERFRAME;
		piTableFAC = &iTableFACRobModB[0][0];
		iNumTimePilots = RMB_NUM_TIME_PIL;
		piTableTimePilots = &iTableTimePilRobModB[0][0];
		piTableFreqPilots = &iTableFreqPilRobModB[0][0];
		iScatPilTimeInt = RMB_SCAT_PIL_TIME_INT;
		iScatPilFreqInt = RMB_SCAT_PIL_FREQ_INT;

		/* Scattered pilots phase definition */
		ScatPilots.piConst = iTableScatPilConstRobModB;
		ScatPilots.iColSizeWZ = SIZE_COL_WZ_ROB_MOD_B;
		ScatPilots.piW = &iScatPilWRobModB[0][0];
		ScatPilots.piZ = &iScatPilZRobModB[0][0];
		ScatPilots.iQ = iScatPilQRobModB;

		ScatPilots.piGainTable = &iScatPilGainRobModB[iSpecOccArrayIndex][0];
		break;

	case RM_ROBUSTNESS_MODE_C:
		iCarrierKmin = iTableCarrierKmin[iSpecOccArrayIndex][2];
		iCarrierKmax = iTableCarrierKmax[iSpecOccArrayIndex][2];

		iFFTSizeN = RMC_FFT_SIZE_N;
		RatioTgTu.iEnum = RMC_ENUM_TG_TU;
		RatioTgTu.iDenom = RMC_DENOM_TG_TU;

		iNumSymPerFrame = RMC_NUM_SYM_PER_FRAME;
		iNumSymbolsPerSuperframe = iNumSymPerFrame * NUM_FRAMES_IN_SUPERFRAME;
		piTableFAC = &iTableFACRobModC[0][0];
		iNumTimePilots = RMC_NUM_TIME_PIL;
		piTableTimePilots = &iTableTimePilRobModC[0][0];
		piTableFreqPilots = &iTableFreqPilRobModC[0][0];
		iScatPilTimeInt = RMC_SCAT_PIL_TIME_INT;
		iScatPilFreqInt = RMC_SCAT_PIL_FREQ_INT;

		/* Scattered pilots phase definition */
		ScatPilots.piConst = iTableScatPilConstRobModC;
		ScatPilots.iColSizeWZ = SIZE_COL_WZ_ROB_MOD_C;
		ScatPilots.piW = &iScatPilWRobModC[0][0];
		ScatPilots.piZ = &iScatPilZRobModC[0][0];
		ScatPilots.iQ = iScatPilQRobModC;

		ScatPilots.piGainTable = &iScatPilGainRobModC[iSpecOccArrayIndex][0];
		break;

	case RM_ROBUSTNESS_MODE_D:
		iCarrierKmin = iTableCarrierKmin[iSpecOccArrayIndex][3];
		iCarrierKmax = iTableCarrierKmax[iSpecOccArrayIndex][3];

		iFFTSizeN = RMD_FFT_SIZE_N;
		RatioTgTu.iEnum = RMD_ENUM_TG_TU;
		RatioTgTu.iDenom = RMD_DENOM_TG_TU;

		iNumSymPerFrame = RMD_NUM_SYM_PER_FRAME;
		iNumSymbolsPerSuperframe = iNumSymPerFrame * NUM_FRAMES_IN_SUPERFRAME;
		piTableFAC = &iTableFACRobModD[0][0];
		iNumTimePilots = RMD_NUM_TIME_PIL;
		piTableTimePilots = &iTableTimePilRobModD[0][0];
		piTableFreqPilots = &iTableFreqPilRobModD[0][0];
		iScatPilTimeInt = RMD_SCAT_PIL_TIME_INT;
		iScatPilFreqInt = RMD_SCAT_PIL_FREQ_INT;

		/* Scattered pilots phase definition */
		ScatPilots.piConst = iTableScatPilConstRobModD;
		ScatPilots.iColSizeWZ = SIZE_COL_WZ_ROB_MOD_D;
		ScatPilots.piW = &iScatPilWRobModD[0][0];
		ScatPilots.piZ = &iScatPilZRobModD[0][0];
		ScatPilots.iQ = iScatPilQRobModD;

		ScatPilots.piGainTable = &iScatPilGainRobModD[iSpecOccArrayIndex][0];
		break;
	}

	/* Get number of carriers with DC */
	iNumCarrier = iCarrierKmax - iCarrierKmin + 1;

	/* Length of guard-interval measured in "time-bins". We do the calculation
	   with integer variables -> "/ RatioTgTu.iDenom" MUST be the last
	   operation! */
	iGuardSize = iFFTSizeN * RatioTgTu.iEnum / RatioTgTu.iDenom;

	/* Symbol block size is the guard-interval plus the useful part */
	iSymbolBlockSize = iFFTSizeN + iGuardSize;

	/* Calculate the index of the DC carrier in the shifted spectrum */
	iIndexDCFreq = (int) ((_REAL) VIRTUAL_INTERMED_FREQ *
		iFFTSizeN / SOUNDCRD_SAMPLE_RATE);

	/* Index of minimum useful carrier (shifted) */
	iShiftedKmin = iIndexDCFreq + iCarrierKmin;

	/* Index. of maximum useful carrier (shifted) */
	iShiftedKmax = iIndexDCFreq + iCarrierKmax;

	/* Calculate number of time-interploated frequency pilots. Special case
	   with robustness mode D: pilots in all carriers! BUT: DC carrier is
	   counted as a pilot in that case!!! Be aware of that! */
	if (iScatPilFreqInt > 1)
		iNumIntpFreqPil = (int) ((_REAL) iNumCarrier / iScatPilFreqInt + 1);
	else
		iNumIntpFreqPil = iNumCarrier;


	/* Allocate memory for vectors and matrices ----------------------------- */
	/* Allocate memory for mapping table (Matrix) */
	matiMapTab.Init(iNumSymbolsPerSuperframe, iNumCarrier);

	/* Allocate memory for pilot cells definition and set it to zero */
	matcPilotCells.Init(iNumSymbolsPerSuperframe, iNumCarrier,
		_COMPLEX((_REAL) 0.0, (_REAL) 0.0));

	/* Allocate memory for vectors with number of certain cells */
	veciNumMSCSym.Init(iNumSymbolsPerSuperframe);
	veciNumFACSym.Init(iNumSymbolsPerSuperframe);
	veciNumSDCSym.Init(iNumSymbolsPerSuperframe);


	/* Build table ************************************************************/
	/* Some of the definitions at the beginning are overwritten by successive
	   definitions! E.g., first define all carriers as MSC cells */
	iFreqPilotsCounter = 0;
	iTimePilotsCounter = 0;
	for (iSym = 0; iSym < iNumSymbolsPerSuperframe; iSym++)
	{
		/* Frame symbol: Counts symbols in one frame, not super frame! */
		iFrameSym = iSym % iNumSymPerFrame;

		/* Reset FAC counter at the beginning of each new frame */
		if (iFrameSym == 0)
			iFACCounter = 0;

		/* Calculate the start value of "p" in equation for gain reference
		   cells in Table 90 (8.4.4.1) */
		iScatPilotsCounter = (int) ((_REAL) (iCarrierKmin -
			(int) ((_REAL) iScatPilFreqInt / 2 + .5) -
			iScatPilFreqInt * mod(iFrameSym, iScatPilTimeInt)
			) / (iScatPilFreqInt * iScatPilTimeInt));

		for (iCar = iCarrierKmin; iCar < iCarrierKmax + 1; iCar++)
		{
			/* Set carrier array index (since we do not have negative indices
			   in c++) */
			iCarArrInd = iCar - iCarrierKmin;


			/* MSC ---------------------------------------------------------- */
			/* First set all cells to MSC-cells */
			matiMapTab[iSym][iCarArrInd] = CM_MSC;


			/* SDC ---------------------------------------------------------- */
			/* No MSC-cells in the first two (or three) symbols -> SDC */
			switch (eNewRobustnessMode)
			{
			case RM_ROBUSTNESS_MODE_A:
			case RM_ROBUSTNESS_MODE_B:
				if ((iSym == 0) || (iSym == 1))
					matiMapTab[iSym][iCarArrInd] = CM_SDC;
				break;

			case RM_ROBUSTNESS_MODE_C:
			case RM_ROBUSTNESS_MODE_D:
				if ((iSym == 0) || (iSym == 1) || (iSym == 2))
					matiMapTab[iSym][iCarArrInd] = CM_SDC;
				break;
			}


			/* FAC ---------------------------------------------------------- */
			/* FAC positions are defined in a table */
			if (iFACCounter < NUM_FAC_CELLS)
			{
				/* piTableFAC[x * 2]: first column; piTableFAC[x * 2 + 1]:
				   second column */
				if (piTableFAC[iFACCounter * 2] * iNumCarrier +
					piTableFAC[iFACCounter * 2 + 1] == iFrameSym *
					iNumCarrier + iCar)
				{
					iFACCounter++;
					matiMapTab[iSym][iCarArrInd] = CM_FAC;
				}
			}


			/* Scattered pilots --------------------------------------------- */
			/* Standard: 8.4.4.3:
			   "In some cases gain references fall in locations which coincide
			   with those already defined for either frequency or time
			   references. In these cases, the phase definitions given in
			   clauses 8.4.2 and 8.4.3 take precedence."
			   Therefore, Scattered pilots must be definded FIRST here! */

			/* The rule for calculating the scattered pilots is defined in the
			   specification in the following form:
			   e.g.: k = 2 + 4 * (s mod 5) + 20 * p
			   We define a "frequency-" (FreqInt) and "time-interpolation"
			   (TimeInt). In this example, "4" is the FreqInt and "5" is the
			   TimeInt. The first term "2" is the half of the FreqInt, rounded
			   towards infinity. The parameter "20" is FreqInt * TimeInt */
			if (iCar == (int) ((_REAL) iScatPilFreqInt / 2 + .5) +
				iScatPilFreqInt * mod(iFrameSym, iScatPilTimeInt) +
				iScatPilFreqInt * iScatPilTimeInt * iScatPilotsCounter)
			{
				iScatPilotsCounter++;

				/* Set flag in mapping table */
				matiMapTab[iSym][iCarArrInd] = CM_SCAT_PI;

				/* Set complex value for this pilot */
				/* Phase calculation ---------------------------------------- */
				int in, im, ip, i;

				/* Calculations as in drm-standard (8.4.4.3.1) */
				/* "in" is ROW index and "im" is COLUMN index! */
				in = mod(iFrameSym, ScatPilots.piConst[1] /* "y" */);
				im = (int)
					((_REAL) iFrameSym / ScatPilots.piConst[1] /* "y" */);
				ip = (int) ((_REAL) (iCar - ScatPilots.piConst[2] /* "k_0" */ -
					in * ScatPilots.piConst[0] /* "x" */) / (
					ScatPilots.piConst[0] /* "x" */ *
					ScatPilots.piConst[1] /* "y" */));

				/* Phase_1024[s,k] =
				   (4Z_256[n,m]pW_1024[n,m] + p^2(1 + s)Q_1024) mod 1024 */
				iScatPilPhase = mod(4 * ScatPilots.piZ[in *
					ScatPilots.iColSizeWZ + im] + ip *
					ScatPilots.piW[in *
					ScatPilots.iColSizeWZ + im] +

⌨️ 快捷键说明

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