diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 9677d65a67..ac934cee8e 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1147,7 +1147,13 @@ set(PHY_POLARSRC ) set(PHY_TURBOIF ${OPENAIR1_DIR}/PHY/CODING/coding_load.c -) + ) +set(PHY_LDPCSRC + ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c + ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c + ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c + ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c + ) add_library(coding MODULE ${PHY_TURBOSRC} ) @@ -1300,6 +1306,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/TOOLS/time_meas.c ${OPENAIR1_DIR}/PHY/TOOLS/lut.c ${PHY_POLARSRC} + ${PHY_LDPCSRC} ) set(PHY_NR_UE_SRC @@ -1337,6 +1344,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/TOOLS/lut.c ${OPENAIR1_DIR}/PHY/INIT/nr_init_ue.c ${PHY_POLARSRC} + ${PHY_LDPCSRC} ) @@ -2541,6 +2549,9 @@ target_link_libraries (dlsim_tm4 add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c) target_link_libraries(polartest m SIMU PHY PHY_NR -lm ${ATLAS_LIBRARIES}) +add_executable(ldpctest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c) +target_link_libraries(ldpctest m SIMU PHY PHY_NR ${ATLAS_LIBRARIES}) + foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) add_executable(${myExe} diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c index 33c51386ba..3a1082382c 100644 --- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c +++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c @@ -25,8 +25,18 @@ #include #include "SIMULATION/TOOLS/sim.h" +#include "PHY/CODING/nrLDPC_encoder/defs.h" +#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h" +#define MAX_NUM_DLSCH_SEGMENTS 16 +#ifndef malloc16 +# ifdef __AVX2__ +# define malloc16(x) memalign(32,x) +# else +# define malloc16(x) memalign(16,x) +# endif +#endif // 4-bit quantizer char quantize4bit(double D,double x) @@ -62,11 +72,11 @@ char quantize(double D,double x,unsigned char B) #define MAX_BLOCK_LENGTH 8448 int test_ldpc(short No_iteration, - int nom_rate, - int denom_rate, + //int nom_rate, + //int denom_rate, double SNR, unsigned char qbits, - short block_length, + unsigned short block_length, unsigned int ntrials, unsigned int *errors, unsigned int *crc_misses) @@ -85,15 +95,16 @@ int test_ldpc(short No_iteration, double *modulated_input; char *channel_output_fixed; unsigned int i,j,trial=0; - short BG,Zc,Kb,nrows,ncols; - int no_punctured_columns,removed_bit; + short BG,Zc,Kb; + //short nrows,ncols; + //int no_punctured_columns,removed_bit; int i1; //Table of possible lifting sizes short lift_size[51]= {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32,36,40,44,48,52,56,60,64,72,80,88,96,104,112,120,128,144,160,176,192,208,224,240,256,288,320,352,384}; int n_segments=8; t_nrLDPC_dec_params decParams; - int n_iter; + //int n_iter; *errors=0; *crc_misses=0; @@ -107,7 +118,9 @@ int test_ldpc(short No_iteration, modulated_input = (double *)malloc(sizeof(double) * 68*384); channel_output = (double *)malloc(sizeof(double) * 68*384); channel_output_fixed = (char *)malloc16(sizeof(char) * 68*384); - estimated_output = (unsigned char*) malloc16(sizeof(unsigned char) * block_length/8); + estimated_output = (unsigned char*) malloc16(sizeof(unsigned char) * block_length); + + memset(channel_output_fixed,0,sizeof(char) * 68*384); reset_meas(&time); reset_meas(&time_optim); @@ -124,18 +137,18 @@ int test_ldpc(short No_iteration, } //determine number of bits in codeword - //if (block_length>3840) + if ((block_length>3840) && (block_length <= MAX_BLOCK_LENGTH)) { BG=1; Kb = 22; - nrows=46; //parity check bits - ncols=22; //info bits + //nrows=46; //parity check bits + //ncols=22; //info bits } - /*else if (block_length<=3840) + else if (block_length<=3840) { BG=2; - nrows=42; //parity check bits - ncols=10; // info bits + //nrows=42; //parity check bits + //ncols=10; // info bits if (block_length>640) Kb = 10; @@ -145,11 +158,14 @@ int test_ldpc(short No_iteration, Kb = 8; else Kb = 6; - }*/ - + } + else { + printf("block_length %d not supported\n",block_length); + exit(-1); + } + //find minimum value in all sets of lifting size Zc=0; - for (i1=0; i1 < 51; i1++) { if (lift_size[i1] >= (double) block_length/Kb) @@ -161,11 +177,11 @@ int test_ldpc(short No_iteration, } printf("ldpc_test: block_length %d, BG %d, Zc %d, Kb %d\n",block_length,BG, Zc, Kb); - no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc; + //no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc; // printf("puncture:%d\n",no_punctured_columns); - removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate)); + //removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate)); if (ntrials==0) - ldpc_encoder_orig(test_input[0],channel_input[0], block_length, nom_rate, denom_rate, 1); + ldpc_encoder_orig(test_input[0],channel_input[0], block_length, BG, 1); for (trial=0; trial < ntrials; trial++) { @@ -173,20 +189,20 @@ int test_ldpc(short No_iteration, //// encoder start_meas(&time); for(j=0;j 1280, 2401 -> 2560 short No_iteration=25; //double rate=0.333; - int nom_rate=1; - int denom_rate=3; + //int nom_rate=1; + //int denom_rate=3; double SNR0=-2.0,SNR,SNR_lin; unsigned char qbits=4; unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to size of SNR @@ -295,21 +301,13 @@ int main(int argc, char *argv[]) randominit(0); - while ((c = getopt (argc, argv, "q:r:s:l:n:d:")) != -1) + while ((c = getopt (argc, argv, "q:s:l:n:h")) != -1) switch (c) { case 'q': qbits = atoi(optarg); break; - case 'r': - nom_rate = atoi(optarg); - break; - - case 'd': - denom_rate = atoi(optarg); - break; - case 'l': block_length = atoi(optarg); break; @@ -323,21 +321,25 @@ int main(int argc, char *argv[]) break; default: - abort (); + case 'h': + printf("usage ldpctest -h -l blocklength -n n_trials -s SNR\n"); + exit(0); } - printf("the decoder supports BG2, Kb=10, Z=128 & 256\n"); - printf(" range of blocklength: 1201 -> 1280, 2401 -> 2560\n"); + //printf("the decoder supports BG2, Kb=10, Z=128 & 256\n"); + //printf(" range of blocklength: 1201 -> 1280, 2401 -> 2560\n"); + //printf("rate: %d/%d\n",nom_rate,denom_rate); printf("block length %d: \n", block_length); - printf("rate: %d/%d\n",nom_rate,denom_rate); + printf("n_trials %d: \n", n_trials); + printf("SNR0 %f: \n", SNR0); //for (block_length=8;block_length<=MAX_BLOCK_LENGTH;block_length+=8) for (SNR=SNR0;SNR3840) + if (BG==1) { - BG=1; Kb = 22; nrows=46; //parity check bits ncols=22; //info bits } - /*else if (block_length<=3840) + else if (BG==2) { - BG=2; nrows=42; //parity check bits ncols=10; // info bits @@ -232,7 +230,7 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh Kb = 8; else Kb = 6; - }*/ + } //find minimum value in all sets of lifting size Zc=0; @@ -315,10 +313,10 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh return 0; } -int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,short block_length,int nom_rate,int denom_rate,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput) +int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,short block_length,short BG,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput) { - short BG,Zc,Kb,nrows,ncols; + short Kb,Zc,nrows,ncols; int i,i1,j; int no_punctured_columns,removed_bit; //Table of possible lifting sizes @@ -345,16 +343,14 @@ int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_i AssertFatal(n_segments>0&&n_segments<=8,"0 < n_segments %d <= 8\n",n_segments); //determine number of bits in codeword - //if (block_length>3840) + if (BG==1) { - BG=1; Kb = 22; nrows=46; //parity check bits ncols=22; //info bits } - /*else if (block_length<=3840) + else if (BG==2) { - BG=2; nrows=42; //parity check bits ncols=10; // info bits @@ -366,7 +362,7 @@ int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_i Kb = 8; else Kb = 6; - }*/ + } //find minimum value in all sets of lifting size Zc=0; diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c index ed8201c51d..93edc734de 100644 --- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c +++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c @@ -361,13 +361,13 @@ short *choose_generator_matrix(short BG,short Zc) return Gen_shift_values; } -int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,unsigned char gen_code) +int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,short BG,unsigned char gen_code) { unsigned char c[22*384]; //padded input, unpacked, max size unsigned char d[68*384]; //coded output, unpacked, max size unsigned char channel_temp,temp; short *Gen_shift_values, *no_shift_values, *pointer_shift_values; - short BG,Zc,Kb,nrows,ncols; + short Zc,Kb,nrows,ncols; int i,i1,i2,i3,i4,i5,temp_prime,var; int no_punctured_columns,removed_bit; //Table of possible lifting sizes @@ -378,16 +378,14 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho int indlist2[1000]; //determine number of bits in codeword - //if (block_length>3840) + if (BG==1) { - BG=1; Kb = 22; nrows=46; //parity check bits ncols=22; //info bits } - /*else if (block_length<=3840) + else if (BG==2) { - BG=2; nrows=42; //parity check bits ncols=10; // info bits @@ -399,7 +397,7 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho Kb = 8; else Kb = 6; - }*/ + } //find minimum value in all sets of lifting size Zc=0; @@ -417,6 +415,8 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho return(-1); } + int K = ncols*Zc; + Gen_shift_values=choose_generator_matrix(BG,Zc); if (Gen_shift_values==NULL) { printf("ldpc_encoder_orig: could not find generator matrix\n"); @@ -438,9 +438,15 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho } no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc; + //nrows - no_punctured_columns = 2 +2*block_length/Zc removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*3); + // ((nrows-no_punctured_columns) * Zc-removed_bit) = + // 2Zc + 2*block_length //printf("%d\n",no_punctured_columns); //printf("%d\n",removed_bit); + //printf("%d\n",nrows-no_punctured_columns); + //printf("%d\n",((nrows-no_punctured_columns) * Zc-removed_bit)); + // unpack input memset(c,0,sizeof(unsigned char) * ncols * Zc); memset(d,0,sizeof(unsigned char) * nrows * Zc); @@ -608,8 +614,8 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho } // information part and puncture columns - memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char)); - memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char)); + memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char)); //systematic bits + memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char)); //systematic bits 2Zc + 2*block_length //memcpy(channel_input,c,Kb*Zc*sizeof(unsigned char)); return 0; }