Changeset 1228 for applications/pmsm

Show
Ignore:
Timestamp:
10/22/10 22:06:23 (14 years ago)
Author:
smidl
Message:

UD hopefully correct

Location:
applications/pmsm/simulator_zdenek
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp

    r1225 r1228  
    1919void mmultAU(int *m1, int *up, int *result, unsigned int rows, unsigned int columns) { 
    2020    unsigned int i, j, k; 
    21     long tmp_sum=0L; 
     21    long tmp_sum=0L; //in 15+qAU 
    2222    int *m2pom; 
    2323    int *m1pom=m1; 
     
    3232            for (k=0; k<j; k++) //inner loop up to "j" - U(j,j)==1; 
    3333            { 
    34                 tmp_sum+=(long)(*(m1pom++))**m2pom; 
     34                tmp_sum+=((long)(*(m1pom++))**m2pom)>>(15-qAU); 
    3535                m2pom+=columns; 
    3636            } 
    3737            // add the missing A(i,j) 
    38             tmp_sum +=(long)(*m1pom)<<15; // no need to shift 
     38            tmp_sum +=(long)(*m1pom)<<qAU; // no need to shift 
    3939            m1pom-=(j); // shift back to first element 
    4040 
    4141            // saturation effect 
    42             tmp_sum=tmp_sum>>(30-qAU); 
     42            tmp_sum=tmp_sum>>15; 
    4343            if (tmp_sum>32767) { 
    4444                //tmp_sum=32767; 
     
    136136        for (j=0;j<rows; j++) { 
    137137            //long s1=(((long)PSIU[i+j*rows]*PSIU[i+j*rows])>>15)*(Dold[i]); 
    138             long s2=((((long)PSIU[i*rows+j]*Dold[j])>>qAU)*PSIU[i*rows+j])<<(15-qAU); 
     138            long s2=((((long)PSIU[i*rows+j]*PSIU[i*rows+j]))>>(2*qAU-15))*Dold[j]; 
    139139//                      printf("%d - %d\n",s1,s2); 
    140140            sigma += s2; 
     
    146146        } 
    147147 
    148         //if (sigma>16384<<15) sigma = 16384<<15; 
     148//        if (sigma>16384<<15) sigma = 16384<<15; 
    149149        *(D+i)=sigma>>15; 
    150150        if (D[i]==0) D[i]=1; 
     
    155155            sigma =0; 
    156156            for (k=0;k<rows;k++) { 
    157                 sigma += (((long(PSIU[i*rows+k])*Dold[k])>>qAU)*PSIU[j*rows+k])<<(15-qAU); 
     157                                sigma += (((long(PSIU[i*rows+k])*PSIU[j*rows+k]))>>(2*qAU-15))*Dold[k]; 
    158158            } 
    159159            for (k=0;k<rows;k++) { 
     
    266266        for (k=0, PSIU_ik=PSIU+irows,Dold_k=Dold; 
    267267                k<rows; k++, PSIU_ik++,Dold_k++) {//Dold_i= 
    268             sigma += (((long)(*PSIU_ik)**PSIU_ik)>>(qAU*qAU-15))*(*Dold_k); 
     268            sigma += (((long)(*PSIU_ik)**PSIU_ik)>>15)*(*Dold_k); 
    269269        } 
    270270        sigma += *(Q+i+irows)<<15; 
     
    285285                    k<rows; k++, PSIU_ik++, PSIU_jk++, Dold_k++) { 
    286286 
    287                 sigma += ((((long)*PSIU_ik)**PSIU_jk)>>(qAU*qAU-15))**Dold_k; 
     287                sigma += ((((long)*PSIU_ik)**PSIU_jk)>>15)**Dold_k; 
    288288            } 
    289289 
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h

    r1225 r1228  
    1111*************************************/ 
    1212 
    13 #define qAU 15 
     13#define qAU 14 
    1414 
    1515/* Matrix multiply Full matrix by upper diagonal matrix with unit diagonal; */ 
  • applications/pmsm/simulator_zdenek/test_UD.cpp

    r1225 r1228  
    5050         
    5151        imat PUcmp(PSIU,5,5); 
    52         cout << "Delta PSI: " << round_i(PhiU*multip-2*PUcmp) <<endl; 
     52        cout << "Delta PSI: " << round_i(PhiU*multip-(1<<(15-qAU))*PUcmp) <<endl; 
    5353         
    54         mat_to_int(round_i(PhiU*multip/2),PSIU); //<< make is same 
     54        mat_to_int(round_i(PhiU*multip/(1<<(15-qAU))),PSIU); //<< make is same 
    5555 
    5656/////////// Test Thorton: