📄 sratematch.c
字号:
/* | | Copyright disclaimer: | This software was developed at the National Institute of Standards | and Technology by employees of the Federal Government in the course | of their official duties. Pursuant to title 17 Section 105 of the | United States Code this software is not subject to copyright | protection and is in the public domain. | | We would appreciate acknowledgement if the software is used. |*//* | Project: WCDMA simulation environment | Module: Static rate matching algorithm. | Author: Tommi Makelainen | Date: January 27, 1999 | | History: | January 27, 1999 Tommi Makelainen | Initial version. | | June 18, 1999 Tommi Makelainen | Instances added. | */#include <stdlib.h> #include <stdio.h>#include <math.h>#include "misdefs.h"#include "sratematch.h"#define NO_UPPER_BLOCK_SIZE -1#define MAX_BLOCK_SIZE 10000 /* ------------ S T A T I C D A T A S T R U C T U R E S ----------- */#if 0/* * Allocation list of available rate matching entities and the current count. */static enum instance_state rate_match_alloc_list[MAX_RATE_MATCHINGS];static rate_match_instance_count = 0;/* * Parameters specific for each rate matching unit. */static int transport_block_sizes[MAX_RATE_MATCHINGS];static double punct_ratios[MAX_RATE_MATCHINGS];/* * Initialization flag for static data structures. */static int general_init_flag = FALSE;#endif /* 0 *//* -------------------------------------------------------------------- *//* * Function: wcdma_rate_match_init * Desc.: Inits rate matching and returns the allocated * instance number. * * Returns: => 0 allocated instance number, -1 if no free. * * Note: */int wcdma_rate_match_init( int pilot_length, /* IN: length of pilot in frame (in chips) */ double finger_inc_level, /* IN: finger select threshold */ int nFingers) /* IN: number of fingers to use */{ int i, instance;#if 0 /* * If first call, initialize static data. */ if (general_init_flag == FALSE) { for (i=0; i < MAX_RAKES; i++) { rate_match_alloc_list[i] = FREE_INSTANCE; init_flags[i] = TRUE; } /* for */ general_init_flag = TRUE; } /* if general_init_flag */ /* * Find first free instance number. */ instance = -1; for (i=0; i < MAX_RAKES; i++) { if (rate_match_alloc_list[i] == FREE_INSTANCE) { instance = i; break; } } if (instance == -1) return(-1); /* no free instances */ /* * Store rake specific data. */ init_flags[instance] = TRUE; path_select_level[instance] = finger_inc_level; finger_count[instance] = nFingers; pilot_len[instance] = pilot_length; /* * Update rake allocation list and count. */ rate_match_alloc_list[instance] = INSTANCE_IN_USE; rate_match_instance_count++;#endif /* 0 */ return(instance);}/* -------------------------------------------------------------------- *//* * Function: wcdma_rate_match_free * Desc.: Free one rate matching reservation. * * Note: */void wcdma_rate_match_free(int instance){#if 0 rate_match_alloc_list[instance] = FREE_INSTANCE; rate_match_instance_count--;#endif /* 0 */ return;}/* -------------------------------------------------------------------- *//* * Function: wcdma_rate_match * Desc.: Do rate matching for uplink channels. * * Note: * Can be used either for static or dynamic rate matching. */int wcdma_rate_match( int Inputs[], /* IN: input data symbol vector */ int nInputs, /* IN: length of input data vector */ double max_punct_ratio, /* IN: Max. ratio to puncture/repetite */ int target_block_size, /* IN: block size to match */ int outData[]) /* OUT: matched output */{ double block_ratio; int temp_int_vector[MAX_BLOCK_SIZE]; int temp_output_vector[MAX_BLOCK_SIZE]; int *temp_input; int current_input_size; int *out_ptr; int output_size; int i, j, k, l, x, y, z, puncture; /* * Check the size of input block related to the allowed * output block size. * Check whether we need to puncture or repeat bits. */ block_ratio = (target_block_size - nInputs) / (float)nInputs; if (block_ratio > max_punct_ratio) { printf("wcdma_rate_match: puncture/repetition ratio %g too large.\n", block_ratio); return(-1); } puncture = (block_ratio > 0) ? FALSE : TRUE; /* * Now puncture, if needed. * Puncture every z'th bit, until input fits to TC block. */ temp_input = Inputs; if (puncture == TRUE) { x = nInputs; y = nInputs - target_block_size; if (y <= 1) { memcpy(temp_output_vector, temp_input, nInputs*sizeof(int)); output_size = nInputs; } while (y > 1) { z = (int)ceil((double)x/(double)y); k = x / z; l = 0; /* * Puncture every z'th bit. */ for (i=0; i < x; i++) { if ((i % z) != (z-1)) { temp_int_vector[l++] = temp_input[i]; } } x -= k; y -= k; memcpy(temp_output_vector, temp_int_vector, sizeof(int)*l); output_size = l; temp_input = temp_output_vector; } if (y == 1) output_size -= 1; memcpy(outData, temp_output_vector, sizeof(int)*(output_size)); } else { /* * Repetition. */ x = nInputs; y = target_block_size - nInputs; current_input_size = nInputs; if (y <= 1) { memcpy(temp_output_vector, temp_input, nInputs*sizeof(int)); output_size = nInputs; } while (y > 1) { z = (int)ceil((double)x/(double)y); k = x / z; l = 0; /* * Repeat every z'th bit. */ for (i=0; i < current_input_size; i++) { if ((i % z) != (z-1)) { temp_int_vector[l++] = temp_input[i]; } else { temp_int_vector[l++] = temp_input[i]; temp_int_vector[l++] = temp_input[i]; } } x -= k; y -= k; memcpy(temp_output_vector, temp_int_vector, sizeof(int)*l); output_size = l; temp_input = temp_output_vector; current_input_size = l; } /* while */ if (y == 1) { output_size += 1; outData[0] = temp_output_vector[0]; out_ptr = &(outData[1]); } else { out_ptr = outData; } memcpy(out_ptr, temp_output_vector, sizeof(int)*output_size); } /* else for repetition */ return(0);} /* wcdma_rate_match *//* -------------------------------------------------------------------- *//* * Function: wcdma_rate_dematch * Desc.: Do dynamic rate dematching for uplink channels. * * Note:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -