- Timestamp:
- 04/12/11 22:30:24 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp
r1321 r1326 206 206 *U_ij -= ((int32)(*a_j)*(*b_i))/lambda; // pozadovane optimalni reseni 207 207 *b_i += ((int32)beta*(*b_j))>>15; 208 printf("%d, %d, %d\n", ((int32)(*a_j)*(*b_i))/lambda, *b_i, beta);208 //printf("%d, %d, %d\n", ((int32)(*a_j)*(*b_i))/lambda, *b_i, beta); 209 209 } 210 210 } … … 451 451 tau=Ch[i*dimx+j]; 452 452 tmp_long=((int32)beta*Ch[i*dimx+j] -(int32)sigma*w[i])/gamma; 453 if (tmp_long>32767) {453 /* if (tmp_long>32767) { 454 454 Ch[i*dimx+j]=32767; 455 455 } else { … … 457 457 Ch[i*dimx+j]=-32767; 458 458 } else { 459 Ch[i*dimx+j]=tmp_long;460 }459 */ Ch[i*dimx+j]=tmp_long; 460 /* } 461 461 } 462 462 */ 463 463 w[i]+=((int32)tau*sigma)>>15; 464 464 } … … 537 537 } 538 538 m1pom-=(j+1); // shift back to first element 539 540 *respom++=tmp_sum>>15; 541 539 540 /* if (tmp_sum>(1<<29)-1) 541 *respom++=(1<<14); 542 else 543 */ 544 if (tmp_sum>0) 545 *respom++=(tmp_sum+(1<<14)-1)>>15; 546 else 547 *respom++=(tmp_sum-(1<<14)+1)>>15; 548 542 549 tmp_sum=0; 543 550 } … … 552 559 int16 rho,s,c,tau; 553 560 int32 tmp_long; 561 562 //c,s in q14!! 554 563 555 564 int16 A[25];//beware … … 573 582 for (j=0; j<dimx; j++) 574 583 { 575 // tmp_long=(long)Ch[i*dimx+i]*Ch[i*dimx+i]+(long)A[i*dimx+j]*A[i*dimx+j]; 576 577 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*A_ij**A_ij; 578 579 if (tmp_long>0) 584 if (*A_ij!=0) 580 585 { 586 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*A_ij**A_ij; 581 587 // rho=qsqrt(tmp_long); // verze pro DSP 582 588 rho=(int16)(sqrt((double)tmp_long)); // verze pro PC 583 s=(( int32)*A_ij<<15)/rho;584 c=(( int32)*Ch_ii<<15)/rho;589 s=(((int32)*A_ij)<<14)/rho; 590 c=(((int32)*Ch_ii)<<14)/rho; 585 591 586 592 Ch_ki=Ch+i; … … 589 595 for (k=0;k<=i; k++) 590 596 { 591 tau=((int32)c**A_kj-(int32)s**Ch_ki)>>15; 592 *Ch_ki=((int32)s**A_kj+(int32)c**Ch_ki)>>15; 597 tau=((int32)c**A_kj-(int32)s**Ch_ki)>>14; 598 tmp_long=(int32)s**A_kj+(int32)c**Ch_ki; 599 if (tmp_long>(1<<28)) //q14 + q15 600 *Ch_ki = (1<<14)-1; 601 else 602 *Ch_ki=tmp_long>>14; 593 603 *A_kj=tau; 594 604 … … 604 614 for (j=0; j<i; j++) 605 615 { 606 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*Ch_ij**Ch_ij; 607 608 if (tmp_long>0) 616 617 if (*Ch_ij>0) 609 618 { 619 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*Ch_ij**Ch_ij; 610 620 // rho=qsqrt(tmp_long); // verze pro DSP 611 rho=(int16)(sqrt((double)tmp_long)); // verze pro PC 612 s=((int32)*Ch_ij<<15)/rho; 613 c=((int32)*Ch_ii<<15)/rho; 621 if (tmp_long>(1<<30)-1) 622 rho=(1<<15)-1; 623 else 624 rho=(int16)(sqrt((double)tmp_long)); // verze pro PC 625 626 s=(((int32)*Ch_ij)<<14)/rho; 627 c=(((int32)*Ch_ii)<<14)/rho; 614 628 615 629 Ch_kj = Ch + j; … … 618 632 for (k=0; k<=i; k++) 619 633 { 620 tau=((int32)c**Ch_kj-(int32)s**Ch_ki)>>15; 621 *Ch_ki =((int32)s**Ch_kj+(int32)c**Ch_ki)>>15; 634 tau=((int32)c**Ch_kj-(int32)s**Ch_ki)>>14; 635 tmp_long =((int32)s**Ch_kj+(int32)c**Ch_ki); 636 if (tmp_long>(1<<28)) 637 *Ch_ki = (1<<14)-1; 638 else 639 *Ch_ki=tmp_long>>14; 622 640 *Ch_kj=tau; 623 641 … … 720 738 721 739 //sigma=Ch[iy*dimx+j]; 722 beta=alpha; 740 beta=alpha; // in q15 723 741 // alpha+=((long)sigma*sigma)>>15; 724 alpha=(((int32)alpha<<15)+(int32)sigma*sigma)>>15; // vyssi presnost 742 tmp_long=((int32)alpha<<15)+(((int32)sigma*sigma)<<(30-2*qCh)); 743 if (tmp_long>0) 744 alpha=(tmp_long+(1<<14)-1)>>15; // vyssi presnost 745 else 746 alpha=(tmp_long-(1<<14)+1)>>15; // vyssi presnost 747 725 748 // gamma= qsqrt(((long)alpha*beta)); // verze pro DSP 726 749 gamma= (int16)(sqrt((double)((int32)alpha*beta))); // verze pro PC 727 750 // in q15 728 751 w[j]=0; 729 752 730 753 Ch_ij=Ch+j; 731 w_i=w; 754 w_i=w; // in q15 732 755 733 756 for (i=0;i<=j;i++) … … 736 759 tau=*Ch_ij; 737 760 // tmp_long=((long)beta*Ch[i*dimx+j] -(long)sigma*w[i])/gamma; 738 tmp_long=((int32)beta**Ch_ij -(int32)sigma**w_i)/gamma; 739 740 if (tmp_long>32767)761 tmp_long=((int32)beta**Ch_ij -(int32)sigma**w_i)/gamma; // in qCh 762 763 /* if (tmp_long>32767) 741 764 tmp_long=32767; 742 765 if (tmp_long<-32768) 743 tmp_long=-32768; 766 tmp_long=-32768;*/ 744 767 *Ch_ij=tmp_long; 745 768 746 769 // w_i+=((long)tau*sigma)>>15; 747 *w_i=(((int32)*w_i<<15)+(int32)tau*sigma)>>15; 770 tmp_long = ((int32)*w_i<<15)+((int32)tau*sigma<<(30-2*qCh)); 771 /*if (tmp_long>0) 772 *w_i=(tmp_long+(1<<14)-1)>>15; 773 else 774 *w_i=(tmp_long-(1<<14)+1)>>15; 775 */ *w_i=(tmp_long)>>15; 748 776 749 777 w_i++; … … 761 789 w_i++; 762 790 } 763 } 764 } 765 791 printf("Kg: %d %d\n",w[0],w[1]); 792 } 793 } 794