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

📄 syncusingpil.cpp

📁 数字音频广播中的同步算法在pc上的实现 主要运用了导频、最大似然估计等算法结合
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************\ * Technische Universitaet Darmstadt, Institut fuer Nachrichtentechnik * Copyright (c) 2001 * * Author(s): *	Volker Fischer * * Description: *	Frame synchronization (Using time-pilots), frequency sync tracking * ****************************************************************************** * * 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 "SyncUsingPil.h"/* Implementation *************************************************************/void CSyncUsingPil::ProcessDataInternal(CParameter& ReceiverParam){	int i;	/**************************************************************************\	* Frame synchronization detection										   *	\**************************************************************************/	_BOOLEAN bSymbolIDHasChanged = FALSE;	if ((bSyncInput == FALSE) && (bAquisition == TRUE))	{#ifdef USE_DRM_FRAME_SYNC_IR_BASED		/* DRM frame synchronization using impulse response ----------------- */		/* We assume that the current received OFDM symbol is the first symbol		   in a DRM frame and estimate the channel transfer function at the		   pilot positions (the positions of pilots in the first OFDM symbol in		   a DRM frame). Then we calculate an FFT to get the impulse response of		   the channel. If the assumption was correct and this really was the		   correct OFDM symbol, we will get something which looks like an		   impulse response (contains peaks -> peak-to-average ratio is high).		   If not, we will certainly get only noise -> no peaks -> peak to		   average ratio is small. This is because the transmitted values at		   the pilot positions are different from the values at the pilot cells		   when transmitting the correct OFDM symbol (which we assumed) */		/* Pick pilot positions and calculate "test" channel estimation */		int iCurIndex = 0;		for (i = 0; i < iNumCarrier; i++)		{			if (_IsScatPil(ReceiverParam.matiMapTab[0][i]))			{				/* Get channel estimate */				veccChan[iCurIndex] =					(*pvecInputData)[i] / ReceiverParam.matcPilotCells[0][i];				/* We have to introduce a new index because not on all carriers				   is a pilot */				iCurIndex++;			}		}		/* Calculate abs(IFFT) for getting estimate of impulse response */		vecrTestImpResp = Abs(Ifft(veccChan, FftPlan));		/* Calculate peak to average */		const CReal rResultIREst = Max(vecrTestImpResp) / Sum(vecrTestImpResp);		/* Store correlation results in a shift register for finding the peak */		vecrCorrHistory.AddEnd(rResultIREst);#else		/* DRM frame synchronization based on time pilots ------------------- */		/* Calculate correlation of received cells with pilot pairs */		CReal rResultPilPairCorr = (CReal) 0.0;		for (i = 0; i < iNumPilPairs; i++)		{			/* Actual correlation */			const CComplex cCorrRes = (*pvecInputData)[vecPilCorr[i].iIdx1] *				Conj(vecPilCorr[i].cPil1) *				Conj((*pvecInputData)[vecPilCorr[i].iIdx2]) *				vecPilCorr[i].cPil2 * cR_HH;			rResultPilPairCorr += Real(cCorrRes);		}		/* Store correlation results in a shift register for finding the peak */		vecrCorrHistory.AddEnd(rResultPilPairCorr);#endif		/* Finding beginning of DRM frame in results ------------------------ */		/* Wait until history is filled completly */		if (iInitCntFraSy > 0)			iInitCntFraSy--;		else		{			/* Search for maximum */			int iMaxIndex = 0;			CReal rMaxValue = -_MAXREAL;			for (i = 0; i < iNumSymPerFrame; i++)			{				if (vecrCorrHistory[i] > rMaxValue)				{					rMaxValue = vecrCorrHistory[i];					iMaxIndex = i;				}			}			/* For initial frame synchronization, use maximum directly */			if (bInitFrameSync == TRUE)			{				/* Reset init flag */				bInitFrameSync = FALSE;				/* Set symbol ID index according to received data */				iSymbCntFraSy = iNumSymPerFrame - iMaxIndex - 1;			}			else			{				/* If maximum is in the middle of the interval				   (check frame sync) */				if (iMaxIndex == iMiddleOfInterval)				{					if (iSymbCntFraSy == iNumSymPerFrame - iMiddleOfInterval - 1)					{						/* Reset flags */						bBadFrameSync = FALSE;						bFrameSyncWasOK = TRUE;						/* Post Message for GUI (Good frame sync) */						PostWinMessage(MS_FRAME_SYNC, 0); /* green */					}					else					{						if (bBadFrameSync == TRUE)						{							/* Reset symbol ID index according to received							   data */							iSymbCntFraSy =								iNumSymPerFrame - iMiddleOfInterval - 1;							/* Inform that symbol ID has changed */							bSymbolIDHasChanged = TRUE;							/* Reset flag */							bBadFrameSync = FALSE;							PostWinMessage(MS_FRAME_SYNC, 2); /* red */						}						else						{							/* One false detected frame sync should not reset							   the actual frame sync because the measurement							   could be wrong. Sometimes the frame sync							   detection gets false results. If the next time							   the frame sync is still unequal to the							   measurement, then correct it */							bBadFrameSync = TRUE;							if (bFrameSyncWasOK == TRUE)							{								/* Post Message that frame sync was wrong but								   was not yet corrected (yellow light) */								PostWinMessage(MS_FRAME_SYNC, 1); /* yellow */							}							else								PostWinMessage(MS_FRAME_SYNC, 2); /* red */						}						/* Set flag for bad sync */						bFrameSyncWasOK = FALSE;					}				}			}		}	}	else	{		/* Frame synchronization has successfully finished, show always green		   light */		PostWinMessage(MS_FRAME_SYNC, 0);	}	/* Set current symbol ID and flag in extended data of output vector */	(*pvecOutputData).GetExData().iSymbolID = iSymbCntFraSy;	(*pvecOutputData).GetExData().bSymbolIDHasChanged = bSymbolIDHasChanged;	/* Increase symbol counter and take care of wrap around */	iSymbCntFraSy++;	if (iSymbCntFraSy >= iNumSymPerFrame)		iSymbCntFraSy = 0;	/**************************************************************************\	* Using Frequency pilot information										   *	\**************************************************************************/	if ((bSyncInput == FALSE) && (bTrackPil == TRUE))	{		CComplex cFreqOffEstVecSym = CComplex((CReal) 0.0, (CReal) 0.0);		for (i = 0; i < NUM_FREQ_PILOTS; i++)		{			/* The old pilots must be rotated due to timing corrections */			const CComplex cOldFreqPilCorr =				Rotate(cOldFreqPil[i], iPosFreqPil[i],				(*pvecInputData).GetExData().iCurTimeCorr);			/* Calculate the inner product of the sum */			const CComplex cCurPilMult =				(*pvecInputData)[iPosFreqPil[i]] * Conj(cOldFreqPilCorr);			/* Save "old" frequency pilots for next symbol. Special treatment			   for robustness mode D (carriers 7 and 21) necessary 			   (See 8.4.2.2) */// TODO: take care of initialization phase: do not start using estimates until// the first "old pilots" were stored. Also, an "initial frequecy offset// estimate" should be made and rFreqOffsetTrack should be set to this value!			if ((ReceiverParam.GetWaveMode() == RM_ROBUSTNESS_MODE_D) &&				(i < 2))			{				cOldFreqPil[i] = -(*pvecInputData)[iPosFreqPil[i]];			}			else				cOldFreqPil[i] = (*pvecInputData)[iPosFreqPil[i]];#ifdef USE_SAMOFFS_TRACK_FRE_PIL			/* Get phase difference for sample rate offset estimation. Average			   the vector, real and imaginary part separately */			IIR1(cFreqPilotPhDiff[i], cCurPilMult, rLamSamRaOff);#endif			/* Calculate estimation of frequency offset */			cFreqOffEstVecSym += cCurPilMult;		}		/* Frequency offset ------------------------------------------------- */		/* Correct frequency offset estimation for resample offset corrections.		   When a sample rate offset correction was applied, the frequency		   offset is shifted proportional to this correction. The correction

⌨️ 快捷键说明

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