Commit 34746b24 authored by wang's avatar wang

update ldpc encoder segmentation

parent 0b5394b5
This diff is collapsed.
...@@ -571,7 +571,8 @@ uint32_t crcbit (uint8_t * , ...@@ -571,7 +571,8 @@ uint32_t crcbit (uint8_t * ,
int16_t reverseBits(int32_t ,int32_t); int16_t reverseBits(int32_t ,int32_t);
void phy_viterbi_dot11(int8_t *,uint8_t *,uint16_t); void phy_viterbi_dot11(int8_t *,uint8_t *,uint16_t);
short *ldpc_decoder(short *msgChannel,short block_length,short No_iteration,double rate); //short *ldpc_decoder(short *msgChannel,short block_length,short No_iteration,double rate);
short *ldpc_encoder(char *test_input,char* channel_input,short block_length,double rate); //short *ldpc_encoder(char *test_input,char* channel_input,short block_length,double rate);
int ldpc_encoder(unsigned char *test_input,unsigned char* channel_input,short block_length,double rate);
#endif #endif
...@@ -116,11 +116,14 @@ short *choose_generator_matrix(short BG,short Zc) ...@@ -116,11 +116,14 @@ short *choose_generator_matrix(short BG,short Zc)
break; break;
} }
} }
/*
else if (BG==2) else if (BG==2)
{
switch (Zc)
{ {
case 2: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_2; case 2: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_2;
break; break;
/*
case 3: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_3; case 3: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_3;
break; break;
case 4: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_4; case 4: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_4;
...@@ -195,8 +198,10 @@ short *choose_generator_matrix(short BG,short Zc) ...@@ -195,8 +198,10 @@ short *choose_generator_matrix(short BG,short Zc)
break; break;
case 120: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_120; case 120: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_120;
break; break;
*/
case 128: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_128; case 128: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_128;
break; break;
/*
case 144: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_144; case 144: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_144;
break; break;
case 160: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_160; case 160: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_160;
...@@ -221,31 +226,34 @@ short *choose_generator_matrix(short BG,short Zc) ...@@ -221,31 +226,34 @@ short *choose_generator_matrix(short BG,short Zc)
break; break;
case 384: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_384; case 384: Gen_shift_values=(short*) Gen_shift_values_BG2_Z_384;
break; break;
}
*/ */
}
}
return Gen_shift_values; return Gen_shift_values;
} }
int ldpc_encoder(char *test_input,char* channel_input,short block_length,double rate) int ldpc_encoder(unsigned char *test_input,unsigned char* channel_input,short block_length,double rate)
{ {
char c[22*384]; //padded input, unpacked, max size unsigned char c[22*384]; //padded input, unpacked, max size
char d[68*384]; //coded output, 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 *Gen_shift_values, *no_shift_values, *pointer_shift_values;
short BG,Zc,Kb,nrows,ncols,channel_temp; short BG,Zc,Kb,nrows,ncols;
int i,i1,i2,i3,i4,i5,t,temp,temp_prime; int i,i1,i2,i3,i4,i5,t,t1,temp_prime;
int no_punctured_columns,output_length; int no_punctured_columns,removed_bit;
//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};
//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; //parity check bits nrows=46; //parity check bits
ncols=22; //info bits ncols=22; //info bits
} /* }
else if (block_length<=3840) else if (block_length<=3840)
{ {
BG=2; BG=2;
...@@ -259,7 +267,7 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double ...@@ -259,7 +267,7 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double
Kb = 8; Kb = 8;
else else
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++)
...@@ -286,14 +294,21 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double ...@@ -286,14 +294,21 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double
} }
Gen_shift_values=choose_generator_matrix(BG,Zc); Gen_shift_values=choose_generator_matrix(BG,Zc);
no_punctured_columns=(int)((nrows+Kb-2)*Zc-block_length/rate)/Zc; no_punctured_columns=(int)((nrows+Kb-2)*Zc-block_length/rate)/Zc;
removed_bit=(Kb+nrows-no_punctured_columns-2) * Zc-(int)(block_length/rate);
//printf("%d\n",no_punctured_columns); //printf("%d\n",no_punctured_columns);
output_length = (Kb+nrows-no_punctured_columns) * Zc; //output_length = (Kb+nrows-no_punctured_columns) * Zc;
// unpack input // unpack input
memset(c,0,sizeof(unsigned char) * Kb * Zc);
for (i=0;i<block_length;i++) for (i=0;i<block_length;i++)
c[i] = (test_input[i/8]>>(i%8))&1; {
//c[i] = test_input[i/8]<<(i%8);
// c[i]=c[i]>>7&1;
c[i]=(test_input[i/8]&(1<<(i&7)))>>(i&7);
}
// parity check part // parity check part
for (i2=0; i2 < Zc; i2++) for (i2=0; i2 < Zc; i2++)
...@@ -303,7 +318,7 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double ...@@ -303,7 +318,7 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double
for (i5=0; i5 < Kb; i5++) for (i5=0; i5 < Kb; i5++)
{ {
temp = c[i5*Zc]; temp = c[i5*Zc];
memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(short)); memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
c[i5*Zc+Zc-1] = temp; c[i5*Zc+Zc-1] = temp;
} }
...@@ -321,17 +336,31 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double ...@@ -321,17 +336,31 @@ int ldpc_encoder(char *test_input,char* channel_input,short block_length,double
} }
d[t+i1*Zc]=channel_temp; d[t+i1*Zc]=channel_temp;
//channel_input[t+i1*Zc]=channel_temp;
} }
} }
// information part // information part
memcpy(d,c,Kb*Zc*sizeof(short)); memcpy(d,c,Kb*Zc*sizeof(unsigned char));
// puncture columns
for (i = 2*Zc,t1=0; i < (Kb+nrows-no_punctured_columns) * Zc-removed_bit; i++)
{
channel_input[t1]=d[i];
t1++;
}
//memcpy(channel_input,c,Kb*Zc*sizeof(unsigned char));
/*
//pack into output //pack into output
memset(channel_input,0,output_length/8*sizeof(char)); memset(channel_input,0,output_length/8*sizeof(unsigned char));
for (i=0;i<output_length;i++) for (i=0;i<output_length;i++)
channel_input[i/8] = channel_input[i/8] | (d[i] << (i%8)); {
//printf("[%d]=%d\n",i,d[i]);
d[i]=d[i] << 7;
channel_input[i/8] = channel_input[i/8] | (d[i] >> (i%8));
}
*/
return 0; return 0;
} }
...@@ -53,9 +53,9 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -53,9 +53,9 @@ int32_t nr_segmentation(unsigned char *input_buffer,
*C=*C+1; *C=*C+1;
Bprime = B+((*C)*L); Bprime = B+((*C)*L);
#ifdef DEBUG_SEGMENTATION //#ifdef DEBUG_SEGMENTATION
printf("Bprime %d\n",Bprime); printf("Bprime %d\n",Bprime);
#endif //#endif
} }
if ((*C)>MAX_NUM_DLSCH_SEGMENTS) { if ((*C)>MAX_NUM_DLSCH_SEGMENTS) {
...@@ -65,7 +65,7 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -65,7 +65,7 @@ int32_t nr_segmentation(unsigned char *input_buffer,
// Find K+ // Find K+
Bprime_by_C = Bprime/(*C); Bprime_by_C = Bprime/(*C);
if (Bprime <=192) { /*if (Bprime <=192) {
Kb = 6; Kb = 6;
} else if (Bprime <=560) { } else if (Bprime <=560) {
Kb = 8; Kb = 8;
...@@ -73,11 +73,17 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -73,11 +73,17 @@ int32_t nr_segmentation(unsigned char *input_buffer,
Kb = 9; Kb = 9;
} else if (Bprime <=3840) { } else if (Bprime <=3840) {
Kb = 10;; Kb = 10;;
} else { } else {*/
Kb = 22; Kb = 22;
} //}
if ((Bprime_by_C%Kb) > 0)
Z = (Bprime_by_C/Kb)+1; Z = (Bprime_by_C/Kb)+1;
else
Z = (Bprime_by_C/Kb);
printf("nr segmetation B %d Bprime %d Bprime_by_C %d z %d \n", B, Bprime, Bprime_by_C, Z);
if (Z <= 2) { if (Z <= 2) {
*Kplus = 2; *Kplus = 2;
...@@ -106,9 +112,9 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -106,9 +112,9 @@ int32_t nr_segmentation(unsigned char *input_buffer,
if (*Kplus < Z) if (*Kplus < Z)
*Kplus = *Kplus + 8; *Kplus = *Kplus + 8;
#ifdef DEBUG_SEGMENTATION //#ifdef DEBUG_SEGMENTATION
printf("Z_by_C %d , Kplus2 %d\n",Z,*Kplus); printf("Z_by_C %d , Kplus2 %d\n",Z,*Kplus);
#endif //#endif
*Kminus = (*Kplus - 8); *Kminus = (*Kplus - 8);
} else if (Z <= 256) { // increase by 4 bytes til here } else if (Z <= 256) { // increase by 4 bytes til here
*Kplus = (Z>>4)<<4; *Kplus = (Z>>4)<<4;
...@@ -128,13 +134,14 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -128,13 +134,14 @@ int32_t nr_segmentation(unsigned char *input_buffer,
//msg("nr_segmentation.c: Illegal codeword size !!!\n"); //msg("nr_segmentation.c: Illegal codeword size !!!\n");
return(-1); return(-1);
} }
*Zout = *Kplus;
*Kplus = *Kplus*Kb; *Kplus = *Kplus*Kb;
*Kminus = *Kminus*Kb; *Kminus = *Kminus*Kb;
*Zout = Z;
*F = ((*C)*(*Kplus) - (Bprime)); *F = ((*C)*(*Kplus) - (Bprime));
printf("final nr seg output Z %d Kplus %d F %d \n", *Zout, *Kplus, *F);
#ifdef DEBUG_SEGMENTATION #ifdef DEBUG_SEGMENTATION
printf("C %d, Kplus %d, Kminus %d, Bprime_bytes %d, Bprime %d, F %d\n",*C,*Kplus,*Kminus,Bprime>>3,Bprime,*F); printf("C %d, Kplus %d, Kminus %d, Bprime_bytes %d, Bprime %d, F %d\n",*C,*Kplus,*Kminus,Bprime>>3,Bprime,*F);
#endif #endif
...@@ -149,10 +156,10 @@ int32_t nr_segmentation(unsigned char *input_buffer, ...@@ -149,10 +156,10 @@ int32_t nr_segmentation(unsigned char *input_buffer,
for (r=0; r<*C; r++) { for (r=0; r<*C; r++) {
if (r<(B%(*C))) //if (r<(B%(*C)))
Kprime = *Kplus; Kprime = *Kplus;
else //else
Kprime = *Kminus; // Kprime = *Kminus;
while (k<((Kprime - L)>>3)) { while (k<((Kprime - L)>>3)) {
output_buffers[r][k] = input_buffer[s]; output_buffers[r][k] = input_buffer[s];
......
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