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