diff --git a/openair1/PHY/CODING/ldpc_encoder.c b/openair1/PHY/CODING/ldpc_encoder.c
index 8cd86e883b13e52b3ac3fb372fd64fc9c780b3bf..bac5333ac05873e7939ebb06a91265015271ef62 100644
--- a/openair1/PHY/CODING/ldpc_encoder.c
+++ b/openair1/PHY/CODING/ldpc_encoder.c
@@ -5520,6 +5520,72 @@ int encode_parity_check_part(unsigned char *c,unsigned char *d, short BG,short Z
   return 0;
 }
 
+short *choose_generator_matrix(short BG,short Zc);
+extern short no_shift_values_BG1[1012],pointer_shift_values_BG1[1012],no_shift_values_BG2[2109],pointer_shift_values_BG2[2019];
+
+int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb)
+{
+  short *Gen_shift_values=choose_generator_matrix(BG,Zc);
+  short *no_shift_values, *pointer_shift_values;
+  int no_punctured_columns;
+  short nrows,ncols;
+  int i1,i2,i3,i4,i5,t,temp_prime;
+  unsigned char channel_temp,temp;
+  short block_length=Zc*Kb;
+
+  if (BG==1)
+  {
+    no_shift_values=(short *) no_shift_values_BG1;
+    pointer_shift_values=(short *) pointer_shift_values_BG1;
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+  }
+  else if (BG==2)
+  {
+    no_shift_values=(short *) no_shift_values_BG2;
+    pointer_shift_values=(short *) pointer_shift_values_BG2;
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+  }
+  else {
+    printf("problem with BG\n");
+    return(-1);
+  }
+
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc;
+
+  for (i2=0; i2 < 1; 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(unsigned char));
+      c[i5*Zc+Zc-1] = temp;
+    }
+
+    // calculate each row in base graph
+    for (i1=0; i1 < nrows-no_punctured_columns; i1++)
+    {
+      channel_temp=0;
+      for (i3=0; i3 < Kb; i3++)
+      {
+        temp_prime=i1 * ncols + i3;
+
+        for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
+        {
+          channel_temp = channel_temp ^ c[ i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ];
+        }
+      }
+      d[t+i1*Zc]=channel_temp;
+      //channel_input[t+i1*Zc]=channel_temp;
+    }
+  }
+  return(0);
+}
+
 int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short block_length,double rate)
 {
   unsigned char c[22*384]; //padded input, unpacked, max size
@@ -5531,39 +5597,44 @@ int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short bl
   //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};
   //determine number of bits in codeword
-  //if (block_length>3840)
-  //{
-  BG=1;
-  Kb = 22;
-  nrows=46; //parity check bits
-  ncols=22; //info bits
-  //}
-  /* else if (block_length<=3840)
-  {
-    BG=2;
-    nrows=42; //parity check bits
-    ncols=10; // info bits
-
-    if (block_length>640)
-      Kb = 10;
-    else if (block_length>560)
-      Kb = 9;
-    else if (block_length>192)
-      Kb = 8;
-    else
-      Kb = 6;
-  } */
-
+  if (block_length>3840)
+    {
+      BG=1;
+      Kb = 22;
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+    }
+  else if (block_length<=3840)
+    {
+      BG=2;
+      nrows=42; //parity check bits
+      ncols=10; // info bits
+      
+      if (block_length>640)
+	Kb = 10;
+      else if (block_length>560)
+	Kb = 9;
+      else if (block_length>192)
+	Kb = 8;
+      else
+	Kb = 6;
+    } 
+    
   //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)
+    if (lift_size[i1] >= block_length/Kb)
     {
       Zc = lift_size[i1];
       //printf("%d\n",Zc);
       break;
     }
   }
+  if ((Kb*Zc)!=block_length) {
+    printf("Cannot determine lift size Zc\n");
+    return(-1);
+  }
 
   // calculate number of punctured bits
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc;
@@ -5580,15 +5651,31 @@ int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short bl
     c[i]=(test_input[i/8]&(1<<(i&7)))>>(i&7);
   }
 
-  // extend matrix
-  for (i1=0; i1 < ncols; i1++)
-  {
-    memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));   /// change type here
-    memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+  if (BG==1) {
+    // extend matrix
+    for (i1=0; i1 < ncols; i1++)
+      {
+	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));   /// change type here
+	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+      }
+    
+    //parity check part
+    if (encode_parity_check_part(c_extension, d, BG, Zc, Kb)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  else if (BG==1) {
+    if (encode_parity_check_part_orig(c, d, BG, Zc, Kb)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  else {
+      printf("Problem with encoder\n");
+      return(-1);
   }
 
-  //parity check part
-  encode_parity_check_part(c_extension, d, BG, Zc, Kb);
   // 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));
diff --git a/openair1/PHY/CODING/ldpc_generate_coefficient.c b/openair1/PHY/CODING/ldpc_generate_coefficient.c
index 968da51e6d2d452525459f64e3f5d62dc3007160..50bb1df2b6af81f49962e9cf2865fb47a788edc5 100644
--- a/openair1/PHY/CODING/ldpc_generate_coefficient.c
+++ b/openair1/PHY/CODING/ldpc_generate_coefficient.c
@@ -387,8 +387,8 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
 
   Gen_shift_values=choose_generator_matrix(BG,Zc);
   // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length/rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/rate);
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*3);
   //printf("%d\n",no_punctured_columns);
   //printf("%d\n",removed_bit);
   // unpack input