Commit e5f9246c authored by letr's avatar letr Committed by Florian Kaltenberger

encoder with rate matching

parent f0e7c3da
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "SIMULATION/TOOLS/defs.h" #include "SIMULATION/TOOLS/defs.h"
#include "Gen_shift_value.h" #include "Gen_shift_value.h"
#include "choose_generator_matrix.h"
#include "ldpc_encoder_header.h"
// 4-bit quantizer // 4-bit quantizer
char quantize4bit(double D,double x) char quantize4bit(double D,double x)
...@@ -70,7 +72,7 @@ int test_ldpc(short No_iteration, ...@@ -70,7 +72,7 @@ int test_ldpc(short No_iteration,
double rate, double rate,
double SNR, double SNR,
unsigned char qbits, unsigned char qbits,
unsigned int block_length, short block_length,
unsigned int ntrials, unsigned int ntrials,
unsigned int *errors, unsigned int *errors,
unsigned int *crc_misses) unsigned int *crc_misses)
...@@ -81,8 +83,9 @@ int test_ldpc(short No_iteration, ...@@ -81,8 +83,9 @@ int test_ldpc(short No_iteration,
opp_enabled=1; opp_enabled=1;
cpu_freq_GHz = get_cpu_freq_GHz(); cpu_freq_GHz = get_cpu_freq_GHz();
short test_input[block_length]; //short test_input[block_length];
short *c; //padded codeword short *test_input;
//short *c; //padded codeword
short *esimated_output; short *esimated_output;
short *channel_input; short *channel_input;
double *channel_output; double *channel_output;
...@@ -90,40 +93,41 @@ int test_ldpc(short No_iteration, ...@@ -90,40 +93,41 @@ int test_ldpc(short No_iteration,
short *channel_output_fixed; short *channel_output_fixed;
unsigned int i,trial=0; unsigned int i,trial=0;
short *Gen_shift_values, *no_shift_values, *pointer_shift_values; /*
short BG,Zc,Kb,nrows,ncols; short BG,Zc,Kb,nrows,ncols,channel_temp;
int i1,i2,i3,i4,i5,i6,t,temp,k; int no_punctured_columns; //new
//Table of possible lifting sizes //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}; 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};
*/
*errors=0; *errors=0;
*crc_misses=0; *crc_misses=0;
while (trial++ < ntrials) { while (trial++ < ntrials)
{
// generate input block // generate input block
for (i=0; i<block_length; i++) { test_input=(short*)malloc(sizeof(short) * block_length);
for (i=0; i<block_length; i++)
//test_input[i] = (unsigned char)(taus()&0xff); {
test_input[i]=rand()%2; test_input[i]=rand()%2;
//test_input[i]=i%2; //test_input[i]=i%2;
} }
start_meas(&time);
//determine number of bits in codeword /*
//determine number of bits in codeword
if (block_length>3840) if (block_length>3840)
{ {
BG=1; BG=1;
Kb = 22; Kb = 22;
nrows=46; nrows=46; //parity check bits
ncols=22; ncols=22; //info bits
} }
else if (block_length<=3840) else if (block_length<=3840)
{ {
BG=2; BG=2;
nrows=42; nrows=42; //parity check bits
ncols=10; ncols=10; // info bits
if (block_length>640) if (block_length>640)
Kb = 10; Kb = 10;
else if (block_length>560) else if (block_length>560)
...@@ -134,7 +138,7 @@ for (i=0; i<block_length; i++) { ...@@ -134,7 +138,7 @@ for (i=0; i<block_length; i++) {
Kb = 6; Kb = 6;
} }
//find minimum value in all sets of lifting size //find minimum value in all sets of lifting size
for (i1=0; i1 < 51; i1++) for (i1=0; i1 < 51; i1++)
{ {
if (lift_size[i1] >= (double) block_length/Kb) if (lift_size[i1] >= (double) block_length/Kb)
...@@ -145,175 +149,74 @@ for (i=0; i<block_length; i++) { ...@@ -145,175 +149,74 @@ for (i=0; i<block_length; i++) {
} }
} }
// load base graph of generator matrix no_punctured_columns=(int)((nrows+Kb-2)*Zc-block_length/rate)/Zc;
if (BG==1) //printf("%d\n",no_punctured_columns);
{ */
no_shift_values=(short*) no_shift_values_BG1; start_meas(&time);
pointer_shift_values=(short*) pointer_shift_values_BG1; //// encoder
if (Zc==2||Zc==4||Zc==8||Zc==16||Zc==32||Zc==64||Zc==128||Zc==256)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_2;
// else if (Zc==3||Zc==6||Zc==12||Zc==24||Zc==48||Zc==96||Zc==192||Zc==384)
//Gen_shift_values=(short*) Gen_shift_values_BG1_a_3;
else if (Zc==384)
Gen_shift_values=(short*) Gen_shift_values_BG1_Z_384;
else if (Zc==5||Zc==10||Zc==20||Zc==40||Zc==80||Zc==160||Zc==320)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_5;
else if (Zc==7||Zc==14||Zc==28||Zc==56||Zc==112||Zc==224)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_7;
else if (Zc==9||Zc==18||Zc==36||Zc==72||Zc==144||Zc==288)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_9;
else if (Zc==11||Zc==22||Zc==44||Zc==88||Zc==176||Zc==352)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_11;
else if (Zc==13||Zc==26||Zc==52||Zc==104||Zc==208)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_13;
else if (Zc==15||Zc==30||Zc==60||Zc==120||Zc==240)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_15;
}
else if (BG==2)
{
no_shift_values=(short*) no_shift_values_BG2;
pointer_shift_values=(short*) pointer_shift_values_BG2;
//if (Zc==2||Zc==4||Zc==8||Zc==16||Zc==32||Zc==64||Zc==128||Zc==256)
// Gen_shift_values=(short*) Gen_shift_values_BG2_a_2;
if (Zc==128)
Gen_shift_values=(short*) Gen_shift_values_BG2_Z_128;
else if (Zc==3||Zc==6||Zc==12||Zc==24||Zc==48||Zc==96||Zc==192||Zc==384)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_3;
else if (Zc==5||Zc==10||Zc==20||Zc==40||Zc==80||Zc==160||Zc==320)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_5;
else if (Zc==7||Zc==14||Zc==28||Zc==56||Zc==112||Zc==224)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_7;
else if (Zc==9||Zc==18||Zc==36||Zc==72||Zc==144||Zc==288)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_9;
else if (Zc==11||Zc==22||Zc==44||Zc==88||Zc==176||Zc==352)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_11;
else if (Zc==13||Zc==26||Zc==52||Zc==104||Zc==208)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_13;
else if (Zc==15||Zc==30||Zc==60||Zc==120||Zc==240)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_15;
}
c=(short *)malloc(sizeof(short) * Kb * Zc);
channel_input = (short *)malloc( (Kb+nrows) * Zc *sizeof(short));
//padded input sequence
memset(c,0,sizeof(short) * Kb * Zc);
memcpy(c,test_input,block_length * sizeof(short));
//start_meas(&time);
//encode the input sequence
memset(channel_input,0,(Kb+nrows) * Zc*sizeof(short));
// parity check part
for (i2=0; i2 < Zc; i2++)
{
t=Kb*Zc+i2;
//rotate matrix here
for (i5=0; i5 < Kb; i5++)
{
temp = c[i5*Zc];
memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(short));
c[i5*Zc+Zc-1] = temp;
//for (i6 = 0; i6 < Zc-1; i6++)
//for (i6 = i5*Zc; i6 < i5*Zc + Zc-1; i6++)
//{
//c[i5*Zc+i6] = c[i5*Zc+i6+1];
//c[i6] = c[i6+1];
//}
//c[i5*Zc+i6] = temp;
//c[i6] = temp;
}
for (i1=0; i1 < nrows; i1++)
{
for (i3=0; i3 < Kb; i3++)
{
for (i4=0; i4 < no_shift_values[i1 * ncols + i3]; i4++)
{
channel_input[t+i1*Zc] = channel_input[t+i1*Zc] + c[ i3*Zc + Gen_shift_values[ pointer_shift_values[i1 * ncols + i3]+i4 ] ];
}
}
channel_input[t+i1*Zc]=channel_input[t+i1*Zc]&1;
}
/*
for (i1=0; i1 < nrows; i1++)
{
k=i1*Zc;
for (i3=0; i3 < Kb; i3++)
{
for (i4=0; i4 < no_shift_values[i1 * ncols + i3]; i4++)
{
channel_input[t+k] = channel_input[t+k] + c[ i3*Zc + Gen_shift_values[ i4] ];
}
}
channel_input[t+k]=channel_input[t+k]&1;
} channel_input=ldpc_encoder_header(test_input, block_length,rate);
*/
}
//stop_meas(&time);
// information part
memcpy(channel_input,c,Kb*Zc*sizeof(short));
stop_meas(&time); stop_meas(&time);
print_meas_now(&time, "", stdout); print_meas_now(&time, "", stdout);
//for (i=(Kb+nrows) * Zc-10;i<(Kb+nrows) * Zc;i++)
// printf("channel_input[%d]=%d\n",i,channel_input[i]);
//for (i=0;i<10;i++)
//printf("channel_input[%d]=%d test_input[%d]=%d\n",i,channel_input[i],i,test_input[i]);
/*
//channel //channel
modulated_input = (double *)malloc( (Kb+nrows) * Zc*sizeof(double)); modulated_input = (double *)malloc( (Kb+nrows) * Zc*sizeof(double));
//channel_output = (short *)malloc( (Kb+nrows) * Zc*sizeof(short)); channel_output = (double *)malloc( (Kb+nrows) * Zc*sizeof(double));
channel_output = (double *)malloc( (Kb+nrows) * Zc*sizeof(double)); channel_output_fixed = (short *)malloc( (Kb+nrows) * Zc*sizeof(short));
channel_output_fixed = (short *)malloc( (Kb+nrows) * Zc*sizeof(short)); memset(channel_output_fixed,0,(Kb+nrows) * Zc*sizeof(short));
memset(channel_output_fixed,0,(Kb+nrows) * Zc*sizeof(short));
for (i = 2*Zc; i < (Kb+nrows) * Zc; i++) { for (i = 2*Zc; i < (Kb+nrows) * Zc; i++)
#ifdef DEBUG_CODER {
#ifdef DEBUG_CODER
if ((i&0xf)==0) if ((i&0xf)==0)
printf("\ne %d..%d: ",i,i+15); printf("\ne %d..%d: ",i,i+15);
#endif #endif
//channel_output[i] = (short)quantize(sigma/4.0,(2.0*channel_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0),qbits);
if (channel_input[i]==0) if (channel_input[i]==0)
modulated_input[i]=1/sqrt(2); //QPSK modulated_input[i]=1/sqrt(2); //QPSK
else else
modulated_input[i]=-1/sqrt(2); modulated_input[i]=-1/sqrt(2);
channel_output[i] = modulated_input[i] + gaussdouble(0.0,1.0) * 1/sqrt(2*SNR); channel_output[i] = modulated_input[i] + gaussdouble(0.0,1.0) * 1/sqrt(2*SNR);
channel_output_fixed[i] = (short) ((channel_output[i]*128)<0?(channel_output[i]*128-0.5):(channel_output[i]*128+0.5)); //fixed point 9-7 channel_output_fixed[i] = (short) ((channel_output[i]*128)<0?(channel_output[i]*128-0.5):(channel_output[i]*128+0.5)); //fixed point 9-7
//printf("%lf %d\n",channel_output[i], channel_output_fixed[i]);
//printf("v[%d]=%lf\n",i,modulated_input[i]);
} }
//for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++) //for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++)
//{ //{
// printf("channel_input[%d]=%d\n",i,channel_input[i]); // printf("channel_input[%d]=%d\n",i,channel_input[i]);
//printf("%lf %d\n",channel_output[i], channel_output_fixed[i]); //printf("%lf %d\n",channel_output[i], channel_output_fixed[i]);
//printf("v[%d]=%lf\n",i,modulated_input[i]);} //printf("v[%d]=%lf\n",i,modulated_input[i]);}
#ifdef DEBUG_CODER #ifdef DEBUG_CODER
printf("\n"); printf("\n");
exit(-1); exit(-1);
#endif #endif
/* /*
esimated_output=ldpc_decoder(channel_output_fixed, block_length, No_iteration, rate); // decode the sequence
esimated_output=ldpc_decoder(channel_output_fixed, block_length, No_iteration, rate);
//for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++) //for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++)
// printf("esimated_output[%d]=%d\n",i,esimated_output[i]); // printf("esimated_output[%d]=%d\n",i,esimated_output[i]);
for (i=0;i<(Kb+nrows) * Zc;i++) { //count errors
for (i=0;i<(Kb+nrows) * Zc;i++)
if (esimated_output[i] != channel_input[i]) { {
if (esimated_output[i] != channel_input[i])
{
*errors = (*errors) + 1; *errors = (*errors) + 1;
break; break;
} }
} }
free(channel_input);
free(modulated_input);
free(channel_output);
free(channel_output_fixed);
*/ */
free(c);
free(channel_input);
free(modulated_input);
free(channel_output);
free(channel_output_fixed);
} }
//printf("%d\n",*errors);
return *errors; return *errors;
...@@ -326,48 +229,27 @@ int main(int argc, char *argv[]) ...@@ -326,48 +229,27 @@ int main(int argc, char *argv[])
{ {
unsigned int errors,crc_misses; unsigned int errors,crc_misses;
unsigned int block_length=22*384; short block_length=22*384;
short No_iteration=25; short No_iteration=25;
double rate=0.2; double rate=0.667;
double SNR,SNR_lin; double SNR,SNR_lin;
unsigned char qbits; unsigned char qbits;
//time_stats_t time;
int i=0; int i=0;
//opp_enabled=1;
// cpu_freq_GHz = get_cpu_freq_GHz();
randominit(0); randominit(0);
//logInit();
if (argc>1) if (argc>1)
qbits = atoi(argv[1]); qbits = atoi(argv[1]);
else else
qbits = 4; qbits = 4;
//printf("Quantization bits %d\n",qbits); unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to size of SNR
for (SNR=-2.1; SNR<-2; SNR+=.1)
unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to {
// size of SNR
for (SNR=-2.1; SNR<-2; SNR+=.1) {
SNR_lin = pow(10,SNR/10); SNR_lin = pow(10,SNR/10);
/*
ret = test_ldpc(coded_bits,
sigma, // noise standard deviation
qbits,
block_length, // block length bytes
NTRIALS,
&errors,
&trials,
&uerrors,
&crc_misses,
&iterations);
*/
// start_meas(&time);
decoded_errors[i]=test_ldpc(No_iteration, decoded_errors[i]=test_ldpc(No_iteration,
rate, rate,
SNR_lin, // noise standard deviation SNR_lin, // noise standard deviation
...@@ -376,17 +258,14 @@ int main(int argc, char *argv[]) ...@@ -376,17 +258,14 @@ int main(int argc, char *argv[])
NTRIALS, NTRIALS,
&errors, &errors,
&crc_misses); &crc_misses);
// stop_meas(&time);
//print_meas_now(&time, "", stdout);
printf("SNR %f, BLER %f (%d/%d)\n",SNR,(float)decoded_errors[i]/(float)NTRIALS,decoded_errors[i],NTRIALS); printf("SNR %f, BLER %f (%d/%d)\n",SNR,(float)decoded_errors[i]/(float)NTRIALS,decoded_errors[i],NTRIALS);
i=i+1; i=i+1;
} }
return(0); return(0);
} }
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "SIMULATION/TOOLS/defs.h" #include "SIMULATION/TOOLS/defs.h"
#include "Gen_shift_value.h" #include "Gen_shift_value.h"
#include "choose_generator_matrix.h"
#include "ldpc_encoder_header.h"
// 4-bit quantizer // 4-bit quantizer
char quantize4bit(double D,double x) char quantize4bit(double D,double x)
...@@ -70,7 +72,7 @@ int test_ldpc(short No_iteration, ...@@ -70,7 +72,7 @@ int test_ldpc(short No_iteration,
double rate, double rate,
double SNR, double SNR,
unsigned char qbits, unsigned char qbits,
unsigned int block_length, short block_length,
unsigned int ntrials, unsigned int ntrials,
unsigned int *errors, unsigned int *errors,
unsigned int *crc_misses) unsigned int *crc_misses)
...@@ -81,8 +83,9 @@ int test_ldpc(short No_iteration, ...@@ -81,8 +83,9 @@ int test_ldpc(short No_iteration,
opp_enabled=1; opp_enabled=1;
cpu_freq_GHz = get_cpu_freq_GHz(); cpu_freq_GHz = get_cpu_freq_GHz();
short test_input[block_length]; //short test_input[block_length];
short *c; //padded codeword short *test_input;
//short *c; //padded codeword
short *esimated_output; short *esimated_output;
short *channel_input; short *channel_input;
double *channel_output; double *channel_output;
...@@ -90,40 +93,43 @@ int test_ldpc(short No_iteration, ...@@ -90,40 +93,43 @@ int test_ldpc(short No_iteration,
short *channel_output_fixed; short *channel_output_fixed;
unsigned int i,trial=0; unsigned int i,trial=0;
/*
short *Gen_shift_values, *no_shift_values, *pointer_shift_values; short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
short BG,Zc,Kb,nrows,ncols; short BG,Zc,Kb,nrows,ncols,channel_temp;
int i1,i2,i3,i4,i5,i6,t,temp,k; int i1,i2,i3,i4,i5,i6,t,temp,temp_prime,k;
int no_punctured_columns; //new
//Table of possible lifting sizes //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}; 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};
*/
*errors=0; *errors=0;
*crc_misses=0; *crc_misses=0;
while (trial++ < ntrials) { while (trial++ < ntrials)
{
// generate input block // generate input block
for (i=0; i<block_length; i++) { test_input=(short*)malloc(sizeof(short) * block_length);
for (i=0; i<block_length; i++)
//test_input[i] = (unsigned char)(taus()&0xff); {
test_input[i]=rand()%2; test_input[i]=rand()%2;
//test_input[i]=i%2; //test_input[i]=i%2;
} }
start_meas(&time);
//determine number of bits in codeword /*
//determine number of bits in codeword
if (block_length>3840) if (block_length>3840)
{ {
BG=1; BG=1;
Kb = 22; Kb = 22;
nrows=46; nrows=46; //parity check bits
ncols=22; ncols=22; //info bits
} }
else if (block_length<=3840) else if (block_length<=3840)
{ {
BG=2; BG=2;
nrows=42; nrows=42; //parity check bits
ncols=10; ncols=10; // info bits
if (block_length>640) if (block_length>640)
Kb = 10; Kb = 10;
else if (block_length>560) else if (block_length>560)
...@@ -134,7 +140,7 @@ for (i=0; i<block_length; i++) { ...@@ -134,7 +140,7 @@ for (i=0; i<block_length; i++) {
Kb = 6; Kb = 6;
} }
//find minimum value in all sets of lifting size //find minimum value in all sets of lifting size
for (i1=0; i1 < 51; i1++) for (i1=0; i1 < 51; i1++)
{ {
if (lift_size[i1] >= (double) block_length/Kb) if (lift_size[i1] >= (double) block_length/Kb)
...@@ -145,173 +151,74 @@ for (i=0; i<block_length; i++) { ...@@ -145,173 +151,74 @@ for (i=0; i<block_length; i++) {
} }
} }
// load base graph of generator matrix no_punctured_columns=(int)((nrows+Kb-2)*Zc-block_length/rate)/Zc;
if (BG==1) //printf("%d\n",no_punctured_columns);
{
no_shift_values=(short*) no_shift_values_BG1;
pointer_shift_values=(short*) pointer_shift_values_BG1;
if (Zc==2||Zc==4||Zc==8||Zc==16||Zc==32||Zc==64||Zc==128||Zc==256)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_2;
// else if (Zc==3||Zc==6||Zc==12||Zc==24||Zc==48||Zc==96||Zc==192||Zc==384)
//Gen_shift_values=(short*) Gen_shift_values_BG1_a_3;
else if (Zc==384)
Gen_shift_values=(short*) Gen_shift_values_BG1_Z_384;
else if (Zc==5||Zc==10||Zc==20||Zc==40||Zc==80||Zc==160||Zc==320)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_5;
else if (Zc==7||Zc==14||Zc==28||Zc==56||Zc==112||Zc==224)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_7;
else if (Zc==9||Zc==18||Zc==36||Zc==72||Zc==144||Zc==288)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_9;
else if (Zc==11||Zc==22||Zc==44||Zc==88||Zc==176||Zc==352)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_11;
else if (Zc==13||Zc==26||Zc==52||Zc==104||Zc==208)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_13;
else if (Zc==15||Zc==30||Zc==60||Zc==120||Zc==240)
Gen_shift_values=(short*) Gen_shift_values_BG1_a_15;
}
else if (BG==2)
{
no_shift_values=(short*) no_shift_values_BG2;
pointer_shift_values=(short*) pointer_shift_values_BG2;
//if (Zc==2||Zc==4||Zc==8||Zc==16||Zc==32||Zc==64||Zc==128||Zc==256)
// Gen_shift_values=(short*) Gen_shift_values_BG2_a_2;
if (Zc==128)
Gen_shift_values=(short*) Gen_shift_values_BG2_Z_128;
else if (Zc==3||Zc==6||Zc==12||Zc==24||Zc==48||Zc==96||Zc==192||Zc==384)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_3;
else if (Zc==5||Zc==10||Zc==20||Zc==40||Zc==80||Zc==160||Zc==320)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_5;
else if (Zc==7||Zc==14||Zc==28||Zc==56||Zc==112||Zc==224)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_7;
else if (Zc==9||Zc==18||Zc==36||Zc==72||Zc==144||Zc==288)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_9;
else if (Zc==11||Zc==22||Zc==44||Zc==88||Zc==176||Zc==352)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_11;
else if (Zc==13||Zc==26||Zc==52||Zc==104||Zc==208)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_13;
else if (Zc==15||Zc==30||Zc==60||Zc==120||Zc==240)
Gen_shift_values=(short*) Gen_shift_values_BG2_a_15;
}
c=(short *)malloc(sizeof(short) * Kb * Zc);
channel_input = (short *)malloc( (Kb+nrows) * Zc *sizeof(short));
//padded input sequence
memset(c,0,sizeof(short) * Kb * Zc);
memcpy(c,test_input,block_length * sizeof(short));
//start_meas(&time);
//encode the input sequence
memset(channel_input,0,(Kb+nrows) * Zc*sizeof(short));
// parity check part
for (i2=0; i2 < Zc; i2++)
{
t=Kb*Zc+i2;
//rotate matrix here
for (i5=0; i5 < Kb; i5++)
{
temp = c[i5*Zc];
memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(short));
c[i5*Zc+Zc-1] = temp;
//for (i6 = 0; i6 < Zc-1; i6++)
//for (i6 = i5*Zc; i6 < i5*Zc + Zc-1; i6++)
//{
//c[i5*Zc+i6] = c[i5*Zc+i6+1];
//c[i6] = c[i6+1];
//}
//c[i5*Zc+i6] = temp;
//c[i6] = temp;
}
/*
for (i1=0; i1 < nrows; i1++)
{
for (i3=0; i3 < Kb; i3++)
{
for (i4=0; i4 < no_shift_values[i1 * ncols + i3]; i4++)
{
channel_input[t+i1*Zc] = channel_input[t+i1*Zc] + c[ i3*Zc + Gen_shift_values[ pointer_shift_values[i1 * ncols + i3]+i4 ] ];
}
}
channel_input[t+i1*Zc]=channel_input[t+i1*Zc]&1;
}
*/ */
for (i1=0; i1 < nrows; i1++) start_meas(&time);
{ //// encoder
k=i1*Zc;
for (i3=0; i3 < Kb; i3++)
{
for (i4=0; i4 < no_shift_values[i1 * ncols + i3]; i4++)
{
channel_input[t+k] = channel_input[t+k] + c[ i3*Zc + Gen_shift_values[ i4] ];
}
}
channel_input[t+k]=channel_input[t+k]&1;
} channel_input=ldpc_encoder_header(test_input, block_length,rate);
}
//stop_meas(&time);
// information part
memcpy(channel_input,c,Kb*Zc*sizeof(short));
stop_meas(&time); stop_meas(&time);
print_meas_now(&time, "", stdout); print_meas_now(&time, "", stdout);
//for (i=(Kb+nrows) * Zc-10;i<(Kb+nrows) * Zc;i++)
// printf("channel_input[%d]=%d\n",i,channel_input[i]);
//for (i=0;i<10;i++)
//printf("channel_input[%d]=%d test_input[%d]=%d\n",i,channel_input[i],i,test_input[i]);
/*
//channel //channel
modulated_input = (double *)malloc( (Kb+nrows) * Zc*sizeof(double)); modulated_input = (double *)malloc( (Kb+nrows) * Zc*sizeof(double));
//channel_output = (short *)malloc( (Kb+nrows) * Zc*sizeof(short)); channel_output = (double *)malloc( (Kb+nrows) * Zc*sizeof(double));
channel_output = (double *)malloc( (Kb+nrows) * Zc*sizeof(double)); channel_output_fixed = (short *)malloc( (Kb+nrows) * Zc*sizeof(short));
channel_output_fixed = (short *)malloc( (Kb+nrows) * Zc*sizeof(short)); memset(channel_output_fixed,0,(Kb+nrows) * Zc*sizeof(short));
memset(channel_output_fixed,0,(Kb+nrows) * Zc*sizeof(short));
for (i = 2*Zc; i < (Kb+nrows) * Zc; i++) { for (i = 2*Zc; i < (Kb+nrows) * Zc; i++)
#ifdef DEBUG_CODER {
#ifdef DEBUG_CODER
if ((i&0xf)==0) if ((i&0xf)==0)
printf("\ne %d..%d: ",i,i+15); printf("\ne %d..%d: ",i,i+15);
#endif #endif
//channel_output[i] = (short)quantize(sigma/4.0,(2.0*channel_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0),qbits);
if (channel_input[i]==0) if (channel_input[i]==0)
modulated_input[i]=1/sqrt(2); //QPSK modulated_input[i]=1/sqrt(2); //QPSK
else else
modulated_input[i]=-1/sqrt(2); modulated_input[i]=-1/sqrt(2);
channel_output[i] = modulated_input[i] + gaussdouble(0.0,1.0) * 1/sqrt(2*SNR); channel_output[i] = modulated_input[i] + gaussdouble(0.0,1.0) * 1/sqrt(2*SNR);
channel_output_fixed[i] = (short) ((channel_output[i]*128)<0?(channel_output[i]*128-0.5):(channel_output[i]*128+0.5)); //fixed point 9-7 channel_output_fixed[i] = (short) ((channel_output[i]*128)<0?(channel_output[i]*128-0.5):(channel_output[i]*128+0.5)); //fixed point 9-7
//printf("%lf %d\n",channel_output[i], channel_output_fixed[i]);
//printf("v[%d]=%lf\n",i,modulated_input[i]);
} }
//for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++) //for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++)
//{ //{
// printf("channel_input[%d]=%d\n",i,channel_input[i]); // printf("channel_input[%d]=%d\n",i,channel_input[i]);
//printf("%lf %d\n",channel_output[i], channel_output_fixed[i]); //printf("%lf %d\n",channel_output[i], channel_output_fixed[i]);
//printf("v[%d]=%lf\n",i,modulated_input[i]);} //printf("v[%d]=%lf\n",i,modulated_input[i]);}
#ifdef DEBUG_CODER #ifdef DEBUG_CODER
printf("\n"); printf("\n");
exit(-1); exit(-1);
#endif #endif
/* /*
esimated_output=ldpc_decoder(channel_output_fixed, block_length, No_iteration, rate); // decode the sequence
esimated_output=ldpc_decoder(channel_output_fixed, block_length, No_iteration, rate);
//for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++) //for (i=(Kb+nrows) * Zc-5;i<(Kb+nrows) * Zc;i++)
// printf("esimated_output[%d]=%d\n",i,esimated_output[i]); // printf("esimated_output[%d]=%d\n",i,esimated_output[i]);
for (i=0;i<(Kb+nrows) * Zc;i++) { //count errors
for (i=0;i<(Kb+nrows) * Zc;i++)
if (esimated_output[i] != channel_input[i]) { {
if (esimated_output[i] != channel_input[i])
{
*errors = (*errors) + 1; *errors = (*errors) + 1;
break; break;
} }
} }
free(channel_input);
free(modulated_input);
free(channel_output);
free(channel_output_fixed);
*/ */
free(c);
free(channel_input);
free(modulated_input);
free(channel_output);
free(channel_output_fixed);
} }
//printf("%d\n",*errors);
return *errors; return *errors;
...@@ -324,48 +231,27 @@ int main(int argc, char *argv[]) ...@@ -324,48 +231,27 @@ int main(int argc, char *argv[])
{ {
unsigned int errors,crc_misses; unsigned int errors,crc_misses;
unsigned int block_length=22*384; short block_length=22*384;
short No_iteration=25; short No_iteration=25;
double rate=0.2; double rate=0.667;
double SNR,SNR_lin; double SNR,SNR_lin;
unsigned char qbits; unsigned char qbits;
//time_stats_t time;
int i=0; int i=0;
//opp_enabled=1;
// cpu_freq_GHz = get_cpu_freq_GHz();
randominit(0); randominit(0);
//logInit();
if (argc>1) if (argc>1)
qbits = atoi(argv[1]); qbits = atoi(argv[1]);
else else
qbits = 4; qbits = 4;
//printf("Quantization bits %d\n",qbits); unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to size of SNR
for (SNR=-2.1; SNR<-2; SNR+=.1)
unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to {
// size of SNR
for (SNR=-2.1; SNR<-2; SNR+=.1) {
SNR_lin = pow(10,SNR/10); SNR_lin = pow(10,SNR/10);
/*
ret = test_ldpc(coded_bits,
sigma, // noise standard deviation
qbits,
block_length, // block length bytes
NTRIALS,
&errors,
&trials,
&uerrors,
&crc_misses,
&iterations);
*/
// start_meas(&time);
decoded_errors[i]=test_ldpc(No_iteration, decoded_errors[i]=test_ldpc(No_iteration,
rate, rate,
SNR_lin, // noise standard deviation SNR_lin, // noise standard deviation
...@@ -374,17 +260,14 @@ int main(int argc, char *argv[]) ...@@ -374,17 +260,14 @@ int main(int argc, char *argv[])
NTRIALS, NTRIALS,
&errors, &errors,
&crc_misses); &crc_misses);
// stop_meas(&time);
//print_meas_now(&time, "", stdout);
printf("SNR %f, BLER %f (%d/%d)\n",SNR,(float)decoded_errors[i]/(float)NTRIALS,decoded_errors[i],NTRIALS); printf("SNR %f, BLER %f (%d/%d)\n",SNR,(float)decoded_errors[i]/(float)NTRIALS,decoded_errors[i],NTRIALS);
i=i+1; i=i+1;
} }
return(0); return(0);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment