亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? viterbi.c

?? DSP 5409 plc應用程序,調試通過,是用在電力線通訊上的演示程序.
?? C
字號:
/*================================================================================
Filename:			viterbi.c

 Description:		Mex function call for data transmittion part of model of  
					power line modem.

 Copyright (C) 2002 - 2003 Texas Instruments Incorporated
 Texas Instruments Proprietary Information
 Use subject to terms and conditions of TI Software License Agreement

 Revision History:
========================================================================*/
#include "ofdm_modem.h"


/*==============================================================
	global vars for this module
===============================================================*/
struct 
{
	u16				*pUserData;
	u16				encodeState;
	u16				inWord;
	i16				bitCount;
}	viterbiEnc;

struct 
{
	u32				*pState0Memory;
	u16				*pUserData;
	u16				outWord;
	i16				outWordBitCount;
	i16				symbolCount;
	iCplx			prevCarrier1;
}	pathMem;

MetricType		pathMetricA[VITERBI_NUM_STATES];
MetricType		pathMetricB[VITERBI_NUM_STATES];
u32				pathMemoryA[VITERBI_NUM_STATES];
u32				pathMemoryB[VITERBI_NUM_STATES];



/*==============================================================
	Init the global structure of state variables for the Viterbi Encoder
===============================================================*/
void viterbiEncodeInit(u16 *pUserData)
{
	viterbiEnc.encodeState = 0;
	viterbiEnc.pUserData = pUserData;
	viterbiEnc.inWord = *viterbiEnc.pUserData++;
	viterbiEnc.bitCount = WORD_LEN; 
	return;
}


/*==============================================================
	Viterbi Encoder for PLC modem
	Uses a K=7 convolutional code with two outputs for each bit input.  
	The two bit outputs returned in the real part of array symbols.
	
            +---+---+---+-----------+---y1
            |   |   |   |           |
	inbits -->D-->D-->D-->D-->D-->D-- 
           0|  1   2|  3|  4   5|  6|
            |       |   |       |   |
            +-------+---+-------+---+---y0

	The function returns pointer to the next user data bits.
===============================================================*/
void viterbiEncodeFrame(iCplx *symbols)
{
	i16				symCount = 0;
	u16				bit;

	for( symCount = 0; symCount < CARRIER_LEN; symCount++ )
	{
		bit = (viterbiEnc.inWord & WORD_MSB) >> WORD_LEN-VITERBI_K;		// shift >> 9
		viterbiEnc.inWord <<= 1;
		viterbiEnc.encodeState = bit + (viterbiEnc.encodeState >> 1 );
		(symbols++)->re = ViterbiEncodeLookup[viterbiEnc.encodeState];

		viterbiEnc.bitCount--;
		if( viterbiEnc.bitCount <= 0 )
		{
			viterbiEnc.inWord = *viterbiEnc.pUserData++;
			viterbiEnc.bitCount = WORD_LEN;
		}
	}
	return;
}


/*====================================================================
	init path memory and path metric structure for Soft Viterbi trellis
=====================================================================*/
void initPathMemory( u16 *pUserData )
{
	i16				state;						// trellis state
	MetricType		*currPathMetric;
	MetricType		*prevPathMetric;
	u32				*currPathMemory;
	u32				*prevPathMemory;

	//---- reset path metric and memory -----------------------
	currPathMetric = pathMetricA;
	prevPathMetric = pathMetricB;
	currPathMemory = pathMemoryA;
	prevPathMemory = pathMemoryB;
	for( state = 0; state < VITERBI_NUM_STATES;  state++ )
	{
		*currPathMetric++ = METRIC_OFFSET;
		*prevPathMetric++ = METRIC_OFFSET;
		*currPathMemory++ = 0;
		*prevPathMemory++ = 0;
	}
	
	//---- initialize Viterbi decode state variables -----------------------
	pathMem.pUserData = pUserData;
	pathMem.pState0Memory = NULL;
	pathMem.outWord = 0;
	pathMem.outWordBitCount = -(VITERBI_MEM_LEN+VITERBI_K-2);
	pathMem.symbolCount = 0;
	//pathMem.prevCarrier1.re = VITERBI_CAR1_RE;	// init for first carrier
	//pathMem.prevCarrier1.im = VITERBI_CAR1_IM;

	return;
}


/*====================================================================
	State Loop
=====================================================================*/
u32 *viterbiStateLoop( MetricType *dist, i16 symbolCount )
{

	i16					state;						// trellis state
	MetricType			metric0, metric1;			// working path metric
	MetricType			d0, d1;						//
	MetricType			*d0Ptr, *d1Ptr;
	static MetricType	distance[4];				//
	const i16			*decodePtr;
	
	MetricType			*currPathMetric;
	MetricType			*prevPathMetric;

	u32					*currPathMemory;
	u32					*prevPathMemory;
	u32 				*state0Memory;

			
	if( symbolCount & 0x01 )	// alternate, odd/even,  between the
	{							// two path memory buffers
		state0Memory   = pathMemoryB;
		currPathMemory = pathMemoryB;
		prevPathMemory = pathMemoryA;

		currPathMetric = pathMetricB;
		prevPathMetric = pathMetricA;
	}
	else
	{
		state0Memory   = pathMemoryA;
		currPathMemory = pathMemoryA;
		prevPathMemory = pathMemoryB;

		currPathMetric = pathMetricA;
		prevPathMetric = pathMetricB;
	}

	//---- retrieve the distance metrics------------------------------------
	distance[0] = *dist;
	distance[2] = -(*dist++);
	distance[1] = *dist;
	distance[3] = -(*dist);

	#if DEBUGIT == DEBUG_DISTANCE
		*diag.r++ = (double)distance[0];
		*diag.r++ = (double)distance[1];
	#endif

	decodePtr = decodeTable;	// reset the table that chooses the correct
								// distance metric for each branch

	/*--------------------------------------------------------------------
	Now cycle through each state in the trellis.  For each state select the 
	best branch from a previous state based on the distance metric. 
	Two previous states and two current states share branches and so are done
	at the same time.  Assign the cumulative metric and memory from the winning
	previous state to the current state.
	---------------------------------------------------------------------*/
	for( state = 0; state < VITERBI_NUM_STATES/2;  state++ )
	{
		//---- Select the proper 2 of 4 distance measurements to use for this state ------
		// Goofy layout here opimtizes processor pipeline
		d0Ptr = distance + *decodePtr++;
		d1Ptr = distance + *decodePtr++;
		d0 = *d0Ptr;
		d1 = *d1Ptr;

		//---- get the path metrics for each branch into the state ---------
		metric0 = (*prevPathMetric++) + d0;		// PM0 + d0
		metric1 = (*prevPathMetric--) + d1;		// PM1 + d1

		if( metric0 > metric1 )
		{
			(*currPathMetric) = metric0;	// save the winning path metric for this node
			(*currPathMemory) = (*prevPathMemory) << 1;	
		}
		else
		{
			(*currPathMetric) = metric1;	
			(*currPathMemory) = ((*(prevPathMemory+1)) << 1) + 1;
		}
		currPathMetric += VITERBI_NUM_STATES/2;
		currPathMemory += VITERBI_NUM_STATES/2;


		metric0 = (*prevPathMetric++) + d1;		// PM0 + d1
		metric1 = (*prevPathMetric++) + d0;		// PM1 + d0

		if( metric0 > metric1 )
		{
			(*currPathMetric) = metric0;	// save the winning path metric for this node
			(*currPathMemory) = (*prevPathMemory) << 1;	
		}
		else
		{
			(*currPathMetric) = metric1;	
			(*currPathMemory) = ((*(prevPathMemory+1)) << 1) + 1;	
		}
		currPathMetric -= (VITERBI_NUM_STATES/2 - 1);
		currPathMemory -= (VITERBI_NUM_STATES/2 - 1);

		prevPathMemory += 2;

	}
			
 	return(state0Memory);
}
			

