Changeset 1182
- Timestamp:
- 09/10/10 11:11:24 (14 years ago)
- Location:
- applications/pmsm/simulator_zdenek/ekf_example
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp
r1180 r1182 228 228 const vec &u=cond; 229 229 int dim = dimension(); 230 230 ///// !!!!!!!!!!!!!!!! 231 231 U = est._R()._L().T(); 232 232 D = est._R()._D(); 233 233 if (false){ 234 mat L; 235 ivec tmp; 236 mat X=randn(5,5); 237 mat XX=X*X.T(); 238 mat T=diag(sqrt(1.0/diag(XX))); 239 XX= T*XX*T; 240 241 ldmat ldd(XX); 242 U = ldd._L().T(); 243 D = ldd._D()*0.9; 244 } 245 234 246 //////////// 235 247 … … 246 258 xref(3) = 3.141593; 247 259 xref(4) = 34.0; 260 261 if (false){ 262 xref = ones(5); 263 } 248 264 249 265 imat Utf; … … 255 271 mat_to_int(Utf,Uf); 256 272 vec_to_int(Dtf, Df); 273 274 // cout << Dtf << endl; 257 275 258 276 // A*U == PSI*U … … 285 303 sigma2 += G(i,j)*G(i,j) * Q(j,j); 286 304 }*/ 287 288 /* UDtof(U,D,Utf,Dtf,xref); 305 D(i) = sigma; 306 307 /* UDtof(U,D,Utf,Dtf,xref); 289 308 cout << "d=sig"<<endl; 290 cout << Utf << endl << Dtf << endl; 291 cout << G << endl << Din << endl<<endl;*/ 292 293 D(i) = sigma; 309 cout << Dtf << endl; 310 */ 294 311 for (j=0;j<i;j++){ 295 312 // cout << i << "," << j << endl; … … 316 333 } 317 334 318 /* cout << "end"<<endl;319 UDtof(U,D,Utf,Dtf,xref);320 cout << G << endl << Din << endl;321 cout << Utf << endl << Dtf << endl<<endl;*/322 335 } 336 UDtof(U,D,Utf,Dtf,xref); 337 // cout << G << endl << Din << endl; 338 imat Urw=Utf.T(); 339 cout << ivec(Urw._data(),25) << endl << Dtf << endl; 323 340 } 324 341 … … 328 345 mat_to_int(Qrnd,Qf); 329 346 347 // cout << Df <<endl; 330 348 thorton(Uf,Df,PSIU,Qf,Gf,Dfold,5); 331 349 332 cout << "bierman double I" <<endl;350 /* cout << "bierman double I" <<endl; 333 351 UDtof(U,D,Utf,Dtf,xref); 334 352 cout << "Uf: " << Utf << endl; 335 353 cout << "Df: " << Dtf << endl; 336 cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl; 354 cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl;*/ 337 355 mat_to_int(Utf,Uf); 338 356 vec_to_int(Dtf, Df); … … 374 392 } 375 393 376 UDtof(U,D,Utf,Dtf,xref);377 cout << "Uf: " << Utf << endl;378 cout << "Df: " << Dtf << endl;379 cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl;394 // UDtof(U,D,Utf,Dtf,xref); 395 // cout << "Uf: " << Utf << endl; 396 // cout << "Df: " << Dtf << endl; 397 // cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl; 380 398 381 399 int difz[2]; … … 387 405 //beirman(int *difz, int *xp, int *U, int *D, int *R, unsigned int dimy, unsigned int dimx 388 406 389 cout <<endl<< "bierman fixed" <<endl;390 for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl;391 for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl;392 for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl;393 394 for (i=0; i<2;i++) cout << difz[i] << ","; cout << endl;407 // cout <<endl<< "bierman fixed" <<endl; 408 // for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 409 // for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl; 410 // for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl; 411 // 412 // for (i=0; i<2;i++) cout << difz[i] << ","; cout << endl; 395 413 396 414 int xf_old[5]; … … 399 417 400 418 UDtof(U,D,Utf,Dtf,xref); 401 for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl;419 /* for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 402 420 for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl; 403 421 for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl; 404 cout << endl; 422 cout << endl;*/ 405 423 406 424 -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp
r1180 r1182 46 46 }; 47 47 48 void UDprt(int *U, int *D) { 49 return; 50 for (int i=0;i<5;i++) { 51 for (int j=0;j<5;j++) { 52 printf("%d,",U[i*5+j]); 53 } 54 printf("\n"); 55 } 56 for (int i=0;i<5;i++) { 57 printf("%d,",D[i]); 58 } 48 bool DBG=true; 49 50 void show(const char name[10], int *I, int n) { 51 if (!DBG) return; 52 53 printf("%s: ",name); 54 for (int i=0;i<n;i++) { 55 printf("%d ",*(I+i)); 56 } 59 57 printf("\n"); 60 58 } … … 82 80 // eye created 83 81 84 long sigma; // in q 1585 for (i=rows-1; i>=0;i--) { // check i==0 at the END!82 long sigma; // in q30!!!!!! 83 for (i=rows-1; true;i--) { // check i==0 at the END! 86 84 sigma = 0; 87 85 88 86 for (j=0;j<rows; j++) { 89 sigma += (((long)PSIU[i*rows+j]*PSIU[i*rows+j])>>15)*(Dold[i]); 87 //long s1=(((long)PSIU[i+j*rows]*PSIU[i+j*rows])>>15)*(Dold[i]); 88 long s2=(((long)PSIU[i*rows+j]*PSIU[i*rows+j])>>15)*(Dold[j]); 89 // printf("%d - %d\n",s1,s2); 90 sigma += s2; 90 91 } 91 sigma += Q[i*rows+i] ;92 sigma += Q[i*rows+i]<<15; 92 93 for (j=i+1;j<rows; j++) { 93 94 sigma += (((long)G[i*rows+j]*G[i*rows+j])>>13)*Q[j*rows+j]; 95 // sigma += (((long)G[i+j*rows]*G[i+j*rows])>>13)*Q[j+j*rows]; 94 96 } 95 97 96 98 *(D+i)=sigma>>15; 97 99 if (D[i]==0) D[i]=1; 98 99 /* printf("d=sig\n"); 100 UDprt(U,D); 101 UDprt(G,Dold);*/ 100 //show("D",D,5); 102 101 103 102 for (j=0;j<i;j++) { … … 116 115 U[j*rows+i] = (int)z; 117 116 118 /* printf("U=sig/D\n");119 UDprt(U,D);120 UDprt(G,Dold);*/121 117 122 118 for (k=0;k<rows;k++) { … … 128 124 } 129 125 130 /* printf("end\n"); 131 UDprt(U,D); 132 UDprt(G,Dold); 133 printf("\n"); */ 134 } 135 if (i==0) return; 126 } 127 //show("U",U,25); 128 //show("G",G,25); 129 if (i==0) return; 136 130 } 137 131 }