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

📄 test_txrx_statchan.c

📁 WCDMA的仿真程序,分别用C和MATLAB两种语言仿真
💻 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:      C-level Test bed for downlink discrete channel routines | Author:      Tommi Makelainen, Nokia/NIST | Date:        February 17, 1999 | | History: |              February 17, 1999 Tommi Makelainen |                      Initial version. | |              May 12, 1999 Tommi Makelainen |                      Created separate tx-rx tester. |                      Tests transmission path from Tx modulation |                      to Rx demodulation (data modulation, spreading, |                      channel, despreading and demodulation). | */#include <stdio.h>#include <math.h>#include "chcoding.h"#include "chdecoding.h"#include "discmod.h"#include "discdemod.h"#include "channel.h"#include "rake.h"#include "blockcollect.h"#define INPUT_SIZE 10#define PROB_VECTOR_LEN 2int main(int argc, char *argv[]){    int I_out[3*256*INPUT_SIZE];    double I_out_2[3*256*INPUT_SIZE];    int I_out_3[3*256*INPUT_SIZE];    double I_out_4[3*256*INPUT_SIZE];    int Q_out[3*256*INPUT_SIZE];    double Q_out_2[3*256*INPUT_SIZE];    int Q_out_3[3*256*INPUT_SIZE];    double Q_out_4[3*256*INPUT_SIZE];    int I_symbs_len, Q_symbs_len;#if 0    int pn_code[] = {1, 1, -1, -1};    int pn_code_len = 4;    int sf = 4;#endif#if 1    int pn_code[] = {1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1};    int pn_code_len = 256;    int sf = 256;#endif#if 0    int pn_code[] = {1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1,                     1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1};    int pn_code_len = 128;    int sf = 128;#endif     int tx_coded_symbol_bits[3*INPUT_SIZE];    int rx_coded_symbol_bits[3*INPUT_SIZE];    int ch_delays[8] = {0, 2, 5,7, 8, 8, 12, 16};    int ch_delays2[8] = {5, 8, 16,3};    int *ch_de_ptr;    int nTaps = 3;    int nImpulse = 1;    int nFrames = 0;    double ch_amplitudes[] = {0.7, 0.1, 0.2, 0.2, 0.15, 0.1, 0.1, 0.1};    double ch_amplitudes2[] = {0.1, 0.1, 0.8, 0.2};    int channel_delays[16];    double esno = 16; /* in dB */    double power = 0; /* milliWatts */    double r_temppi[3*INPUT_SIZE];    int in_temppi[10000];    int ch_id0 = 0, ch_id1 = 1;    int coder_instance, decoder_instance;    int rake_instance1, rake_instance2;    int channel_instance1, channel_instance2;    int symbuf_instance;    int ready;    double out_data[20];    double path_select_threshold;    int pilot_len;    int round;    double impulse_prob[1] = { 1.0 };    double impulse_cumul[1];    int channel_no = 0;    int bit_delay=0;    int delayI, delayQ;    int nFingers;    int diff;    int i, j, k, m, tmp_value;    ch_id0 = wcdma_channel_init(ch_amplitudes, ch_delays, nTaps,                                nImpulse, impulse_prob, nFrames,                                esno, power, pn_code_len);    round = 0;    m = 0;    ch_de_ptr = ch_delays;    path_select_threshold = 0.18;    nFingers = 2;    pilot_len = 20;    rake_instance1= wcdma_rake_init(pilot_len, path_select_threshold,                                    nFingers);    rake_instance2= wcdma_rake_init(pilot_len, path_select_threshold,                                    nFingers);    symbuf_instance = wcdma_symbolbuffer_init(20);    for (k=0; k < 8; k++) {    printf("round %d\n", round);/*    if ( (round % 8) == 1 ) ch_de_ptr = ch_delays;    if (round == 2) ch_de_ptr = ch_delays2;*/    if ((round % 2) == 0) {        for (i=0; i < INPUT_SIZE; i++) {            tmp_value = i % 2;            tx_coded_symbol_bits[i] = tmp_value > 0 ? 0 : 1;        }    } else {        for (i=0; i < INPUT_SIZE; i++) {            tmp_value = i % 2;            tx_coded_symbol_bits[i] = tmp_value > 0 ? 1 : 0;        }    }    for (i=0; i < INPUT_SIZE; i++)         in_temppi[k*INPUT_SIZE+i] = tx_coded_symbol_bits[i];    round++;    wcdma_dl_mod(tx_coded_symbol_bits, INPUT_SIZE, pn_code, pn_code_len,                 sf, I_out+pilot_len, Q_out+pilot_len);    wcdma_channel(I_out, Q_out, sf*(INPUT_SIZE/2)+pilot_len, ch_id0,                  ch_amplitudes, channel_delays, I_out_2, Q_out_2);    delayI = delayQ = 0;    wcdma_rake_receiver(rake_instance1, I_out_2, sf*(INPUT_SIZE/2)+pilot_len,                         pn_code, pn_code_len, sf,                        ch_de_ptr, ch_amplitudes, nTaps,                        &I_symbs_len, &delayI, I_out_4);    wcdma_rake_receiver(rake_instance2, Q_out_2, sf*(INPUT_SIZE/2)+pilot_len,                        pn_code, pn_code_len, sf,                        ch_de_ptr, ch_amplitudes, nTaps,                        &Q_symbs_len, &delayQ, Q_out_4);    for (i=0, j=0; i < INPUT_SIZE/2; i++, j += 2) {        rx_coded_symbol_bits[j] = I_out_3[i] = (I_out_4[i] > 0) ? 1 : 0;         rx_coded_symbol_bits[j+1] = Q_out_3[i] = (Q_out_4[i] > 0) ? 1 : 0;     }    ready = 0;    for (i=0; i < I_symbs_len+Q_symbs_len; i++)          r_temppi[i] = (double)rx_coded_symbol_bits[i];    wcdma_symbolbuffer(symbuf_instance, r_temppi,             I_symbs_len+Q_symbs_len, &ready, out_data);    if (ready == 1) {        printf(" round %d output: ", k);        for (j=0; j < 20; j++) {            printf(" %d", (out_data[j] > 0) ? 1 : 0 );            if ( ((m*20+j) % INPUT_SIZE) == 15 ) printf(" x ");        }        printf("\n");        printf(" round %d input : ", k);        for (j=0; j < 20; j++) {            printf(" %d", in_temppi[m*20+j]);            if ( ((m*20+j) % INPUT_SIZE) == 15 ) printf(" x ");        }        m++;        printf("\n");    }#if 0    for (i=0; i < (INPUT_SIZE); i++) {      printf("input %d output %d\n",             tx_coded_symbol_bits[i], rx_coded_symbol_bits[i]);    }#endif    printf(" ---- \n");    } /* for k *//*    printf("\n\tChecking difference of bits before and after convolution.\n");    diff=0;    bit_delay = (delayI == 0) ? 0 : (delayI/pn_code_len + 1);    for (i=0; i < (INPUT_SIZE-bit_delay); i++) {      printf("input %d output %d\n",             tx_coded_symbol_bits[i], rx_coded_symbol_bits[i+bit_delay]);      diff += (tx_coded_symbol_bits[i] == rx_coded_symbol_bits[i+bit_delay])               ? 0 : 1;    }    printf("\t\tDifference is %d bit places.\n", diff);*/    printf("\n");    wcdma_channel_free(ch_id0);    wcdma_channel_free(ch_id1);    wcdma_symbolbuffer_free(0);    return(0);}

⌨️ 快捷键说明

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