/*====================================================================
	Soft Viterbi decoding algorithm
=====================================================================*/
void viterbiDecodeFrame( MetricType *distance, u16 numCarriers )
{
	i16				ncar;
	i16				state;						// trellis state
  	MetricType		pathMetric0;
 	#if METRIC_OFFSET >= 0
		MetricType		acc;
	#endif

	//---- loop thourgh the subcarriers ---------------------------------
	for( ncar = 0; ncar < numCarriers; ncar++ )
	{		
		pathMem.pState0Memory = viterbiStateLoop(distance, pathMem.symbolCount);
		distance += 2;				// get next pair of distance metrics 

		/*--------------------------------------------------------------------
		As the 32 bit path memmory (currPathMemory) fills up, we need to catch the
		data before it falls off the MSB end.  Since we are loading the path memory
		from the bits that fall off the end of the (virtual) state shift register, 
		we can ignore the first K bits that are loaded into the path memory.  So,
		the user data starts at VITERBI_MEM_LEN+VITERBI_K symbols from when we
		started the decoder.  This is accomplished by presetting the variable 
		outWordBitCount = VITERBI_MEM_LEN+VITERBI_K-2.  
		---------------------------------------------------------------------*/
		pathMem.outWord <<= 1;					// shift in a 1, else shift in a zero
		if( *pathMem.pState0Memory & VITERBI_MSB )
			pathMem.outWord |= 1;	

		pathMem.outWordBitCount++;
		if( pathMem.outWordBitCount > WORD_LEN-1 )	// if we've collected a whole byte
		{									// put it in the buffer
			*pathMem.pUserData++ = pathMem.outWord;			// but a word in the user data Buffer
			pathMem.outWordBitCount = 0;
		}

		pathMem.symbolCount++;

		#if DEBUGIT == DEBUG_VITERBI_STATES
		{
			MetricType		*currPathMetric;
			u32				*currPathMemory;

			if( pathMem.symbolCount & 0x01 )	// alternate, odd/even,  between the
			{
				currPathMetric = pathMetricB;
				currPathMemory = pathMemoryB;
			}
			else
			{
				currPathMetric = pathMetricA;
				currPathMemory = pathMemoryA;
			}
			for(state = 0; state < VITERBI_NUM_STATES; state++ )
			{
				*diag.r++ = (double)currPathMetric[state];
				*diag.r++ = (double)currPathMemory[state];
			}
		}
		#endif
	}	// ncar
	
	// All metrics are roughly equal, but keep growing from frame to frame.
	// Subtract a common amount from all metrics to keep them from rolling over
	// the 16-bit variable.
	#if (METRIC_SIZE == 16) 
	{ 
		#if METRIC_OFFSET < 0
 			pathMetric0 = pathMetricA[0];
		#else
			acc = METRIC_OFFSET - pathMetricA[0];
		#endif

		for( state = 0; state < VITERBI_NUM_STATES;  state++ )
		{
			
			#if METRIC_OFFSET < 0
				pathMetricA[state] -= pathMetric0;
				pathMetricA[state] += METRIC_OFFSET;
				pathMetricB[state] -= pathMetric0;
				pathMetricB[state] += METRIC_OFFSET;
			#else
				pathMetricA[state] += acc;
				pathMetricB[state] += acc;
			#endif
		}

	}
	#endif

	return;
}


/*====================================================================
	Flush the path memory by processing a set of metric values
	representing zeros through the algorithm 
=====================================================================*/
void flushPathMemoryV( void )
{
#define	ZERODIST0		100
#define	ZERODIST1		0

	i16				ncar;
	MetricType 		*distance;

	#if CARRIER_LEN < VITERBI_MEM_LEN
		#error 	  flushPathMemoryV does not support CARRIER_LEN less than VITERBI_MEM_LEN.
	#endif

	distance = distanceArray;
	for( ncar = 0; ncar < CARRIER_LEN; ncar++ )
	{
		*distance++ = ZERODIST0;
		*distance++ = ZERODIST1;
	}

	//---- loop thourgh the subcarriers ---------------------------------
	viterbiDecodeFrame( distanceArray, VITERBI_MEM_LEN );
	
	return;
}


