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

📄 cdma_powerlog5.ps.c

📁 在opnet平台下的卫星仿真程序
💻 C
字号:
/* cdma_powerlog5.ps.c */                                                       /* CDMA log-normal with %5 percentage received power model for radio link Transceiver Pipeline */#include "opnet.h"#include <math.h>/***** constants *****/#define C					3.0E+08			/* speed of light (m/s) */#define SIXTEEN_PI_SQ		157.91367		/* 16 times pi-squared */static const char*	PowI_Err_Hdr = "Error in radio power computation pipeline stage (cdma_powerlog5):";/***** pipeline procedure *****/#if defined (__cplusplus)extern "C"#endifvoidcdma_powerlog5 (Packet * pkptr)	{	double		prop_distance, rcvd_power, rcvd_power1, path_loss;	double		tx_power, tx_base_freq, tx_bandwidth, tx_center_freq;	double		lambda, rx_ant_gain, tx_ant_gain;	Objid		rx_ch_obid;	Objid 		rx_nodeid;	double		in_band_tx_power, band_max, band_min;	double		rx_base_freq, rx_bandwidth;	Distribution* normalpower;	double 		logper,logvar;	double 		randnum,lognum;	int 		msgbuf[512];   		/** Compute the average power in Watts of the		**/	/** signal associated with a transmitted packet.	**/	FIN (cdma_powerlog5(pkptr));	/*Generate Normal Distiributed Numbers with mean 0.0 and variance 1.0 */	normalpower=op_dist_load("fast_normal",0.0,1.0);	/* We have to make sure that the initialization is done and the extended 	attributes are loaded */		rx_nodeid = op_td_get_int(pkptr, OPC_TDA_RA_RX_OBJID);	if (op_ima_obj_attr_get( rx_nodeid, "Log_Percentage",				 &logper) ==	    OPC_COMPCODE_FAILURE) 	{		op_sim_end (PowI_Err_Hdr, "No Log_Percentage attr",			    OPC_NIL, OPC_NIL);	}		if (op_ima_obj_attr_get( rx_nodeid, "Log_Var",				 &logvar) ==	    OPC_COMPCODE_FAILURE) 	{		op_sim_end (PowI_Err_Hdr, "No Log_Var attr",			    OPC_NIL, OPC_NIL);	}	/* If the incoming packet is 'valid', it may cause the receiver to	*/	/* lock onto it. However, if the receiving node is disabled, then	*/	/* the channel match should be set to noise.						*/	if (op_td_get_int (pkptr, OPC_TDA_RA_MATCH_STATUS) == OPC_TDA_RA_MATCH_VALID)		{		if (op_td_is_set (pkptr, OPC_TDA_RA_ND_FAIL))			{			/* The receiving node is disabled.  Change	*/			/* the channel match status to noise.		*/			op_td_set_int (pkptr, OPC_TDA_RA_MATCH_STATUS, OPC_TDA_RA_MATCH_NOISE);			}		else			{			/* The receiving node is enabled.  Get	*/			/* the address of the receiver channel.	*/			rx_ch_obid = op_td_get_int (pkptr, OPC_TDA_RA_RX_CH_OBJID);			}	}	/* Get power allotted to transmitter channel. */	tx_power = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_POWER);		/* Get transmission frequency in Hz. */	tx_base_freq = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_FREQ);	tx_bandwidth = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_BW);	tx_center_freq = tx_base_freq + (tx_bandwidth / 2.0);	/* Caclculate wavelength (in meters). */	lambda = C / tx_center_freq;	/* Get distance between transmitter and receiver (in meters). */	prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_START_DIST);		/* When using TMM, the TDA OPC_TDA_RA_RCVD_POWER will already	*/	/* have a raw value for the path loss. */	if (op_td_is_set (pkptr, OPC_TDA_RA_RCVD_POWER))		{		path_loss = op_td_get_dbl (pkptr, OPC_TDA_RA_RCVD_POWER);		}	else		{		/* Compute the path loss for this distance and wavelength. */		if (prop_distance > 0.0)			{			path_loss = (lambda * lambda) / 				(SIXTEEN_PI_SQ * prop_distance * prop_distance);			}		else			path_loss = 1.0;		}	/* Determine the receiver bandwidth and base frequency. */	rx_base_freq = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_FREQ);	rx_bandwidth = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_BW);	/* Use these values to determine the band overlap with the transmitter.	*/	/* Note that if there were no overlap at all, the packet would already	*/	/* have been filtered by the channel match stage.						*/	/* The base of the overlap band is the highest base frequency. */	if (rx_base_freq > tx_base_freq) 		band_min = rx_base_freq;	else		band_min = tx_base_freq;		/* The top of the overlap band is the lowest end frequency. */	if (rx_base_freq + rx_bandwidth > tx_base_freq + tx_bandwidth)		band_max = tx_base_freq + tx_bandwidth;	else		band_max = rx_base_freq + rx_bandwidth;	/* Compute the amount of in-band transmitter power. */	in_band_tx_power = tx_power * (band_max - band_min) / tx_bandwidth;	/* Get antenna gains (raw form, not in dB). */	tx_ant_gain = pow (10.0, op_td_get_dbl (pkptr, OPC_TDA_RA_TX_GAIN) / 10.0);	rx_ant_gain = pow (10.0, op_td_get_dbl (pkptr, OPC_TDA_RA_RX_GAIN) / 10.0);	/* Calculate received power level. */	randnum=op_dist_outcome(normalpower);	lognum=pow(10.0,((sqrt(logvar)*randnum / 10.0) - (sqrt(logvar)*1.6449 / 10)));		rcvd_power = in_band_tx_power * tx_ant_gain * path_loss * rx_ant_gain * lognum;		/* Assign the received power level (in Watts) */	/* to the packet transmission data attribute. */	op_td_set_dbl (pkptr, OPC_TDA_RA_RCVD_POWER, rcvd_power);			FOUT;	}

⌨️ 快捷键说明

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