##// END OF EJS Templates
sync
paul -
r19:cc82265fd480 TCH
parent child
Show More
@@ -1,918 +1,920
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013)
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013)
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10
10
11
11
12 #include <stdint.h>
12 #include <stdint.h>
13 #include "basic_parameters.h"
13 #include "basic_parameters.h"
14 #include "basic_parameters_params.h"
14 #include "basic_parameters_params.h"
15
15
16 void init_k_coefficients(float *k_coefficients,
16 void init_k_coefficients(float *k_coefficients,
17 unsigned char nb_binscompressed_matrix )
17 unsigned char nb_binscompressed_matrix )
18 {
18 {
19 uint16_t i; // 16 bits unsigned
19 uint16_t i; // 16 bits unsigned
20 for(i=0; i<nb_binscompressed_matrix; i++){
20 for(i=0; i<nb_binscompressed_matrix; i++){
21 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
21 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
22 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
22 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
23 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
23 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
24 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
24 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
25 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
25 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
26 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
26 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
27 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
27 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
28 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
28 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
29 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
29 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
30 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
30 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
31 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
31 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
32 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
32 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
33 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
33 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
34 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
34 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
35 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
35 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
36 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
36 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
37 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
37 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
38 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
38 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
39 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
39 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
40 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
40 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
41 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
41 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
42 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
42 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
43 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
43 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
44 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
44 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
45 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
45 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
46 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
46 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
47 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
47 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
48 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
48 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
49 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
49 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
50 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
50 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
51 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
51 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
52 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
52 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
53 }
53 }
54 }
54 }
55
55
56 void BP1_set( float * compressed_spec_mat, float * k_coeff_intercalib, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp1 ){
56 void BP1_set( float * compressed_spec_mat, float * k_coeff_intercalib, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp1 ){
57 float PSDB; // 32-bit floating point
57 float PSDB; // 32-bit floating point
58 float PSDE;
58 float PSDE;
59 float tmp;
59 float tmp;
60 float NVEC_V0;
60 float NVEC_V0;
61 float NVEC_V1;
61 float NVEC_V1;
62 float NVEC_V2;
62 float NVEC_V2;
63 float aux;
63 float aux;
64 float tr_SB_SB;
64 float tr_SB_SB;
65 float e_cross_b_re;
65 float e_cross_b_re;
66 float e_cross_b_im;
66 float e_cross_b_im;
67 float n_cross_e_scal_b_re;
67 float n_cross_e_scal_b_re;
68 float n_cross_e_scal_b_im;
68 float n_cross_e_scal_b_im;
69 float ny;
69 float ny;
70 float nz;
70 float nz;
71 float bx_bx_star;
71 float bx_bx_star;
72 float vphi;
72 float vphi;
73 float significand;
73 float significand;
74 int exponent; // 32-bit signed integer
74 int exponent; // 32-bit signed integer
75 float alpha_M;
75 float alpha_M;
76
76
77 uint8_t nbitexp; // 8-bit unsigned integer
77 uint8_t nbitexp; // 8-bit unsigned integer
78 uint8_t nbitsig;
78 uint8_t nbitsig;
79 uint8_t tmp_uint8;
79 uint8_t tmp_uint8;
80 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
80 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
81 int8_t expmin; // 8-bit signed integer
81 int8_t expmin; // 8-bit signed integer
82 int8_t expmax;
82 int8_t expmax;
83 uint16_t rangesig; // 16-bit unsigned integer
83 uint16_t rangesig; // 16-bit unsigned integer
84 uint16_t psd;
84 uint16_t psd;
85 uint16_t exp;
85 uint16_t exp;
86 uint16_t tmp_uint16;
86 uint16_t tmp_uint16;
87 uint16_t i;
87 uint16_t i;
88
88
89 alpha_M = 45 * (3.1415927/180);
89 alpha_M = 45 * (3.1415927/180);
90
90
91 #ifdef DEBUG_TCH
91 #ifdef DEBUG_TCH
92 printf("BP1 : \n");
92 printf("BP1 : \n");
93 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
93 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
94 #endif
94 #endif
95
95
96 // initialization for managing the exponents of the floating point data:
96 // initialization for managing the exponents of the floating point data:
97 nbitexp = 5; // number of bits for the exponent
97 nbitexp = 5; // number of bits for the exponent
98 expmax = 30; // maximum value of the exponent
98 expmax = 30; // maximum value of the exponent
99 expmin = expmax - (1 << nbitexp) + 1; // accordingly the minimum exponent value
99 expmin = expmax - (1 << nbitexp) + 1; // accordingly the minimum exponent value
100 // for floating point data to be recorded on 12-bit words:
100 // for floating point data to be recorded on 12-bit words:
101 nbitsig = 12 - nbitexp; // number of bits for the significand
101 nbitsig = 12 - nbitexp; // number of bits for the significand
102 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
102 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
103
103
104 #ifdef DEBUG_TCH
104 #ifdef DEBUG_TCH
105 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
105 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
106 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
106 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
107 #endif
107 #endif
108
108
109 for(i=0; i<nb_bins_compressed_spec_mat; i++){
109 for(i=0; i<nb_bins_compressed_spec_mat; i++){
110 //==============================================
110 //==============================================
111 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
111 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
112 PSDB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] // S11
112 PSDB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] // S11
113 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22
113 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22
114 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]; // S33
114 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]; // S33
115
115
116 significand = frexpf(PSDB/3, &exponent); // 0.5 <= significand < 1
116 significand = frexpf(PSDB/3, &exponent); // 0.5 <= significand < 1
117 // PSDB/3 = significand * 2^exponent
117 // PSDB/3 = significand * 2^exponent
118 // the division by 3 is to ensure that max value <= 2^30
118 // the division by 3 is to ensure that max value <= 2^30
119
119
120 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
120 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
121 exponent = expmin;
121 exponent = expmin;
122 significand = 0.5; // min value that can be recorded
122 significand = 0.5; // min value that can be recorded
123 }
123 }
124 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
124 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
125 exponent = expmax;
125 exponent = expmax;
126 significand = 1.0; // max value that can be recorded
126 significand = 1.0; // max value that can be recorded
127 }
127 }
128 if (significand == 0) { // in that case exponent == 0 too
128 if (significand == 0) { // in that case exponent == 0 too
129 exponent = expmin;
129 exponent = expmin;
130 significand = 0.5; // min value that can be recorded
130 significand = 0.5; // min value that can be recorded
131 }
131 }
132
132
133 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
133 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
134 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
134 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
135 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
135 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
136 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
136 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
137 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
137 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
138 // left place of the significand bits (nbitsig),
138 // left place of the significand bits (nbitsig),
139 // making the 16-bit word to be recorded
139 // making the 16-bit word to be recorded
140 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
140 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
141 #ifdef MSB_FIRST_TCH
141 #ifdef MSB_FIRST_TCH
142 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[0]; // Record MSB of tmp_uint16
142 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[0]; // Record MSB of tmp_uint16
143 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[1]; // Record LSB of tmp_uint16
143 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[1]; // Record LSB of tmp_uint16
144 #endif
144 #endif
145 #ifdef LSB_FIRST_TCH
145 #ifdef LSB_FIRST_TCH
146 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[1]; // Record MSB of tmp_uint16
146 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[1]; // Record MSB of tmp_uint16
147 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[0]; // Record LSB of tmp_uint16
147 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[0]; // Record LSB of tmp_uint16
148 #endif
148 #endif
149 #ifdef DEBUG_TCH
149 #ifdef DEBUG_TCH
150 printf("\nBin number: %d\n", i);
150 printf("\nBin number: %d\n", i);
151 printf("PSDB / 3 : %16.8e\n",PSDB/3);
151 printf("PSDB / 3 : %16.8e\n",PSDB/3);
152 printf("significand : %16.8e\n",significand);
152 printf("significand : %16.8e\n",significand);
153 printf("exponent : %d\n" ,exponent);
153 printf("exponent : %d\n" ,exponent);
154 printf("psd for PSDB significand : %d\n",psd);
154 printf("psd for PSDB significand : %d\n",psd);
155 printf("exp for PSDB exponent : %d\n",exp);
155 printf("exp for PSDB exponent : %d\n",exp);
156 printf("pt_uint8[1] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
156 printf("pt_uint8[1] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
157 printf("pt_uint8[0] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
157 printf("pt_uint8[0] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
158 printf("lfr_bp1[i*NB_BYTES_BP1+3] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+3], lfr_bp1[i*NB_BYTES_BP1+3]);
158 printf("lfr_bp1[i*NB_BYTES_BP1+3] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+3], lfr_bp1[i*NB_BYTES_BP1+3]);
159 printf("lfr_bp1[i*NB_BYTES_BP1+2] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+2], lfr_bp1[i*NB_BYTES_BP1+2]);
159 printf("lfr_bp1[i*NB_BYTES_BP1+2] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+2], lfr_bp1[i*NB_BYTES_BP1+2]);
160 #endif
160 #endif
161 //==============================================
161 //==============================================
162 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
162 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
163 PSDE = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K44_PE] // S44
163 PSDE = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K44_PE] // S44
164 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K55_PE] // S55
164 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K55_PE] // S55
165 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_RE] // S45 Re
165 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_RE] // S45 Re
166 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_IM]; // S45 Im
166 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_IM]; // S45 Im
167
167
168 significand = frexpf(PSDE/2, &exponent); // 0.5 <= significand < 1
168 significand = frexpf(PSDE/2, &exponent); // 0.5 <= significand < 1
169 // PSDE/2 = significand * 2^exponent
169 // PSDE/2 = significand * 2^exponent
170 // the division by 2 is to ensure that max value <= 2^30
170 // the division by 2 is to ensure that max value <= 2^30
171 // should be reconsidered by taking into account the k-coefficients ...
171 // should be reconsidered by taking into account the k-coefficients ...
172
172
173 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
173 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
174 exponent = expmin;
174 exponent = expmin;
175 significand = 0.5; // min value that can be recorded
175 significand = 0.5; // min value that can be recorded
176 }
176 }
177 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
177 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
178 exponent = expmax;
178 exponent = expmax;
179 significand = 1.0; // max value that can be recorded
179 significand = 1.0; // max value that can be recorded
180 }
180 }
181 if (significand == 0) {// in that case exponent == 0 too
181 if (significand == 0) {// in that case exponent == 0 too
182 exponent = expmin;
182 exponent = expmin;
183 significand = 0.5; // min value that can be recorded
183 significand = 0.5; // min value that can be recorded
184 }
184 }
185
185
186 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
186 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
187 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
187 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
188 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
188 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
189 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
189 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
190 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
190 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
191 // left place of the significand bits (nbitsig),
191 // left place of the significand bits (nbitsig),
192 // making the 16-bit word to be recorded
192 // making the 16-bit word to be recorded
193 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
193 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
194 #ifdef MSB_FIRST_TCH
194 #ifdef MSB_FIRST_TCH
195 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[0]; // Record MSB of tmp_uint16
195 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[0]; // Record MSB of tmp_uint16
196 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[1]; // Record LSB of tmp_uint16
196 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[1]; // Record LSB of tmp_uint16
197 #endif
197 #endif
198 #ifdef LSB_FIRST_TCH
198 #ifdef LSB_FIRST_TCH
199 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[1]; // Record MSB of tmp_uint16
199 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[1]; // Record MSB of tmp_uint16
200 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[0]; // Record LSB of tmp_uint16
200 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[0]; // Record LSB of tmp_uint16
201 #endif
201 #endif
202 #ifdef DEBUG_TCH
202 #ifdef DEBUG_TCH
203 printf("Bin number: %d\n", i);
203 printf("Bin number: %d\n", i);
204 printf("PSDE/2 : %16.8e\n",PSDE/2);
204 printf("PSDE/2 : %16.8e\n",PSDE/2);
205 printf("significand : %16.8e\n",significand);
205 printf("significand : %16.8e\n",significand);
206 printf("exponent : %d\n" ,exponent);
206 printf("exponent : %d\n" ,exponent);
207 printf("psd for PSDE significand : %d\n",psd);
207 printf("psd for PSDE significand : %d\n",psd);
208 printf("exp for PSDE exponent : %d\n",exp);
208 printf("exp for PSDE exponent : %d\n",exp);
209 printf("pt_uint8[1] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
209 printf("pt_uint8[1] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
210 printf("pt_uint8[0] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
210 printf("pt_uint8[0] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
211 printf("lfr_bp1[i*NB_BYTES_BP1+1] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+1], lfr_bp1[i*NB_BYTES_BP1+1]);
211 printf("lfr_bp1[i*NB_BYTES_BP1+1] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+1], lfr_bp1[i*NB_BYTES_BP1+1]);
212 printf("lfr_bp1[i*NB_BYTES_BP1+0] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+0], lfr_bp1[i*NB_BYTES_BP1+0]);
212 printf("lfr_bp1[i*NB_BYTES_BP1+0] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+0], lfr_bp1[i*NB_BYTES_BP1+0]);
213 #endif
213 #endif
214 //==============================================================================
214 //==============================================================================
215 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
215 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
216 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
216 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
217 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
217 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
218 tmp = sqrt_ple( compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] //Im S12
218 tmp = sqrt_ple( compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] //Im S12
219 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13
219 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13
220 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23
220 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23
221 );
221 );
222 NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1
222 NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1
223 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
223 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
224 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
224 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
225
225
226 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
226 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
227 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
227 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
228 pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2
228 pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2
229 #ifdef LSB_FIRST_TCH
229 #ifdef LSB_FIRST_TCH
230 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
230 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
231 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
231 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
232 #endif
232 #endif
233 #ifdef MSB_FIRST_TCH
233 #ifdef MSB_FIRST_TCH
234 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 1th octet:SPARC convention)
234 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 1th octet:SPARC convention)
235 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
235 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
236 #endif
236 #endif
237 #ifdef DEBUG_TCH
237 #ifdef DEBUG_TCH
238 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
238 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
239 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
239 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
240 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
240 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
241 printf("lfr_bp1[i*NB_BYTES_BP1+4] for NVEC_V0 : %u\n",lfr_bp1[i*NB_BYTES_BP1+4]);
241 printf("lfr_bp1[i*NB_BYTES_BP1+4] for NVEC_V0 : %u\n",lfr_bp1[i*NB_BYTES_BP1+4]);
242 printf("lfr_bp1[i*NB_BYTES_BP1+5] for NVEC_V1 : %u\n",lfr_bp1[i*NB_BYTES_BP1+5]);
242 printf("lfr_bp1[i*NB_BYTES_BP1+5] for NVEC_V1 : %u\n",lfr_bp1[i*NB_BYTES_BP1+5]);
243 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
243 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
244 #endif
244 #endif
245 //=======================================================
245 //=======================================================
246 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
246 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
247 aux = 2*tmp / PSDB; // Compute the ellipticity
247 aux = 2*tmp / PSDB; // Compute the ellipticity
248
248
249 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
249 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
250 // where just the first 4 bits are used (0, ..., 15)
250 // where just the first 4 bits are used (0, ..., 15)
251 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
251 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
252 // of the sign bit of NVEC_V2 (recorded
252 // of the sign bit of NVEC_V2 (recorded
253 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
253 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
254 #ifdef DEBUG_TCH
254 #ifdef DEBUG_TCH
255 printf("ellipticity : %16.8e\n",aux);
255 printf("ellipticity : %16.8e\n",aux);
256 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
256 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
257 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
257 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
258 #endif
258 #endif
259 //==============================================================
259 //==============================================================
260 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
260 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
261 tr_SB_SB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]
261 tr_SB_SB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]
262 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]
262 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]
263 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]
263 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]
264 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1]
264 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1]
265 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]
265 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]
266 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3]
266 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3]
267 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]
267 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]
268 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
268 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
269 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
269 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
270 aux = PSDB*PSDB;
270 aux = PSDB*PSDB;
271 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation
271 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation
272
272
273 tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
273 tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
274 // where just the first 3 bits are used (0, ..., 7)
274 // where just the first 3 bits are used (0, ..., 7)
275 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
275 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
276 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
276 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
277 #ifdef DEBUG_TCH
277 #ifdef DEBUG_TCH
278 printf("DOP : %16.8e\n",tmp);
278 printf("DOP : %16.8e\n",tmp);
279 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
279 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
280 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity + DOP : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
280 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity + DOP : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
281 #endif
281 #endif
282 //=======================================================================================
282 //=======================================================================================
283 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 8 (+ 2) bits
283 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 8 (+ 2) bits
284 // = 5 bits (exponent) + 3 bits (significand)
284 // = 5 bits (exponent) + 3 bits (significand)
285 // + 1 sign bit + 1 argument bit (two sectors)
285 // + 1 sign bit + 1 argument bit (two sectors)
286 e_cross_b_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Re
286 e_cross_b_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Re
287 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Re
287 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Re
288 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Re
288 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Re
289 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Re
289 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Re
290 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Re
290 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Re
291 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE] //S25 Re
291 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE] //S25 Re
292 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Im
292 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Im
293 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Im
293 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Im
294 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Im
294 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Im
295 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Im
295 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Im
296 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Im
296 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Im
297 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM]; //S25 Im
297 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM]; //S25 Im
298 // Im(S_ji) = -Im(S_ij)
298 // Im(S_ji) = -Im(S_ij)
299 // k_ji = k_ij
299 // k_ji = k_ij
300 e_cross_b_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Re
300 e_cross_b_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Re
301 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Re
301 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Re
302 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Re
302 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Re
303 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Re
303 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Re
304 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Re
304 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Re
305 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM] //S25 Re
305 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM] //S25 Re
306 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Im
306 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Im
307 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Im
307 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Im
308 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Im
308 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Im
309 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Im
309 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Im
310 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Im
310 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Im
311 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE]; //S25 Im
311 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE]; //S25 Im
312 #ifdef DEBUG_TCH
312 #ifdef DEBUG_TCH
313 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
313 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
314 #endif
314 #endif
315 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
315 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
316 #ifdef LSB_FIRST_TCH
316 #ifdef LSB_FIRST_TCH
317 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
317 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
318 // Record it at the 8th bit position (from the right to the left)
318 // Record it at the 8th bit position (from the right to the left)
319 // of lfr_bp1[i*NB_BYTES_BP1+0]
319 // of lfr_bp1[i*NB_BYTES_BP1+0]
320 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
320 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
321 #endif
321 #endif
322 #ifdef MSB_FIRST_TCH
322 #ifdef MSB_FIRST_TCH
323 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
323 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
324 // Record it at the 8th bit position (from the right to the left)
324 // Record it at the 8th bit position (from the right to the left)
325 // of lfr_bp1[i*NB_BYTES_BP1+0]
325 // of lfr_bp1[i*NB_BYTES_BP1+0]
326 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
326 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
327 #endif
327 #endif
328 significand = frexpf(e_cross_b_re/2, &exponent); // 0.5 <= significand < 1
328 significand = frexpf(e_cross_b_re/2, &exponent); // 0.5 <= significand < 1
329 // ReaSX/2 = significand * 2^exponent
329 // ReaSX/2 = significand * 2^exponent
330 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
330 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
331 // Should be reconsidered by taking into account the k-coefficients ...
331 // Should be reconsidered by taking into account the k-coefficients ...
332
332
333 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
333 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
334 exponent = expmin;
334 exponent = expmin;
335 significand = 0.5; // min value that can be recorded
335 significand = 0.5; // min value that can be recorded
336 }
336 }
337 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
337 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
338 exponent = expmax;
338 exponent = expmax;
339 significand = 1.0; // max value that can be recorded
339 significand = 1.0; // max value that can be recorded
340 }
340 }
341 if (significand == 0) { // in that case exponent == 0 too
341 if (significand == 0) { // in that case exponent == 0 too
342 exponent = expmin;
342 exponent = expmin;
343 significand = 0.5; // min value that can be recorded
343 significand = 0.5; // min value that can be recorded
344 }
344 }
345
345
346 lfr_bp1[i*NB_BYTES_BP1+7] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
346 lfr_bp1[i*NB_BYTES_BP1+7] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
347 // where just the first 3 bits are used (0, ..., 7)
347 // where just the first 3 bits are used (0, ..., 7)
348 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
348 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
349 // just the first 5 bits are used (0, ..., 2^5-1)
349 // just the first 5 bits are used (0, ..., 2^5-1)
350 #ifdef DEBUG_TCH
350 #ifdef DEBUG_TCH
351 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
351 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
352 printf("significand : %16.8e\n",significand);
352 printf("significand : %16.8e\n",significand);
353 printf("exponent : %d\n" ,exponent);
353 printf("exponent : %d\n" ,exponent);
354 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
354 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
355 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
355 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
356 #endif
356 #endif
357 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (tmp_uint8 << 3); // Shift these 5 bits to the left before logical addition
357 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (tmp_uint8 << 3); // Shift these 5 bits to the left before logical addition
358 // with lfr_bp1[i*NB_BYTES_BP1+7]
358 // with lfr_bp1[i*NB_BYTES_BP1+7]
359 #ifdef DEBUG_TCH
359 #ifdef DEBUG_TCH
360 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
360 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
361 printf("lfr_bp1[i*NB_BYTES_BP1+0] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+0]);
361 printf("lfr_bp1[i*NB_BYTES_BP1+0] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+0]);
362 printf("ImaSX / 2 : %16.8e\n",e_cross_b_im/2);
362 printf("ImaSX / 2 : %16.8e\n",e_cross_b_im/2);
363 #endif
363 #endif
364 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
364 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
365 #ifdef LSB_FIRST_TCH
365 #ifdef LSB_FIRST_TCH
366 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
366 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
367 #endif
367 #endif
368 #ifdef MSB_FIRST_TCH
368 #ifdef MSB_FIRST_TCH
369 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
369 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
370 #endif
370 #endif
371 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
371 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
372 // an unsigned 8-bit char with 01000000; otherwise with null.
372 // an unsigned 8-bit char with 01000000; otherwise with null.
373 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
373 lfr_bp1[i*NB_BYTES_BP1+0] = lfr_bp1[i*NB_BYTES_BP1+0] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
374 // to the left) of lfr_bp1[i*NB_BYTES_BP1+0], by simple logical addition.
374 // to the left) of lfr_bp1[i*NB_BYTES_BP1+0], by simple logical addition.
375 #ifdef DEBUG_TCH
375 #ifdef DEBUG_TCH
376 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
376 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
377 printf("ArgSX sign : %u\n",tmp_uint8);
377 printf("ArgSX sign : %u\n",tmp_uint8);
378 printf("lfr_bp1[i*NB_BYTES_BP1+0] for ReaSX & ArgSX signs + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+0]);
378 printf("lfr_bp1[i*NB_BYTES_BP1+0] for ReaSX & ArgSX signs + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+0]);
379 #endif
379 #endif
380 //======================================================================
380 //======================================================================
381 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 8 (+ 2) bits
381 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 8 (+ 2) bits
382 // = 5 bits (exponent) + 3 bits (significand)
382 // = 5 bits (exponent) + 3 bits (significand)
383 // + 1 sign bit + 1 argument bit (two sectors)
383 // + 1 sign bit + 1 argument bit (two sectors)
384 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
384 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
385 nz = NVEC_V0;
385 nz = NVEC_V0;
386 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22 Re
386 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22 Re
387 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] // S33 Re
387 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] // S33 Re
388 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]; // S23 Re
388 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]; // S23 Re
389
389
390 n_cross_e_scal_b_re = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Re
390 n_cross_e_scal_b_re = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Re
391 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Re
391 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Re
392 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Re
392 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Re
393 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE] //S35 Re
393 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE] //S35 Re
394 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Im
394 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Im
395 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Im
395 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Im
396 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Im
396 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Im
397 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM]) //S35 Im
397 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM]) //S35 Im
398 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Re
398 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Re
399 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Re
399 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Re
400 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Re
400 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Re
401 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] //S35 Re
401 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] //S35 Re
402 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Im
402 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Im
403 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Im
403 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Im
404 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Im
404 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Im
405 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM]);//S35 Im
405 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM]);//S35 Im
406 // Im(S_ji) = -Im(S_ij)
406 // Im(S_ji) = -Im(S_ij)
407 // k_ji = k_ij
407 // k_ji = k_ij
408 n_cross_e_scal_b_im = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Re
408 n_cross_e_scal_b_im = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Re
409 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Re
409 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Re
410 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Re
410 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Re
411 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM] //S35 Re
411 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM] //S35 Re
412 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Im
412 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Im
413 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Im
413 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Im
414 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Im
414 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Im
415 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE]) //S35 Im
415 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE]) //S35 Im
416 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Re
416 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Re
417 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Re
417 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Re
418 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Re
418 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Re
419 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] //S35 Re
419 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] //S35 Re
420 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Im
420 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Im
421 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Im
421 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Im
422 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Im
422 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Im
423 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE]);//S35 Im
423 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE]);//S35 Im
424 #ifdef DEBUG_TCH
424 #ifdef DEBUG_TCH
425 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
425 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
426 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
426 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
427 #endif
427 #endif
428 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
428 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
429 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re
429 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re
430 #ifdef LSB_FIRST_TCH
430 #ifdef LSB_FIRST_TCH
431 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
431 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
432 // Record it at the 8th bit position (from the right to the left)
432 // Record it at the 8th bit position (from the right to the left)
433 // of lfr_bp1[i*NB_BYTES_BP1+2]
433 // of lfr_bp1[i*NB_BYTES_BP1+2]
434 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
434 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
435 #endif
435 #endif
436 #ifdef MSB_FIRST_TCH
436 #ifdef MSB_FIRST_TCH
437 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
437 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
438 // Record it at the 8th bit position (from the right to the left)
438 // Record it at the 8th bit position (from the right to the left)
439 // of lfr_bp1[i*NB_BYTES_BP1+2]
439 // of lfr_bp1[i*NB_BYTES_BP1+2]
440 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|
440 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|
441 #endif
441 #endif
442 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
442 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
443
443
444 significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1
444 significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1
445 // vphi/2 = significand * 2^exponent
445 // vphi/2 = significand * 2^exponent
446 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
446 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
447 // Should be reconsidered by taking into account the k-coefficients ...
447 // Should be reconsidered by taking into account the k-coefficients ...
448
448
449 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
449 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
450 exponent = expmin;
450 exponent = expmin;
451 significand = 0.5; // min value that can be recorded
451 significand = 0.5; // min value that can be recorded
452 }
452 }
453 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
453 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
454 exponent = expmax;
454 exponent = expmax;
455 significand = 1.0; // max value that can be recorded
455 significand = 1.0; // max value that can be recorded
456 }
456 }
457 if (significand == 0) {// in that case exponent == 0 too
457 if (significand == 0) {// in that case exponent == 0 too
458 exponent = expmin;
458 exponent = expmin;
459 significand = 0.5; // min value that can be recorded
459 significand = 0.5; // min value that can be recorded
460 }
460 }
461 #ifdef DEBUG_TCH
461 #ifdef DEBUG_TCH
462 printf("|VPHI| / 2 : %16.8e\n",vphi/2);
462 printf("|VPHI| / 2 : %16.8e\n",vphi/2);
463 printf("significand : %16.8e\n",significand);
463 printf("significand : %16.8e\n",significand);
464 printf("exponent : %d\n" ,exponent);
464 printf("exponent : %d\n" ,exponent);
465 #endif
465 #endif
466 lfr_bp1[i*NB_BYTES_BP1+8] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
466 lfr_bp1[i*NB_BYTES_BP1+8] = (uint8_t) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
467 // where just the first 3 bits are used (0, ..., 7)
467 // where just the first 3 bits are used (0, ..., 7)
468 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
468 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
469 // just the first 5 bits are used (0, ..., 2^5-1)
469 // just the first 5 bits are used (0, ..., 2^5-1)
470 #ifdef DEBUG_TCH
470 #ifdef DEBUG_TCH
471 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
471 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
472 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
472 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
473 #endif
473 #endif
474 lfr_bp1[i*NB_BYTES_BP1+8] = lfr_bp1[i*NB_BYTES_BP1+8] | (tmp_uint8 << 3); // shift these 5 bits to the left before logical addition
474 lfr_bp1[i*NB_BYTES_BP1+8] = lfr_bp1[i*NB_BYTES_BP1+8] | (tmp_uint8 << 3); // shift these 5 bits to the left before logical addition
475 // with lfr_bp1[i*NB_BYTES_BP1+8]
475 // with lfr_bp1[i*NB_BYTES_BP1+8]
476 #ifdef DEBUG_TCH
476 #ifdef DEBUG_TCH
477 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
477 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
478 printf("lfr_bp1[i*NB_BYTES_BP1+2] for VPHI sign + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+2]);
478 printf("lfr_bp1[i*NB_BYTES_BP1+2] for VPHI sign + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+2]);
479 #endif
479 #endif
480 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_im; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_im
480 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_im; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_im
481 #ifdef LSB_FIRST_TCH
481 #ifdef LSB_FIRST_TCH
482 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
482 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
483 #endif
483 #endif
484 #ifdef MSB_FIRST_TCH
484 #ifdef MSB_FIRST_TCH
485 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
485 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
486 #endif
486 #endif
487 tmp_uint8 = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
487 tmp_uint8 = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
488 // an unsigned 8-bit char with 01000000; otherwise with null.
488 // an unsigned 8-bit char with 01000000; otherwise with null.
489 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
489 lfr_bp1[i*NB_BYTES_BP1+2] = lfr_bp1[i*NB_BYTES_BP1+2] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
490 // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition.
490 // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition.
491 #ifdef DEBUG_TCH
491 #ifdef DEBUG_TCH
492 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
492 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
493 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
493 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
494 printf("ArgNEBX sign : %u\n",tmp_uint8);
494 printf("ArgNEBX sign : %u\n",tmp_uint8);
495 printf("lfr_bp1[i*NB_BYTES_BP1+2] for VPHI & ArgNEBX signs + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+2]);
495 printf("lfr_bp1[i*NB_BYTES_BP1+2] for VPHI & ArgNEBX signs + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+2]);
496 #endif
496 #endif
497 }
497 }
498 }
498 }
499
499
500 float sqrt_ple( float x )
500 float sqrt_ple( float x )
501 {
501 {
502 float y;
502 float y;
503
503
504 y = 0;
504 // y = 0;
505
505
506 if ( x < 0)
506 // if ( x < 0)
507 {
507 // {
508 printf("sqrt(<0)\n");
508 // printf("sqrt(<0)\n");
509 }
509 // }
510 else
510 // else
511 {
511 // {
512 y = sqrt( x );
512 // y = sqrt( x );
513 }
513 // }
514
514
515 if ( y == 0 )
515 // if ( y == 0 )
516 {
516 // {
517 y = 1e-9;
517 // y = 1e-9;
518 }
518 // }
519
520 y = sqrt( x );
519
521
520 return y;
522 return y;
521 }
523 }
522
524
523 void BP2_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp2 )
525 void BP2_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp2 )
524 {
526 {
525 float cross_re; // 32-bit floating point
527 float cross_re; // 32-bit floating point
526 float cross_im;
528 float cross_im;
527 float aux;
529 float aux;
528 float significand;
530 float significand;
529 int exponent; // 32-bit signed integer
531 int exponent; // 32-bit signed integer
530 uint8_t nbitexp; // 8-bit unsigned integer
532 uint8_t nbitexp; // 8-bit unsigned integer
531 uint8_t nbitsig;
533 uint8_t nbitsig;
532 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
534 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
533 int8_t expmin; // 8-bit signed integer
535 int8_t expmin; // 8-bit signed integer
534 int8_t expmax;
536 int8_t expmax;
535 uint16_t rangesig; // 16-bit unsigned integer
537 uint16_t rangesig; // 16-bit unsigned integer
536 uint16_t autocor;
538 uint16_t autocor;
537 uint16_t exp;
539 uint16_t exp;
538 uint16_t tmp_uint16;
540 uint16_t tmp_uint16;
539 uint16_t i;
541 uint16_t i;
540
542
541 #ifdef DEBUG_TCH
543 #ifdef DEBUG_TCH
542 printf("BP2 : \n");
544 printf("BP2 : \n");
543 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
545 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
544 #endif
546 #endif
545
547
546 // For floating point data to be recorded on 16-bit words :
548 // For floating point data to be recorded on 16-bit words :
547 nbitexp = 6; // number of bits for the exponent
549 nbitexp = 6; // number of bits for the exponent
548 nbitsig = 16 - nbitexp; // number of bits for the significand
550 nbitsig = 16 - nbitexp; // number of bits for the significand
549 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
551 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
550 expmax = 32;
552 expmax = 32;
551 expmin = expmax - (1 << nbitexp) + 1;
553 expmin = expmax - (1 << nbitexp) + 1;
552
554
553 #ifdef DEBUG_TCH
555 #ifdef DEBUG_TCH
554 printf("nbitexp : %d, nbitsig : %d, rangesig : %d\n", nbitexp, nbitsig, rangesig);
556 printf("nbitexp : %d, nbitsig : %d, rangesig : %d\n", nbitexp, nbitsig, rangesig);
555 printf("expmin : %d, expmax : %d\n", expmin, expmax);
557 printf("expmin : %d, expmax : %d\n", expmin, expmax);
556 #endif
558 #endif
557
559
558 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
560 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
559 //==============================================
561 //==============================================
560 // BP2 normalized cross correlations == PA_LFR_SC_BP2_CROSS_F0 == 10 * (8+8) bits
562 // BP2 normalized cross correlations == PA_LFR_SC_BP2_CROSS_F0 == 10 * (8+8) bits
561 // == PA_LFR_SC_BP2_CROSS_RE_0_F0 == 8 bits
563 // == PA_LFR_SC_BP2_CROSS_RE_0_F0 == 8 bits
562 // == PA_LFR_SC_BP2_CROSS_IM_0_F0 == 8 bits
564 // == PA_LFR_SC_BP2_CROSS_IM_0_F0 == 8 bits
563 // == PA_LFR_SC_BP2_CROSS_RE_1_F0 == 8 bits
565 // == PA_LFR_SC_BP2_CROSS_RE_1_F0 == 8 bits
564 // == PA_LFR_SC_BP2_CROSS_IM_1_F0 == 8 bits
566 // == PA_LFR_SC_BP2_CROSS_IM_1_F0 == 8 bits
565 // == PA_LFR_SC_BP2_CROSS_RE_2_F0 == 8 bits
567 // == PA_LFR_SC_BP2_CROSS_RE_2_F0 == 8 bits
566 // == PA_LFR_SC_BP2_CROSS_IM_2_F0 == 8 bits
568 // == PA_LFR_SC_BP2_CROSS_IM_2_F0 == 8 bits
567 // == PA_LFR_SC_BP2_CROSS_RE_3_F0 == 8 bits
569 // == PA_LFR_SC_BP2_CROSS_RE_3_F0 == 8 bits
568 // == PA_LFR_SC_BP2_CROSS_IM_3_F0 == 8 bits
570 // == PA_LFR_SC_BP2_CROSS_IM_3_F0 == 8 bits
569 // == PA_LFR_SC_BP2_CROSS_RE_4_F0 == 8 bits
571 // == PA_LFR_SC_BP2_CROSS_RE_4_F0 == 8 bits
570 // == PA_LFR_SC_BP2_CROSS_IM_4_F0 == 8 bits
572 // == PA_LFR_SC_BP2_CROSS_IM_4_F0 == 8 bits
571 // == PA_LFR_SC_BP2_CROSS_RE_5_F0 == 8 bits
573 // == PA_LFR_SC_BP2_CROSS_RE_5_F0 == 8 bits
572 // == PA_LFR_SC_BP2_CROSS_IM_5_F0 == 8 bits
574 // == PA_LFR_SC_BP2_CROSS_IM_5_F0 == 8 bits
573 // == PA_LFR_SC_BP2_CROSS_RE_6_F0 == 8 bits
575 // == PA_LFR_SC_BP2_CROSS_RE_6_F0 == 8 bits
574 // == PA_LFR_SC_BP2_CROSS_IM_6_F0 == 8 bits
576 // == PA_LFR_SC_BP2_CROSS_IM_6_F0 == 8 bits
575 // == PA_LFR_SC_BP2_CROSS_RE_7_F0 == 8 bits
577 // == PA_LFR_SC_BP2_CROSS_RE_7_F0 == 8 bits
576 // == PA_LFR_SC_BP2_CROSS_IM_7_F0 == 8 bits
578 // == PA_LFR_SC_BP2_CROSS_IM_7_F0 == 8 bits
577 // == PA_LFR_SC_BP2_CROSS_RE_8_F0 == 8 bits
579 // == PA_LFR_SC_BP2_CROSS_RE_8_F0 == 8 bits
578 // == PA_LFR_SC_BP2_CROSS_IM_8_F0 == 8 bits
580 // == PA_LFR_SC_BP2_CROSS_IM_8_F0 == 8 bits
579 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
581 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
580 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
582 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
581 // S12
583 // S12
582 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
584 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
583 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
585 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
584 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
586 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
585 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
587 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
586 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
588 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
587 #ifdef DEBUG_TCH
589 #ifdef DEBUG_TCH
588 printf("\nBin number: %d\n", i);
590 printf("\nBin number: %d\n", i);
589 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
591 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
590 printf("lfr_bp2[i*NB_BYTES_BP2+20] for cross12_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+20]);
592 printf("lfr_bp2[i*NB_BYTES_BP2+20] for cross12_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+20]);
591 #endif
593 #endif
592 // S13
594 // S13
593 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
595 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
594 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
596 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
595 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
597 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
596 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
598 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
597 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
599 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
598 #ifdef DEBUG_TCH
600 #ifdef DEBUG_TCH
599 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
601 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
600 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
602 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
601 #endif
603 #endif
602 // S14
604 // S14
603 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
605 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
604 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
606 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
605 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
607 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
606 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
608 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
607 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
609 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
608 #ifdef DEBUG_TCH
610 #ifdef DEBUG_TCH
609 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
611 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
610 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
612 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
611 #endif
613 #endif
612 // S15
614 // S15
613 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
615 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
614 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
616 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
615 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
617 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
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
618 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
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
619 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
618 #ifdef DEBUG_TCH
620 #ifdef DEBUG_TCH
619 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
621 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
620 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
622 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
621 #endif
623 #endif
622 // S23
624 // S23
623 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
625 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
624 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
626 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
625 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
627 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
626 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
628 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
627 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
629 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
628 #ifdef DEBUG_TCH
630 #ifdef DEBUG_TCH
629 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
631 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
630 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
632 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
631 #endif
633 #endif
632 // S24
634 // S24
633 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
635 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
634 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
636 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
635 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
637 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
636 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
638 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
637 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
639 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
638 #ifdef DEBUG_TCH
640 #ifdef DEBUG_TCH
639 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
641 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
640 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
642 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
641 #endif
643 #endif
642 // S25
644 // S25
643 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
645 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
644 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
646 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
645 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
647 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
646 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
648 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
647 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
649 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
648 #ifdef DEBUG_TCH
650 #ifdef DEBUG_TCH
649 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
651 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
650 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
652 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
651 #endif
653 #endif
652 // S34
654 // S34
653 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
655 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
654 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
656 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
655 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
657 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
656 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
658 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
657 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
659 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
658 #ifdef DEBUG_TCH
660 #ifdef DEBUG_TCH
659 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
661 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
660 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
662 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
661 #endif
663 #endif
662 // S35
664 // S35
663 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
665 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
664 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
666 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
665 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
667 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
666 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
668 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
667 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
669 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
668 #ifdef DEBUG_TCH
670 #ifdef DEBUG_TCH
669 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
671 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
670 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
672 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
671 #endif
673 #endif
672 // S45
674 // S45
673 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
675 aux = sqrt_ple(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
674 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
676 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
675 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
677 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
676 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
678 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
677 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
679 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
678 #ifdef DEBUG_TCH
680 #ifdef DEBUG_TCH
679 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
681 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
680 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
682 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
681 #endif
683 #endif
682 //==============================================
684 //==============================================
683 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
685 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
684 // == PA_LFR_SC_BP2_AUTO_A0_F0 == 16 bits
686 // == PA_LFR_SC_BP2_AUTO_A0_F0 == 16 bits
685 // == PA_LFR_SC_BP2_AUTO_A1_F0 == 16 bits
687 // == PA_LFR_SC_BP2_AUTO_A1_F0 == 16 bits
686 // == PA_LFR_SC_BP2_AUTO_A2_F0 == 16 bits
688 // == PA_LFR_SC_BP2_AUTO_A2_F0 == 16 bits
687 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
689 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
688 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
690 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
689 // S11
691 // S11
690 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
692 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
691 // S11 = significand * 2^exponent
693 // S11 = significand * 2^exponent
692 #ifdef DEBUG_TCH
694 #ifdef DEBUG_TCH
693 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
695 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
694 printf("significand : %16.8e\n",significand);
696 printf("significand : %16.8e\n",significand);
695 printf("exponent : %d\n" ,exponent);
697 printf("exponent : %d\n" ,exponent);
696 #endif
698 #endif
697 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
699 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
698 exponent = expmin;
700 exponent = expmin;
699 significand = 0.5; // min value that can be recorded
701 significand = 0.5; // min value that can be recorded
700 }
702 }
701 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
703 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
702 exponent = expmax;
704 exponent = expmax;
703 significand = 1.0; // max value that can be recorded
705 significand = 1.0; // max value that can be recorded
704 }
706 }
705 if (significand == 0) { // in that case exponent == 0 too
707 if (significand == 0) { // in that case exponent == 0 too
706 exponent = expmin;
708 exponent = expmin;
707 significand = 0.5; // min value that can be recorded
709 significand = 0.5; // min value that can be recorded
708 }
710 }
709
711
710 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
712 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
711 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
713 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
712 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
714 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
713 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
715 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
714 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
716 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
715 // left place of the significand bits (nbitsig),
717 // left place of the significand bits (nbitsig),
716 // making the 16-bit word to be recorded
718 // making the 16-bit word to be recorded
717 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
719 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
718 #ifdef MSB_FIRST_TCH
720 #ifdef MSB_FIRST_TCH
719 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[0]; // Record MSB of tmp_uint16
721 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[0]; // Record MSB of tmp_uint16
720 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[1]; // Record LSB of tmp_uint16
722 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[1]; // Record LSB of tmp_uint16
721 #endif
723 #endif
722 #ifdef LSB_FIRST_TCH
724 #ifdef LSB_FIRST_TCH
723 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[1]; // Record MSB of tmp_uint16
725 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[1]; // Record MSB of tmp_uint16
724 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[0]; // Record LSB of tmp_uint16
726 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[0]; // Record LSB of tmp_uint16
725 #endif
727 #endif
726 #ifdef DEBUG_TCH
728 #ifdef DEBUG_TCH
727 printf("autocor for S11 significand : %u\n",autocor);
729 printf("autocor for S11 significand : %u\n",autocor);
728 printf("exp for S11 exponent : %u\n",exp);
730 printf("exp for S11 exponent : %u\n",exp);
729 printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
731 printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
730 printf("pt_uint8[0] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
732 printf("pt_uint8[0] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
731 printf("lfr_bp2[i*NB_BYTES_BP2+1] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]);
733 printf("lfr_bp2[i*NB_BYTES_BP2+1] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]);
732 printf("lfr_bp2[i*NB_BYTES_BP2+0] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]);
734 printf("lfr_bp2[i*NB_BYTES_BP2+0] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]);
733 #endif
735 #endif
734 // S22
736 // S22
735 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
737 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
736 // S22 = significand * 2^exponent
738 // S22 = significand * 2^exponent
737 #ifdef DEBUG_TCH
739 #ifdef DEBUG_TCH
738 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
740 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
739 printf("significand : %16.8e\n",significand);
741 printf("significand : %16.8e\n",significand);
740 printf("exponent : %d\n" ,exponent);
742 printf("exponent : %d\n" ,exponent);
741 #endif
743 #endif
742 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
744 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
743 exponent = expmin;
745 exponent = expmin;
744 significand = 0.5; // min value that can be recorded
746 significand = 0.5; // min value that can be recorded
745 }
747 }
746 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
748 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
747 exponent = expmax;
749 exponent = expmax;
748 significand = 1.0; // max value that can be recorded
750 significand = 1.0; // max value that can be recorded
749 }
751 }
750 if (significand == 0) { // in that case exponent == 0 too
752 if (significand == 0) { // in that case exponent == 0 too
751 exponent = expmin;
753 exponent = expmin;
752 significand = 0.5; // min value that can be recorded
754 significand = 0.5; // min value that can be recorded
753 }
755 }
754
756
755 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
757 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
756 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
758 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
757 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
759 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
758 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
760 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
759 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
761 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
760 // left place of the significand bits (nbitsig),
762 // left place of the significand bits (nbitsig),
761 // making the 16-bit word to be recorded
763 // making the 16-bit word to be recorded
762 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
764 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
763 #ifdef MSB_FIRST_TCH
765 #ifdef MSB_FIRST_TCH
764 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[0]; // Record MSB of tmp_uint16
766 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[0]; // Record MSB of tmp_uint16
765 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[1]; // Record LSB of tmp_uint16
767 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[1]; // Record LSB of tmp_uint16
766 #endif
768 #endif
767 #ifdef LSB_FIRST_TCH
769 #ifdef LSB_FIRST_TCH
768 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[1]; // Record MSB of tmp_uint16
770 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[1]; // Record MSB of tmp_uint16
769 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[0]; // Record LSB of tmp_uint16
771 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[0]; // Record LSB of tmp_uint16
770 #endif
772 #endif
771 #ifdef DEBUG_TCH
773 #ifdef DEBUG_TCH
772 printf("autocor for S22 significand : %u\n",autocor);
774 printf("autocor for S22 significand : %u\n",autocor);
773 printf("exp for S11 exponent : %u\n",exp);
775 printf("exp for S11 exponent : %u\n",exp);
774 printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
776 printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
775 printf("pt_uint8[0] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
777 printf("pt_uint8[0] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
776 printf("lfr_bp2[i*NB_BYTES_BP2+3] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]);
778 printf("lfr_bp2[i*NB_BYTES_BP2+3] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]);
777 printf("lfr_bp2[i*NB_BYTES_BP2+2] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]);
779 printf("lfr_bp2[i*NB_BYTES_BP2+2] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]);
778 #endif
780 #endif
779 // S33
781 // S33
780 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
782 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
781 // S33 = significand * 2^exponent
783 // S33 = significand * 2^exponent
782 #ifdef DEBUG_TCH
784 #ifdef DEBUG_TCH
783 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
785 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
784 printf("significand : %16.8e\n",significand);
786 printf("significand : %16.8e\n",significand);
785 printf("exponent : %d\n" ,exponent);
787 printf("exponent : %d\n" ,exponent);
786 #endif
788 #endif
787 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
789 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
788 exponent = expmin;
790 exponent = expmin;
789 significand = 0.5; // min value that can be recorded
791 significand = 0.5; // min value that can be recorded
790 }
792 }
791 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
793 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
792 exponent = expmax;
794 exponent = expmax;
793 significand = 1.0; // max value that can be recorded
795 significand = 1.0; // max value that can be recorded
794 }
796 }
795 if (significand == 0) { // in that case exponent == 0 too
797 if (significand == 0) { // in that case exponent == 0 too
796 exponent = expmin;
798 exponent = expmin;
797 significand = 0.5; // min value that can be recorded
799 significand = 0.5; // min value that can be recorded
798 }
800 }
799
801
800 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
802 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
801 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
803 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
802 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
804 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
803 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
805 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
804 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
806 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
805 // left place of the significand bits (nbitsig),
807 // left place of the significand bits (nbitsig),
806 // making the 16-bit word to be recorded
808 // making the 16-bit word to be recorded
807 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
809 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
808 #ifdef MSB_FIRST_TCH
810 #ifdef MSB_FIRST_TCH
809 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[0]; // Record MSB of tmp_uint16
811 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[0]; // Record MSB of tmp_uint16
810 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[1]; // Record LSB of tmp_uint16
812 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[1]; // Record LSB of tmp_uint16
811 #endif
813 #endif
812 #ifdef LSB_FIRST_TCH
814 #ifdef LSB_FIRST_TCH
813 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[1]; // Record MSB of tmp_uint16
815 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[1]; // Record MSB of tmp_uint16
814 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[0]; // Record LSB of tmp_uint16
816 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[0]; // Record LSB of tmp_uint16
815 #endif
817 #endif
816 #ifdef DEBUG_TCH
818 #ifdef DEBUG_TCH
817 printf("autocor for S33 significand : %u\n",autocor);
819 printf("autocor for S33 significand : %u\n",autocor);
818 printf("exp for S33 exponent : %u\n",exp);
820 printf("exp for S33 exponent : %u\n",exp);
819 printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
821 printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
820 printf("pt_uint8[0] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
822 printf("pt_uint8[0] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
821 printf("lfr_bp2[i*NB_BYTES_BP2+5] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]);
823 printf("lfr_bp2[i*NB_BYTES_BP2+5] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]);
822 printf("lfr_bp2[i*NB_BYTES_BP2+4] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]);
824 printf("lfr_bp2[i*NB_BYTES_BP2+4] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]);
823 #endif
825 #endif
824 // S44
826 // S44
825 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
827 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
826 // S44 = significand * 2^exponent
828 // S44 = significand * 2^exponent
827 #ifdef DEBUG_TCH
829 #ifdef DEBUG_TCH
828 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
830 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
829 printf("significand : %16.8e\n",significand);
831 printf("significand : %16.8e\n",significand);
830 printf("exponent : %d\n" ,exponent);
832 printf("exponent : %d\n" ,exponent);
831 #endif
833 #endif
832
834
833 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
835 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
834 exponent = expmin;
836 exponent = expmin;
835 significand = 0.5; // min value that can be recorded
837 significand = 0.5; // min value that can be recorded
836 }
838 }
837 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
839 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
838 exponent = expmax;
840 exponent = expmax;
839 significand = 1.0; // max value that can be recorded
841 significand = 1.0; // max value that can be recorded
840 }
842 }
841 if (significand == 0) { // in that case exponent == 0 too
843 if (significand == 0) { // in that case exponent == 0 too
842 exponent = expmin;
844 exponent = expmin;
843 significand = 0.5; // min value that can be recorded
845 significand = 0.5; // min value that can be recorded
844 }
846 }
845
847
846 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
848 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
847 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
849 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
848 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
850 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
849 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
851 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
850 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
852 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
851 // left place of the significand bits (nbitsig),
853 // left place of the significand bits (nbitsig),
852 // making the 16-bit word to be recorded
854 // making the 16-bit word to be recorded
853 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
855 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
854 #ifdef MSB_FIRST_TCH
856 #ifdef MSB_FIRST_TCH
855 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[0]; // Record MSB of tmp_uint16
857 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[0]; // Record MSB of tmp_uint16
856 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[1]; // Record LSB of tmp_uint16
858 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[1]; // Record LSB of tmp_uint16
857 #endif
859 #endif
858 #ifdef LSB_FIRST_TCH
860 #ifdef LSB_FIRST_TCH
859 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[1]; // Record MSB of tmp_uint16
861 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[1]; // Record MSB of tmp_uint16
860 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[0]; // Record LSB of tmp_uint16
862 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[0]; // Record LSB of tmp_uint16
861 #endif
863 #endif
862 #ifdef DEBUG_TCH
864 #ifdef DEBUG_TCH
863 printf("autocor for S44 significand : %u\n",autocor);
865 printf("autocor for S44 significand : %u\n",autocor);
864 printf("exp for S44 exponent : %u\n",exp);
866 printf("exp for S44 exponent : %u\n",exp);
865 printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
867 printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
866 printf("pt_uint8[0] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
868 printf("pt_uint8[0] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
867 printf("lfr_bp2[i*NB_BYTES_BP2+7] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]);
869 printf("lfr_bp2[i*NB_BYTES_BP2+7] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]);
868 printf("lfr_bp2[i*NB_BYTES_BP2+6] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]);
870 printf("lfr_bp2[i*NB_BYTES_BP2+6] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]);
869 #endif
871 #endif
870 // S55
872 // S55
871 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
873 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
872 // S55 = significand * 2^exponent
874 // S55 = significand * 2^exponent
873 #ifdef DEBUG_TCH
875 #ifdef DEBUG_TCH
874 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
876 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
875 printf("significand : %16.8e\n",significand);
877 printf("significand : %16.8e\n",significand);
876 printf("exponent : %d\n" ,exponent);
878 printf("exponent : %d\n" ,exponent);
877 #endif
879 #endif
878 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
880 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
879 exponent = expmin;
881 exponent = expmin;
880 significand = 0.5; // min value that can be recorded
882 significand = 0.5; // min value that can be recorded
881 }
883 }
882 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
884 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
883 exponent = expmax;
885 exponent = expmax;
884 significand = 1.0; // max value that can be recorded
886 significand = 1.0; // max value that can be recorded
885 }
887 }
886 if (significand == 0) { // in that case exponent == 0 too
888 if (significand == 0) { // in that case exponent == 0 too
887 exponent = expmin;
889 exponent = expmin;
888 significand = 0.5; // min value that can be recorded
890 significand = 0.5; // min value that can be recorded
889 }
891 }
890
892
891 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
893 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
892 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
894 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
893 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
895 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
894 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
896 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
895 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
897 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
896 // left place of the significand bits (nbitsig),
898 // left place of the significand bits (nbitsig),
897 // making the 16-bit word to be recorded
899 // making the 16-bit word to be recorded
898 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
900 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
899 #ifdef MSB_FIRST_TCH
901 #ifdef MSB_FIRST_TCH
900 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[0]; // Record MSB of tmp_uint16
902 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[0]; // Record MSB of tmp_uint16
901 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[1]; // Record LSB of tmp_uint16
903 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[1]; // Record LSB of tmp_uint16
902 //printf("MSB:\n");
904 //printf("MSB:\n");
903 #endif
905 #endif
904 #ifdef LSB_FIRST_TCH
906 #ifdef LSB_FIRST_TCH
905 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[1]; // Record MSB of tmp_uint16
907 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[1]; // Record MSB of tmp_uint16
906 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[0]; // Record LSB of tmp_uint16
908 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[0]; // Record LSB of tmp_uint16
907 //printf("LSB:\n");
909 //printf("LSB:\n");
908 #endif
910 #endif
909 #ifdef DEBUG_TCH
911 #ifdef DEBUG_TCH
910 printf("autocor for S55 significand : %u\n",autocor);
912 printf("autocor for S55 significand : %u\n",autocor);
911 printf("exp for S55 exponent : %u\n",exp);
913 printf("exp for S55 exponent : %u\n",exp);
912 printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
914 printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
913 printf("pt_uint8[0] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
915 printf("pt_uint8[0] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
914 printf("lfr_bp2[i*NB_BYTES_BP2+9] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]);
916 printf("lfr_bp2[i*NB_BYTES_BP2+9] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]);
915 printf("lfr_bp2[i*NB_BYTES_BP2+8] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]);
917 printf("lfr_bp2[i*NB_BYTES_BP2+8] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]);
916 #endif
918 #endif
917 }
919 }
918 }
920 }
General Comments 0
You need to be logged in to leave comments. Login now