module: amp_lut_5bit_dtc25_pwm_noncenter
description: amplitude LUT approximation v = sin(pi*tau/T)sin(pi*tau/T)
             Digital Predistortion for PWM noncenter 6bit(LSB) input
             dtc25
             Assuming 960ps period.
             0 <= bit6 < 64
             Coded by Min Park 03/14/09 (converted 10/10/10) 
parameters:  
inputs:  double bit5
outputs:  double dtc25out
classes:  
static_variables: double err int nn double err_dis[24]
                  double tau double v_eq double lut[32]
                  double err_q5 int ind int mm double minerrdiff
                  double T double pulsewidth[25]  
init:  
   pulsewidth[0] = 0;
   pulsewidth[1] = 35;
   for(nn=2; nn<25; nn++){
      pulsewidth[nn]=pulsewidth[nn-1]+20;
   }

   T= 960;

   for( nn=0; nn<24 ; nn++){
      tau = pulsewidth[nn];
      v_eq = sin( 3.141592 * tau / T)*sin( 3.141592 * tau / T);
      printf("v_eq = %e\n", v_eq);
      err_dis[nn] = v_eq;
      // Assuming the maximum q error is 1.
   }

   err_q5 = 0.0;
   for( nn=0; nn<32 ; nn++){
      ind = 0;
      minerrdiff = 1e6;
      for( mm=0 ; mm < 24; mm++){
         if( fabs( err_q5 - err_dis[mm]) < minerrdiff ){
            minerrdiff = fabs( err_q5 - err_dis[mm] );
            ind = mm;
         }
      }
      lut[nn] = (double)ind;
      printf("lut[%d] = %e\n",nn,lut[nn]);
      err_q5 += 1.0/32.0;
      // Assuming the maximum q error is 1.
      // Then the q error for 5-bit is 1/32. 
   }

end:  
code:  
   if( bit5 < 0 || bit5 > 32 ){
      printf("Error! bit5 is out of range. amp_lut_dtc25_noncenter\n");
      printf("bit5 = %f\n",bit5);
   }
   else{
      dtc25out = lut[ (int)bit5 ];
   }


functions:  
custom_classes_definition:  
custom_classes_code:  
