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

📄 dl_sc_alloc.c

📁 802.16e物理层下行子载波分配。严格按照802.16e实现。
💻 C
📖 第 1 页 / 共 2 页
字号:

/*
 ***************************************************************************************
 *                                     DEFINES
 ***************************************************************************************
 */
#include "..\include\wib_phy_def.h"
#define DEBUG_OUT_FILE

/*
 * *************************************************************************************
 * function: dl_subcarrier_alloc_pusc module
 * parameters: 
 *
 *			UINT16 	* datasc_index_addr,	//matrix of data subcarrier of subchannel:[MAXSUBCHN_NUM][MAX_SC_NUM_SUBCHN]
 *			UINT16 	* pilotsc_index_addr,	//sequence of pilot subcarrier of symbol:[MAX_PILOT_NUM_SYM]
 *			UINT16 	* data_physc_index_addr,//sequence of data subcarrier of symbol:[MAX_DATASC_NUM]
 *			UINT16 	first_dl_flag,			//first downlink zone flag bit
 *			UINT16 	zone_use_all_sc,		//use all subchannels indicatior
 *			UINT16 	zone_dl_permbase,		//permbase of zone
 *			UINT16 	zone_PRBS_ID,			//PRBS_ID of zone
 *			UINT16 	* fch_bitmap,			//used flag of subchannel group
 *			UINT16 	symbol_parity,			//symbol parity
 *			UINT16 	segment_id				//segment ID of current 
 * return: int 1
 * description: downlink FUSC zone subchannel subcarriers allocation module
 * -------------------------------------------------------------------------------------
 */
