📄 spreading.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: Spreading and despreading | Author: Tommi Makelainen, Nokia/NIST | Date: January 5, 1999 | | History: | January 5, 1999 Tommi Makelainen | Initial version. | January 7, 1999 Tommi Makelainen | Spreading code can be longer than one input symbol. | Now it can be any multiple of data | symbols times spreading factor. | | January 9, 1999 Tommi Makelainen | Data types changed from char to int. | | April 6, 1999 Tommi Makelainen | Added soft despreader function. */#include <stdio.h>#include <math.h>#include "config_wcdma.h"/* * Function: wcdma_spread * Desc.: Spreads each data bit from vector 'data' by code * in vector 'code'. The code has length 'code_len'. * * Note: * Both input data and spreading code are expected * to given in antipodal (-1,1) presentation. * The length of data, 'data_len', must be * multiple of the code length 'code_len'. */int wcdma_spread( int data[], /* IN: input data bit vector */ int data_len, /* IN: length of input data vector */ int code[], /* IN: spreading code vector */ int code_len, /* IN: length of spreading code */ int sf, /* IN: Chip/data rate, i.e. spreading factor */ int out[]) /* OUT: spreaded output symbol vector */{ int i, out_index, j, k; int data_symbols_per_code_seq; data_symbols_per_code_seq = code_len / sf;#ifndef I_KNOW_WHAT_I_DO if (data_symbols_per_code_seq == 0) { if ( ((sf / code_len) != 0) && ((data_len / code_len) != 0) ) { printf("spread: Data length must be multiple of code length divided by spreading factor.\n"); return(-1); } } else if ( ( data_len % data_symbols_per_code_seq ) != 0 ) { printf("spread: Data length must be multiple of code length divided by spreading factor.\n"); return(-1); }#endif /* I_KNOW_WHAT_I_DO */ out_index = i = 0; while (i < data_len) { for (j=0; j < data_symbols_per_code_seq; j++) { for (k=j*sf; k < sf; k++) { out[out_index++] = data[i] * code[k]; } i++; } /* for */ } /* while */ return(0);} /* wcdma_spread *//* * Function: wcdma_hard_despread * Desc.: Despreads data symbols from vector 'in_data' by code * in vector 'code'. The code has length 'sf'. * * Note: * Both input data and spreading code are expected * to given in antipodal (-1,1) presentation. */int wcdma_hard_despread( int in_data[], /* IN: input data symbol vector */ int in_len, /* IN: length of input data vector */ int code[], /* IN: spreading code vector */ int code_len, /* IN: length of spreading code */ int sf, /* IN: Chip/data rate, i.e. spreading factor */ int out_data[]) /* OUT: despreaded output symbol vector */{ int i, data_length, out_index, j, new_out_index, k; int antipodal_data, outer_loop_count; int temp_data = 0; int data_symbols_per_code_seq; data_symbols_per_code_seq = code_len / sf;#ifndef I_KNOW_WHAT_I_DO if ( (in_len % data_symbols_per_code_seq ) != 0) { printf("despread: Data length must be multiple of ratio between code length and spreading factor.\n"); return(-1); }#endif /* I_KNOW_WHAT_I_DO */ out_index = i = 0; outer_loop_count = in_len / sf; while (out_index < outer_loop_count) { for (j=0; j < data_symbols_per_code_seq; j++) { temp_data = 0; for (k=j*sf; k < sf; k++, i++) { temp_data += in_data[i] * code[k]; } out_data[out_index] = (temp_data > 0) ? 1 : -1; out_index++; } /* for */ } /* while */ return(0);} /* wcdma_hard_despread *//* * Function: wcdma_soft_despread * Desc.: Despreads data symbols from vector 'in_data' by code * in vector 'code'. The code has length 'sf'. * Output soft decision is normalized with 'code_len'. * * Note: * Both input data and spreading code are expected * to given in antipodal (-1,1) presentation. */int wcdma_soft_despread( double in_data[], /* IN: input data symbol vector */ int in_len, /* IN: length of input data vector */ int code[], /* IN: spreading code vector */ int code_len, /* IN: length of spreading code */ int sf, /* IN: Chip/data rate, i.e. spreading factor */ double out_data[], /* OUT: despreaded output symbol vector */ int add_index, /* IN: index to add next output */ int ringBufLen) /* IN: ringbuffer length */{ int i, data_length, out_index, j, new_out_index, k; int antipodal_data, outer_loop_count; double temp_data = 0; int data_symbols_per_code_seq; data_symbols_per_code_seq = code_len / sf;#ifndef I_KNOW_WHAT_I_DO if ( (in_len % data_symbols_per_code_seq ) != 0) { printf("despread: Data length must be multiple of ratio between code length and spreading factor.\n"); return(-1); }#endif /* I_KNOW_WHAT_I_DO */ out_index = i = 0; outer_loop_count = in_len / sf; while (out_index < outer_loop_count) { for (j=0; j < data_symbols_per_code_seq; j++) { temp_data = 0; for (k=j*sf; k < code_len; k++, i++) { temp_data += in_data[i] * code[k]; } out_data[add_index] = temp_data / code_len; add_index = (add_index + 1) % ringBufLen; } /* for */ out_index++; } /* while */ return(0);} /* wcdma_soft_despread */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -