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

📄 sratematch.c

📁 这是一个c++编写的WCDMA链路采用RAKE接收的方针源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 *              Algorithm can be used either to static or dynamic rate matching. */int wcdma_rate_dematch(           double 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 */           double outData[])    /* OUT: Dematched output */{    double block_ratio;    double temp_double_vector[MAX_BLOCK_SIZE];    double temp_output_vector[MAX_BLOCK_SIZE];    double *temp_input;    int current_input_size;    double *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(double));            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_double_vector[l++] = temp_input[i];                }            }            x -= k;            y -= k;            memcpy(temp_output_vector, temp_double_vector, sizeof(double)*l);            output_size = l;            temp_input = temp_output_vector;        }        if (y == 1) {            output_size -= 1;            memcpy(outData, temp_output_vector+1, sizeof(double)*(output_size));        } else {            memcpy(outData, temp_output_vector, sizeof(double)*(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(double));            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_double_vector[l++] = temp_input[i];                } else {                    temp_double_vector[l++] = temp_input[i];                    temp_double_vector[l++] = temp_input[i];                }            }            x -= k;            y -= k;            memcpy(temp_output_vector, temp_double_vector, sizeof(double)*l);            output_size = l;            temp_input = temp_output_vector;            current_input_size = l;        } /* while */        if (y == 1) {            output_size += 1;            temp_output_vector[output_size-1] =                                   temp_output_vector[output_size-2];            out_ptr = &(outData[0]);        } else {            out_ptr = outData;        }        memcpy(out_ptr, temp_output_vector, sizeof(double)*output_size);    } /* else for repetition */    return(0);} /* wcdma_rate_dematch *//* -------------------------------------------------------------------- *//* * Static rate matching algorithm for a Transport Channel (TC). * The algorithm gets a vector of allowable bits per block, * size of input bit block, maximum puncturing ratio (1=all, 0.0=none). * Depending on the given pucturing ratio, it either punctures  * or repeats bits.  */int wcdma_srate_match4TC(        int no_of_allowed_sizes,/* size of allowed_bit_sizes -vector */	int allowed_block_sizes[],/* vector of allowed block sizes */	float max_punct_ratio,	/* max puncturing ratio (0.0 .. 1.0) */ 	int input_size,		/* size of input block */	int input_data[],	/* vector of input data bits */	int *output_size,	/* size of output block */	int output_data[])	/* vector of output data bits */{    int i, j, k, x, y, z, puncture;    int ratio_to_upper_size, ratio_to_lower_size, l;    int temp_int_vector[MAX_BLOCK_SIZE];    int temp_output_vector[MAX_BLOCK_SIZE];    int *temp_input;    int *out_ptr;    int upper_block_size, lower_block_size;    int current_input_size;    float lbs;    float needed_punct_ratio;    /*     * Check the size of input block related to the allowed     * output blocks.     * Check whether we need to puncture or repeat bits.     */    i = 0;    while ( (i < no_of_allowed_sizes) &&            (input_size > allowed_block_sizes[i] ) ) {        i++;    }    if (i < no_of_allowed_sizes) { /* between two output sizes */        lower_block_size = allowed_block_sizes[i-1];        upper_block_size = allowed_block_sizes[i];        ratio_to_upper_size  = upper_block_size / input_size;        /*         * If input block fits N (N>1) times to output block,         * then repeat every bit N times.         */        if ( (ratio_to_upper_size > 1) && (input_size != lower_block_size) ) {            l = 0;	    for (j=0; j < input_size; j++) {		for (k=0; k < ratio_to_upper_size; k++) {                    temp_output_vector[l++] = input_data[j];                }	    }        }        lbs = (float)lower_block_size;        needed_punct_ratio = ((float)input_size - lbs) / (float)input_size;;        puncture = (needed_punct_ratio > max_punct_ratio) ? FALSE : TRUE;    }    else /* bigger than maximum output size */    {        lower_block_size = allowed_block_sizes[i];        upper_block_size = NO_UPPER_BLOCK_SIZE;        ratio_to_lower_size  = (float)input_size / (float)lower_block_size;        if (ratio_to_lower_size > max_punct_ratio) {            fprintf(stderr,                    "wcdma_srate_match4TC: Too much pucturing required.\n");            return(-1);        } else {            puncture = TRUE;        }    }        /*     * Now puncture, if needed.     * Puncture every z'th bit, until input fits to TC block.     */    temp_input = input_data;    if (puncture == TRUE) {        x = input_size;        y = input_size - lower_block_size;        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(output_data, temp_output_vector, sizeof(int)*(*output_size));    } else {        /*         * Could not puncture, do repetition to fill up to upper block size.         */        x = input_size;        y = upper_block_size - input_size;        current_input_size = input_size;        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;            output_data[0] = temp_output_vector[0];            out_ptr = &(output_data[1]);        } else {            out_ptr = output_data;        }        memcpy(out_ptr, temp_output_vector, sizeof(int)*l);    } /* else for repetition */    return(0);} /* wcdma_srate_match4TC *//* ----------------------------------------------------------- */

⌨️ 快捷键说明

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