module: ph_approx_lut_5bit_dtc25_noncenter
description: phase LUT approximation ph = 1/V * cos()*sin()
             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, double bit10
outputs:  double t_compen
classes: List list1()  
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 tau_table[32] double luttmp[1024]
                  double one_msb double pulsewidth[24]  
init:  
   list1.load("c:/CppSim/SimRuns/Pwm_polar_tx/distortion_dpa_10bit_tst/table.dat");
   list1.reset();
   for(nn=1023; nn>=0; nn--){
      luttmp[nn] = list1.read();
   }

   pulsewidth[0] = 0;
   pulsewidth[1] = 35;
   for(nn=2; nn<24; 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("tau = %e   v_eq = %e\n", pulsewidth[nn], 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;
      tau_table[nn]=pulsewidth[ind];
      printf("lut[%d] = %e tau_table[%d] = %e\n",nn,lut[nn],nn,tau_table[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. digpre_lut_4bit_center\n");
      printf("bit5 = %f\n",bit5);
   }
   else{
      one_msb = luttmp[ (int)bit10+1 ]- luttmp[ (int)bit10 ];
      tau = tau_table[ (int)bit5 ];
      t_compen = cos(3.141592*tau/T)*sin(3.141592*tau/T);
      t_compen = (1/luttmp[ (int)bit10 ]*one_msb) * t_compen;
      t_compen = T*1e-12/6.2831853*t_compen;
   }


functions:  
custom_classes_definition:  
custom_classes_code:  
