@@ -7,6 +7,7 | |||
|
7 | 7 | // version 1.5: 20/05/2014 |
|
8 | 8 | // version 1.6: 19/12/2014 |
|
9 | 9 | // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3]) |
|
10 | // version 1.8: 02/02/2015 (gestion des divisions par zéro) | |
|
10 | 11 | |
|
11 | 12 | #ifndef BASIC_PARAMETERS_H_INCLUDED |
|
12 | 13 | #define BASIC_PARAMETERS_H_INCLUDED |
@@ -191,10 +192,17 void BP1_set( float * compressed_spec_ma | |||
|
191 | 192 | +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13 |
|
192 | 193 | +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23 |
|
193 | 194 | ); |
|
195 | if (tmp != 0.) { // no division by 0. | |
|
194 | 196 | NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1 |
|
195 | 197 | NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2 |
|
196 | 198 | NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3 |
|
197 | ||
|
199 | } | |
|
200 | else | |
|
201 | { | |
|
202 | NVEC_V0 = 0.; | |
|
203 | NVEC_V1 = 0.; | |
|
204 | NVEC_V2 = 0.; | |
|
205 | } | |
|
198 | 206 | lfr_bp1[i*NB_BYTES_BP1+4] = (uint8_t) (NVEC_V0*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
199 | 207 | lfr_bp1[i*NB_BYTES_BP1+5] = (uint8_t) (NVEC_V1*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
200 | 208 | pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2 |
@@ -216,8 +224,13 void BP1_set( float * compressed_spec_ma | |||
|
216 | 224 | #endif |
|
217 | 225 | //======================================================= |
|
218 | 226 | // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits |
|
227 | if (PSDB != 0.) { // no division by 0. | |
|
219 | 228 | aux = 2*tmp / PSDB; // Compute the ellipticity |
|
220 | ||
|
229 | } | |
|
230 | else | |
|
231 | { | |
|
232 | aux = 0.; | |
|
233 | } | |
|
221 | 234 | tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding |
|
222 | 235 | // where just the first 4 bits are used (0, ..., 15) |
|
223 | 236 | lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_uint8 << 3); // Put these 4 bits next to the right place |
@@ -240,8 +253,13 void BP1_set( float * compressed_spec_ma | |||
|
240 | 253 | + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] |
|
241 | 254 | + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]; |
|
242 | 255 | aux = PSDB*PSDB; |
|
256 | if (aux != 0.) { // no division by 0. | |
|
243 | 257 | tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation |
|
244 | ||
|
258 | } | |
|
259 | else | |
|
260 | { | |
|
261 | tmp = 0.; | |
|
262 | } | |
|
245 | 263 | tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding |
|
246 | 264 | // where just the first 3 bits are used (0, ..., 7) |
|
247 | 265 | lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_uint8; // Record these 3 bits at the 3 first bit positions |
@@ -411,8 +429,13 void BP1_set( float * compressed_spec_ma | |||
|
411 | 429 | // of lfr_bp1[i*NB_BYTES_BP1+2] |
|
412 | 430 | pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re| |
|
413 | 431 | #endif |
|
432 | if (bx_bx_star != 0.) { // no division by 0. | |
|
414 | 433 | vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI| |
|
415 | ||
|
434 | } | |
|
435 | else | |
|
436 | { | |
|
437 | vphi = 1.e+20; // Put a huge value | |
|
438 | } | |
|
416 | 439 | significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1 |
|
417 | 440 | // vphi/2 = significand * 2^exponent |
|
418 | 441 | // The division by 2 is to ensure that max value <= 2^30 (rough estimate) |
@@ -529,8 +552,15 void BP2_set( float * compressed_spec_ma | |||
|
529 | 552 | // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits |
|
530 | 553 | // S12 |
|
531 | 554 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]); |
|
555 | if (aux != 0.) { // no division by 0. | |
|
532 | 556 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux; |
|
533 | 557 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux; |
|
558 | } | |
|
559 | else | |
|
560 | { | |
|
561 | cross_re = 0.; | |
|
562 | cross_im = 0.; | |
|
563 | } | |
|
534 | 564 | lfr_bp2[i*NB_BYTES_BP2+10] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
535 | 565 | lfr_bp2[i*NB_BYTES_BP2+20] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
536 | 566 | #ifdef DEBUG_TCH |
@@ -540,8 +570,15 void BP2_set( float * compressed_spec_ma | |||
|
540 | 570 | #endif |
|
541 | 571 | // S13 |
|
542 | 572 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]); |
|
573 | if (aux != 0.) { // no division by 0. | |
|
543 | 574 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux; |
|
544 | 575 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux; |
|
576 | } | |
|
577 | else | |
|
578 | { | |
|
579 | cross_re = 0.; | |
|
580 | cross_im = 0.; | |
|
581 | } | |
|
545 | 582 | lfr_bp2[i*NB_BYTES_BP2+11] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
546 | 583 | lfr_bp2[i*NB_BYTES_BP2+21] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
547 | 584 | #ifdef DEBUG_TCH |
@@ -550,8 +587,15 void BP2_set( float * compressed_spec_ma | |||
|
550 | 587 | #endif |
|
551 | 588 | // S14 |
|
552 | 589 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); |
|
590 | if (aux != 0.) { // no division by 0. | |
|
553 | 591 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux; |
|
554 | 592 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux; |
|
593 | } | |
|
594 | else | |
|
595 | { | |
|
596 | cross_re = 0.; | |
|
597 | cross_im = 0.; | |
|
598 | } | |
|
555 | 599 | lfr_bp2[i*NB_BYTES_BP2+12] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
556 | 600 | lfr_bp2[i*NB_BYTES_BP2+22] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
557 | 601 | #ifdef DEBUG_TCH |
@@ -560,8 +604,15 void BP2_set( float * compressed_spec_ma | |||
|
560 | 604 | #endif |
|
561 | 605 | // S15 |
|
562 | 606 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); |
|
607 | if (aux != 0.) { // no division by 0. | |
|
563 | 608 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux; |
|
564 | 609 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux; |
|
610 | } | |
|
611 | else | |
|
612 | { | |
|
613 | cross_re = 0.; | |
|
614 | cross_im = 0.; | |
|
615 | } | |
|
565 | 616 | lfr_bp2[i*NB_BYTES_BP2+13] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
566 | 617 | lfr_bp2[i*NB_BYTES_BP2+23] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
567 | 618 | #ifdef DEBUG_TCH |
@@ -570,8 +621,15 void BP2_set( float * compressed_spec_ma | |||
|
570 | 621 | #endif |
|
571 | 622 | // S23 |
|
572 | 623 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]); |
|
624 | if (aux != 0.) { // no division by 0. | |
|
573 | 625 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux; |
|
574 | 626 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux; |
|
627 | } | |
|
628 | else | |
|
629 | { | |
|
630 | cross_re = 0.; | |
|
631 | cross_im = 0.; | |
|
632 | } | |
|
575 | 633 | lfr_bp2[i*NB_BYTES_BP2+14] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
576 | 634 | lfr_bp2[i*NB_BYTES_BP2+24] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
577 | 635 | #ifdef DEBUG_TCH |
@@ -580,8 +638,15 void BP2_set( float * compressed_spec_ma | |||
|
580 | 638 | #endif |
|
581 | 639 | // S24 |
|
582 | 640 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); |
|
641 | if (aux != 0.) { // no division by 0. | |
|
583 | 642 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux; |
|
584 | 643 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux; |
|
644 | } | |
|
645 | else | |
|
646 | { | |
|
647 | cross_re = 0.; | |
|
648 | cross_im = 0.; | |
|
649 | } | |
|
585 | 650 | lfr_bp2[i*NB_BYTES_BP2+15] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
586 | 651 | lfr_bp2[i*NB_BYTES_BP2+25] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
587 | 652 | #ifdef DEBUG_TCH |
@@ -590,8 +655,15 void BP2_set( float * compressed_spec_ma | |||
|
590 | 655 | #endif |
|
591 | 656 | // S25 |
|
592 | 657 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); |
|
658 | if (aux != 0.) { // no division by 0. | |
|
593 | 659 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux; |
|
594 | 660 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux; |
|
661 | } | |
|
662 | else | |
|
663 | { | |
|
664 | cross_re = 0.; | |
|
665 | cross_im = 0.; | |
|
666 | } | |
|
595 | 667 | lfr_bp2[i*NB_BYTES_BP2+16] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
596 | 668 | lfr_bp2[i*NB_BYTES_BP2+26] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
597 | 669 | #ifdef DEBUG_TCH |
@@ -600,8 +672,15 void BP2_set( float * compressed_spec_ma | |||
|
600 | 672 | #endif |
|
601 | 673 | // S34 |
|
602 | 674 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]); |
|
675 | if (aux != 0.) { // no division by 0. | |
|
603 | 676 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux; |
|
604 | 677 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux; |
|
678 | } | |
|
679 | else | |
|
680 | { | |
|
681 | cross_re = 0.; | |
|
682 | cross_im = 0.; | |
|
683 | } | |
|
605 | 684 | lfr_bp2[i*NB_BYTES_BP2+17] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
606 | 685 | lfr_bp2[i*NB_BYTES_BP2+27] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
607 | 686 | #ifdef DEBUG_TCH |
@@ -610,8 +689,15 void BP2_set( float * compressed_spec_ma | |||
|
610 | 689 | #endif |
|
611 | 690 | // S35 |
|
612 | 691 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); |
|
692 | if (aux != 0.) { // no division by 0. | |
|
613 | 693 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux; |
|
614 | 694 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux; |
|
695 | } | |
|
696 | else | |
|
697 | { | |
|
698 | cross_re = 0.; | |
|
699 | cross_im = 0.; | |
|
700 | } | |
|
615 | 701 | lfr_bp2[i*NB_BYTES_BP2+18] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
616 | 702 | lfr_bp2[i*NB_BYTES_BP2+28] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
617 | 703 | #ifdef DEBUG_TCH |
@@ -620,8 +706,15 void BP2_set( float * compressed_spec_ma | |||
|
620 | 706 | #endif |
|
621 | 707 | // S45 |
|
622 | 708 | aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]); |
|
709 | if (aux != 0.) { // no division by 0. | |
|
623 | 710 | cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux; |
|
624 | 711 | cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux; |
|
712 | } | |
|
713 | else | |
|
714 | { | |
|
715 | cross_re = 0.; | |
|
716 | cross_im = 0.; | |
|
717 | } | |
|
625 | 718 | lfr_bp2[i*NB_BYTES_BP2+19] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
626 | 719 | lfr_bp2[i*NB_BYTES_BP2+29] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding |
|
627 | 720 | #ifdef DEBUG_TCH |
General Comments 0
You need to be logged in to leave comments.
Login now