int dl_subcarrier_alloc_pusc
	(
		UINT16 *datasc_index_addr, 
		UINT16 *data_physc_index_addr,
		UINT16 first_dl_flag,
		UINT16 zone_use_all_sc,
		UINT16 zone_dl_permbase,
		UINT16 zone_PRBS_ID,
		UINT16 *fch_bitmap,		
		UINT16 symbol_parity,
		UINT16 segment_id
	)
{
	/*
	 ***************************************************************************************
	 *                             basic parameter definition
	 ***************************************************************************************
	 */

		/* group's first subchannel index of all subchannel for 1024 FFT size */
		UINT16 startindx_group[6] = {0,6,10,16,20,26};

		/* cluster renumber sequence for 1024 FFT size */
		UINT16 clust_renum_seq[60]	= {
							6, 48, 37, 21, 31, 40, 42, 56, 32, 47, 30, 33, 54, 18,
	                   		10, 15, 50, 51, 58, 46, 23, 45, 16, 57, 39, 35, 7, 55,
	                   		25, 59, 53, 11, 22, 38, 28, 19, 17, 3, 27, 12, 29, 26,
	                  		5, 41, 49, 44, 9, 8, 1, 13, 36, 14, 43, 2, 20, 24, 52,
	                   		4, 34, 0
	                   		};

		/* permutation base sequence of group which have 6 subchannels for 1024 FFT size */
		UINT16 permubase6_pusc_1024[6] = {3,2,0,4,5,1};

		/* permutation base sequence of group which have 4 subchannels for 1024 FFT size */
		UINT16 permubase4_pusc_1024[4] = {3,0,2,1};
		
		/* basic parameter of PUSC 1024 FFT */
		UINT16 nb_group_pusc = 6;					// group number
		UINT16 nb_clust_pusc = 60;					// cluster number
		UINT16 nb_subchn_pusc = 30;					// subchannel number
		UINT16 clust_per_group_b = 12;				// cluster number of group 0,2,4
		UINT16 clust_per_group_s = 8;				// cluster number of group 1,3,5
		UINT16 sc_per_clust_pusc = 14;				// subcarrier number of a cluster
		UINT16 datasc_per_clust_pusc = 12;			// data subcarrier number of a cluster
		UINT16 sc_per_subchn_pusc = 24;				// subcarrier number of a subchannel

	/*
	 ***************************************************************************************
	 *                            variable definition
	 ***************************************************************************************
	 */
                                	               		

		/* data type variable for PUSC permutiaon 1024 FFT size */ 
		UINT16 clust_phys_pusc[60][14];				//subcarrier of physical cluster
		UINT16 clust_lgc_pusc[60][14];				//subcarrier of logic cluster
		UINT16 sc_data_clust_pusc[60][12];			//data subcarrier of cluster
		UINT16 sc_pilot_clust_pusc[60][2];			//pilot subcarrier of cluster
		UINT16 sc_data_group_pusc[6][144];			//data subcarrier of group
		UINT16 sc_pilot_group_pusc[6][24];			//pilot subcarrier of group
		UINT16 sc_subchn_pusc[30][24];				//data subcarrier of subchannel
		UINT16 sc_subchn_seg_pusc[30][24];			//data subcarrier of subchannel for current segment
		UINT16 suchn_nb_seg_pusc;					//subchannel number of current segment
		UINT16 pilot_nb_seg_pusc;					//pilot number of current segment
		UINT16 idic_group_seg[6][2];				//used group indicator of current segment
		UINT16 idic_group_seg_tmp[6][2];			//temporary

#ifdef DEBUG_OUT_FILE		
		FILE *fp_scallc_PUSC_10M;							//file pionter of ouput file
#endif

	/* tempory variable */
	UINT16 renum_temp;
	UINT16 tmp_subchn_index;
	UINT16 tmp_permubase6[6];
	UINT16 tmp_permubase4[4];
	UINT16 tmp_i;
	UINT16 tmp_j;
	UINT16 tmp_k;
	UINT16 tmp_index;
	UINT16 nk,nk_m;
	UINT16 i,j,k;
	
	/*
	 ***************************************************************************************
	 *                             function definition
	 ***************************************************************************************
	 */
		/*------------------------ 10M bandwidth  ---------------------------------------*/



		/*------------------------ generate logic cluster -------------------------------*/

#ifdef DEBUG_OUT_FILE
		/* create scallc_PUSC_10M.txt to store debug information of PUSC 10M */
		fp_scallc_PUSC_10M = fopen("scallc_PUSC_10M.txt","w");

		fprintf(fp_scallc_PUSC_10M,"\n/*************the first subcarrier of cluster*******************/\n");
#endif		
		/* subcarriers are allocated into physical cluster group */
		/* 0 ~ 91,512,933 ~ 1023 is zero subcarriers */
		for (i = 0; i < nb_clust_pusc; i++)
		{
			for(j = 0; j < sc_per_clust_pusc; j++)
			{
				/* 92 ~ 511 also (-420 ~ -1) */
				if(i < nb_clust_pusc/2)			
					clust_phys_pusc[i][j] =  92 + i * sc_per_clust_pusc + j;
				
				/* 512 ~ 932(1 ~ 420) */
				else							
					clust_phys_pusc[i][j] =  92 + i * sc_per_clust_pusc + j + 1;
			}
		}
		

		/* renumber physical cluster then transmit it into logical cluster */
		for (i = 0; i < nb_clust_pusc; i++)
		{
			/*computer logic cluter position */
			/* first DL zone and use all sc indicator is 1*/
			if((zone_use_all_sc == 0) || (first_dl_flag))
				renum_temp = clust_renum_seq[i];
			else
				renum_temp = clust_renum_seq[(i + zone_dl_permbase * 13) % nb_clust_pusc];

			/*renumber cluster*/
			for (j = 0; j < sc_per_clust_pusc; j++)
			{
				clust_lgc_pusc[renum_temp][j] = clust_phys_pusc[i][j];
			}
		}


		/************DSP*******************/
		/* return the cluster subcarriers */
		for(i = 0; i < nb_clust_pusc; i++){
				*data_physc_index_addr = clust_lgc_pusc[i][0];
				data_physc_index_addr++;
		}

		for(i = 0; i < nb_clust_pusc; i++){
			if(i%5 == 4){
				fprintf(fp_scallc_PUSC_10M," cluster %5d : %5d\n",i,clust_lgc_pusc[i][0]); 
			}
			else{
				fprintf(fp_scallc_PUSC_10M," cluster %5d : %5d",i,clust_lgc_pusc[i][0]); 
			}

			
		}

	/*------------------------ separate pilot from data subcarriers -------------------------------*/

		/* separate data subcarriers from pilot subcarriers */
		for (i = 0; i < nb_clust_pusc; i++)
		{
			if(symbol_parity == 0)	//even symbol
			{
				/*  subcarrier 4,8 is pilot*/
				sc_pilot_clust_pusc[i][0] = clust_lgc_pusc[i][4];
				sc_pilot_clust_pusc[i][1] = clust_lgc_pusc[i][8];

				/* other subcarriers is data */
				sc_data_clust_pusc[i][0] = clust_lgc_pusc[i][0];
				sc_data_clust_pusc[i][1] = clust_lgc_pusc[i][1];
				sc_data_clust_pusc[i][2] = clust_lgc_pusc[i][2];
				sc_data_clust_pusc[i][3] = clust_lgc_pusc[i][3];
				sc_data_clust_pusc[i][4] = clust_lgc_pusc[i][5];
				sc_data_clust_pusc[i][5] = clust_lgc_pusc[i][6];
				sc_data_clust_pusc[i][6] = clust_lgc_pusc[i][7];
				sc_data_clust_pusc[i][7] = clust_lgc_pusc[i][9];
				sc_data_clust_pusc[i][8] = clust_lgc_pusc[i][10];
				sc_data_clust_pusc[i][9] = clust_lgc_pusc[i][11];
				sc_data_clust_pusc[i][10] = clust_lgc_pusc[i][12];
				sc_data_clust_pusc[i][11] = clust_lgc_pusc[i][13];
			}
			else					//odd symbol
			{
				/*  subcarrier 0,12 is pilot*/
				sc_pilot_clust_pusc[i][0] = clust_lgc_pusc[i][0];
				sc_pilot_clust_pusc[i][1] = clust_lgc_pusc[i][12];

				/* other subcarriers is data */
				sc_data_clust_pusc[i][0] = clust_lgc_pusc[i][1];
				sc_data_clust_pusc[i][1] = clust_lgc_pusc[i][2];
				sc_data_clust_pusc[i][2] = clust_lgc_pusc[i][3];
				sc_data_clust_pusc[i][3] = clust_lgc_pusc[i][4];
				sc_data_clust_pusc[i][4] = clust_lgc_pusc[i][5];
				sc_data_clust_pusc[i][5] = clust_lgc_pusc[i][6];
				sc_data_clust_pusc[i][6] = clust_lgc_pusc[i][7];
				sc_data_clust_pusc[i][7] = clust_lgc_pusc[i][8];
				sc_data_clust_pusc[i][8] = clust_lgc_pusc[i][9];
				sc_data_clust_pusc[i][9] = clust_lgc_pusc[i][10];
				sc_data_clust_pusc[i][10] = clust_lgc_pusc[i][11];
				sc_data_clust_pusc[i][11] = clust_lgc_pusc[i][13];
			}
		}
		
		/*------------------------ assign subcarrier to group -------------------------------*/

		/* assign cluster to group */
		for (i = 0; i < nb_group_pusc; i++)
		{
			
			/*  computer group's first cluster index of all cluster */
			tmp_j = startindx_group[i] * 2;

			/* this group have 12 clusters */
			if(i == 0 || i == 2 || i == 4)
			{
				for (j = 0; j < clust_per_group_b; j++)
				{
					tmp_k = tmp_j + j;

					/* assign data cluster to group  */
					for(k = 0; k < datasc_per_clust_pusc; k ++)
					{							
						sc_data_group_pusc[i][j*datasc_per_clust_pusc + k] = sc_data_clust_pusc[tmp_k][k];
					}

					/* assign pilot of cluster to group  */
					for(k = 0; k < 2; k++)
					{
						sc_pilot_group_pusc[i][j*2 + k] = sc_pilot_clust_pusc[tmp_k][k];
					} 	
				}
			}	

			/* this group have 8 clusters */
			else
			{
				for (j = 0; j < clust_per_group_s; j++)
				{
					tmp_k = tmp_j + j;

					/* assign data cluster to group  */
					for(k = 0; k < datasc_per_clust_pusc; k ++)
					{							
						sc_data_group_pusc[i][j*datasc_per_clust_pusc + k] = sc_data_clust_pusc[tmp_k][k];
					} 

					/* assign pilot of cluster to group  */
					for(k = 0; k < 2; k++)
					{
						sc_pilot_group_pusc[i][j*2 + k] = 	sc_pilot_clust_pusc[tmp_k][k];
					}		
				}
			}
		}




 		/*------------------------ generate subchannel subcarrier from group -------------------------------*/

		/* generate subcarrier's physical location of subchannel from group */
	
		for(i = 0; i < 6; i++)
		{
			/* this group have 6 subchannels */
			if(i == 0 || i == 2 || i == 4)
			{
				for(j = 0; j < 6; j++)
				{
					/* compute current subchannel index */
					tmp_index = i * 5 + j;

					/* initial permutationbase sequence */
					for (k = 0; k < 6 ; k++)
					{
						tmp_permubase6[k] = permubase6_pusc_1024[k];
					}	
					
					/* shift permutationbase sequence */
					for(k = 0; k < j; k++)
					{
						tmp_k = tmp_permubase6[0];
						tmp_permubase6[0] = tmp_permubase6[1];
						tmp_permubase6[1] = tmp_permubase6[2];
						tmp_permubase6[2] = tmp_permubase6[3];
						tmp_permubase6[3] = tmp_permubase6[4];
						tmp_permubase6[4] = tmp_permubase6[5];
						tmp_permubase6[5] = tmp_k;
					}

					/* compute suchannel sucarrier's physical location */
					for(k = 0; k < sc_per_subchn_pusc; k++)
					{
						/* nk_m = (k+13*s) mod Nsubcarriers */
						nk = (k + 13*j) % sc_per_subchn_pusc;

						/* nk_m = nk mod Nsubchannels */
						nk_m = nk % 6; 

						/* subcarrier (k, s) = Nsubchannels . nk +{ps[nk mod Nsubchannels]+ DL_PermBase} mod Nsubchannels */
						tmp_subchn_index = 6 * nk + (tmp_permubase6[nk_m] + zone_dl_permbase) % 6;				
						sc_subchn_pusc[tmp_index][k] = sc_data_group_pusc[i][tmp_subchn_index];

					}
				}						
			}

			/* this group have 4 subchannels */
			else if(i == 1 || i == 3 || i == 5)
			{
				for(j = 0; j < 4; j++)
				{
					/* compute current subchannel index */
					tmp_index = (i-1)*5 + 6 + j;

					/* initial permutationbase sequence */
					for (k = 0; k < 4 ; k++)
					{
						tmp_permubase4[k] = permubase4_pusc_1024[k];
					}

					/* shift permutationbase sequence */
					for(k = 0; k < j; k++)
					{
						tmp_k = tmp_permubase4[0];
						tmp_permubase4[0] = tmp_permubase4[1];
						tmp_permubase4[1] = tmp_permubase4[2];
						tmp_permubase4[2] = tmp_permubase4[3];
						tmp_permubase4[3] = tmp_k;
					}

					/* compute suchannel sucarrier's physical location */
					for(k = 0; k < sc_per_subchn_pusc; k++)
					{
						/* nk_m = (k+13*s) mod Nsubcarriers */
						nk = (k + 13*j) % sc_per_subchn_pusc;

						/* nk_m = nk mod Nsubchannels */
						nk_m = nk % 4; 

						/* subcarrier (k, s) = Nsubchannels . nk +{ps[nk mod Nsubchannels]+ DL_PermBase} mod Nsubchannels */
						tmp_subchn_index = 4 * nk + (tmp_permubase4[nk_m] + zone_dl_permbase) % 4;	
						sc_subchn_pusc[tmp_index][k] = sc_data_group_pusc[i][tmp_subchn_index];
						

					}
				}				
			}				
		}

		/*------------------------ renumber subchannel -------------------------------*/

#ifdef DEBUG_OUT_FILE
		/* renumber subchannel order */
		fprintf(fp_scallc_PUSC_10M,"\n/****************************the renumber suchannel subcarriers ************************/\n");			
#endif
		
		/* reset subchannel and pilot number of current segment */
		suchn_nb_seg_pusc = 0;
		pilot_nb_seg_pusc = 0;

		
		/* initial matrix of subchannel data subcarrier and pilot subcarriers of current segment */
		for (i = 0; i < nb_subchn_pusc; i++)
		{
			for(j = 0; j < sc_per_subchn_pusc; j++)
				sc_subchn_seg_pusc[i][j] = 0;
		}

		/* make mapping relationship between fch_bitmap and group */
    	for (i = 0; i < 6; i ++)
    	{
    		idic_group_seg_tmp[i][0] = *(fch_bitmap + i);
    		idic_group_seg_tmp[i][1] = i;  			
    	}
	  		
    	/* subchannel order renumber */
		/* not use all subchannels */
    	if(zone_use_all_sc == 0)	
    	{ 

    		/* renumber group */
			/* decide the first group based on segment ID*/
			/*start from group 0 ;the order is 0,1,2,3,4,5*/
    		if(segment_id == 0)
     		{
     			for(i = 0; i < 6; i ++)
     			{
     				idic_group_seg [i][0] = idic_group_seg_tmp[i][0];
     				idic_group_seg [i][1] = idic_group_seg_tmp[i][1];
     			}   						
    		}

			/*start from group 2 ; the order is 2,3,4,5,0,1*/
    		else if(segment_id == 1)
    		{
       			for(i = 0; i < 6; i ++)
     			{
     				tmp_j = (i + 2)%6;
     				idic_group_seg [i][0] = idic_group_seg_tmp[tmp_j][0];
     				idic_group_seg [i][1] = idic_group_seg_tmp[tmp_j][1];
     			}   						
    		}

			/*start from group 4 ; the order is 4,5,0,1,2,3*/
    		else if (segment_id == 2)
    		{
       			for(i = 0; i < 6; i ++)
     			{
     				tmp_j = (i + 4)%6;
     				idic_group_seg [i][0] = idic_group_seg_tmp[tmp_j][0];
     				idic_group_seg [i][1] = idic_group_seg_tmp[tmp_j][1];
     			}
    		}

    		/* renumber subchannel's order based on group's renumber order */
 			for (i = 0; i < nb_group_pusc; i++)
			{

				/*get the used flag of crrent group*/
				tmp_i = idic_group_seg [i][0];

⌨️ 快捷键说明

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