/*====================================================================
	Shift out remaining bits in the path memory.
	Note that this routine assumes that at least VITERBI_MEM_LEN+VITERBI_K 
	bits have been processed.
=====================================================================*/
void flushPathMemory( void )
{
	i16				nbit;
	
	//u16				outWord = 0;
	//i16				outWordBitCount = -(VITERBI_MEM_LEN+VITERBI_K-2);


	//mexPrintf("flush path memory data pointer: %d\n", pathMem.pUserData - rxUserDataArray );

	/*------------------------------------------------------------------------
	shift off the rest of the path memory except the last byte this was tacked
	on by the encoder to force the states to zero at the end of the record.
	------------------------------------------------------------------------*/
	for( nbit = 0;  nbit < VITERBI_MEM_LEN-2;  nbit++ )
	{
		pathMem.outWord <<= 1;					// shift in a 1, else shift in a zero
		if( *pathMem.pState0Memory & VITERBI_MSB )
		pathMem.outWord |= 1;					

		pathMem.outWordBitCount++;
		if( pathMem.outWordBitCount > WORD_LEN-1 )	// if we've collected a whole word
		{									// put it in the buffer
			*pathMem.pUserData++ = pathMem.outWord;
			pathMem.outWordBitCount = 0;
		}

		*pathMem.pState0Memory <<= 1;
	}

	//mexPrintf("flush path memory data pointer: %d\n", pathMem.pUserData - rxUserDataArray );

	//---- finish up the last word ----------------------------
	if( pathMem.outWordBitCount < WORD_LEN )
	{
		pathMem.outWord <<= (WORD_LEN - pathMem.outWordBitCount);
		*pathMem.pUserData++ = pathMem.outWord;
	}

	//mexPrintf("flush path memory data pointer: %d\n", pathMem.pUserData - rxUserDataArray );
	return;
}




?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧洲综合另类在线| 久久精品亚洲麻豆av一区二区| 自拍偷在线精品自拍偷无码专区| 成人在线视频首页| 日韩一区在线播放| 在线视频你懂得一区| 亚洲国产精品麻豆| 日韩亚洲欧美一区二区三区| 久久国产人妖系列| 久久亚洲精品小早川怜子| 国产91精品一区二区麻豆亚洲| 国产精品盗摄一区二区三区| 在线观看视频欧美| 人妖欧美一区二区| 国产日产欧产精品推荐色| 成年人午夜久久久| 香蕉加勒比综合久久| 精品99一区二区三区| 国产剧情av麻豆香蕉精品| 日韩毛片精品高清免费| 欧美日韩国产免费一区二区| 国产在线日韩欧美| 亚洲色图制服诱惑| 日韩午夜激情免费电影| 国产成人av电影在线播放| 亚洲丝袜精品丝袜在线| 欧美喷潮久久久xxxxx| 狠狠狠色丁香婷婷综合激情| 一区免费观看视频| 91精品一区二区三区久久久久久| 国产精品77777| 亚洲va国产天堂va久久en| 2024国产精品视频| 在线观看免费成人| 国产美女在线精品| 水蜜桃久久夜色精品一区的特点| 久久久久久久久久久久电影 | 波多野结衣一区二区三区| 17c精品麻豆一区二区免费| 日韩欧美一卡二卡| 一本色道久久综合狠狠躁的推荐| 久久国产精品99久久人人澡| 亚洲精品乱码久久久久久| 欧美精品一区二区在线观看| 在线亚洲一区二区| 丁香一区二区三区| 久久er99精品| 亚洲在线视频免费观看| 欧美激情在线看| 日韩一级在线观看| 欧美日韩一区二区在线观看| 国产91在线看| 韩国一区二区视频| 天天色 色综合| 亚洲九九爱视频| 国产精品无遮挡| 久久久久久久综合色一本| 欧美一区二区三区视频免费| 亚洲欧美在线视频观看| 久久亚洲春色中文字幕久久久| 欧美人狂配大交3d怪物一区| 色网综合在线观看| 99久久777色| 国产不卡一区视频| 久久精品免费观看| 蜜桃av一区二区三区| 日韩精品视频网站| 亚洲午夜精品在线| 一区二区三区欧美日韩| 亚洲人一二三区| 亚洲少妇30p| 国产精品久久久久aaaa樱花| 国产欧美一区二区精品忘忧草| 欧美大度的电影原声| 欧美videos中文字幕| 日韩丝袜美女视频| 精品裸体舞一区二区三区| 日韩欧美一区二区视频| 欧美一区二区视频在线观看 | 午夜精品久久久久久不卡8050| 亚洲激情在线激情| 一区二区三区日韩在线观看| 亚洲人成网站色在线观看| 一区二区三区资源| 一二三四区精品视频| 亚洲国产欧美一区二区三区丁香婷| 一个色综合av| 青青青伊人色综合久久| 久久成人综合网| 久久综合色综合88| wwww国产精品欧美| 国产精品久线在线观看| 一区二区三区四区不卡在线| 亚洲天堂免费看| 亚洲超碰精品一区二区| 久久国产精品一区二区| 国产一区二区剧情av在线| 成人18视频在线播放| 欧洲一区在线观看| 日韩欧美中文一区| 中文字幕免费不卡在线| 一区二区三区.www| 青青青爽久久午夜综合久久午夜| 久久激情五月激情| 成人激情开心网| 欧美三级韩国三级日本一级| 欧美一级片在线观看| 久久精品日产第一区二区三区高清版 | 欧美日韩精品免费| 日韩一区二区三区四区五区六区| 精品国产凹凸成av人导航| 国产精品国产三级国产| 午夜精品久久久久久久99樱桃 | 亚洲一区二区精品视频| 日本va欧美va欧美va精品| 成人av网在线| 在线不卡一区二区| 国产精品无遮挡| 美女视频黄a大片欧美| 9l国产精品久久久久麻豆| 3d成人动漫网站| 中文字幕中文字幕一区| 日韩电影在线一区| 99r国产精品| 精品美女一区二区| 亚洲综合丁香婷婷六月香| 极品瑜伽女神91| 欧美日韩国产首页| |精品福利一区二区三区| 久久国产精品色婷婷| 在线看国产一区二区| 国产人成一区二区三区影院| 色激情天天射综合网| 日韩欧美一区二区视频| 亚洲色图制服丝袜| 国产剧情一区二区三区| 欧美一区中文字幕| 亚洲女人的天堂| 国产成人免费视频一区| 91精品国产综合久久精品麻豆| 自拍偷拍国产亚洲| 国产91精品一区二区麻豆网站 | 精品一区二区三区免费毛片爱| 在线精品视频小说1| 国产精品久久久久久亚洲伦 | 国产一区二区三区在线看麻豆| 欧美日韩综合不卡| 中文字幕综合网| www.av精品| 国产精品免费aⅴ片在线观看| 免费人成黄页网站在线一区二区| 在线区一区二视频| 亚洲精品va在线观看| 99re8在线精品视频免费播放| 国产丝袜在线精品| 国产一区在线观看麻豆| 欧美v日韩v国产v| 麻豆国产91在线播放| 欧美一区二区在线不卡| 午夜欧美大尺度福利影院在线看| 一本久久综合亚洲鲁鲁五月天| 国产精品伦理一区二区| 国产iv一区二区三区| 久久精品人人做| 国产精品996| 日本一区二区久久| 粉嫩欧美一区二区三区高清影视| 久久久三级国产网站| 国产乱码精品一区二区三区av| 精品国产在天天线2019| 精品夜夜嗨av一区二区三区| 精品久久人人做人人爱| 麻豆成人久久精品二区三区小说| 欧美一区二区观看视频| 免费av成人在线| 精品成人在线观看| 国产成人午夜精品影院观看视频 | 2021国产精品久久精品 | 国产美女精品在线| 国产夜色精品一区二区av| 国产成人日日夜夜| 成人免费小视频| 国产精品高潮久久久久无| 色综合久久久久综合99| 亚洲综合免费观看高清在线观看| 欧美日韩精品专区| 久久精品国产一区二区| 久久久久久黄色| 色综合久久久久久久久久久| 亚洲一区二区三区四区中文字幕| 欧美日韩一区 二区 三区 久久精品| 香蕉av福利精品导航| 欧美精品一区二区不卡 | 综合久久久久久久| 欧美日韩中字一区| 国产一区二区三区蝌蚪| 亚洲人吸女人奶水| 日韩午夜av一区| 99国产麻豆精品| 日本成人在线看|