##// END OF EJS Templates

Compare Commits r7:ccd69f4e7a60...r9:19349b3a5e90

Target:

Source:

Compare was calculated based on this common ancestor commit: be100cfb14bd
Time Author Commit Description
r7:ccd69f4e7a60
version 1.3 qui finalise la version 1.2 (pb d'alignement mémoire réglé pour BP1 et BP2) (NB_BINS_COMPRESSED_MATRIX_f0 = 11 + quelques mises en forme des commentaires)
r9:19349b3a5e90
Sync
@@ -0,0 +1,2
1 syntax: glob
2 tab_test2_v1.3
@@ -2,6 +2,7
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5
6
6 #include "basic_parameters.h"
7 #include "basic_parameters.h"
7 #include <math.h>
8 #include <math.h>
@@ -92,8 +93,7 void init_k_f0( void )
92 float alpha_M = 45 * (3.1415927/180);
93 float alpha_M = 45 * (3.1415927/180);
93
94
94 void BP1_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp1 ){
95 void BP1_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp1 ){
95 int exponent; // 32 bits signed
96 float PSDB; // 32-bit floating point
96 float PSDB; // 32 bits floating point
97 float PSDE;
97 float PSDE;
98 float tmp;
98 float tmp;
99 float NVEC_V0;
99 float NVEC_V0;
@@ -110,13 +110,14 void BP1_set( float * compressed_spec_ma
110 float bx_bx_star;
110 float bx_bx_star;
111 float vphi;
111 float vphi;
112 float significand;
112 float significand;
113 uint8_t nbitexp; // 8 bits unsigned
113 int exponent; // 32-bit signed integer
114 uint8_t nbitexp; // 8-bit unsigned integer
114 uint8_t nbitsig;
115 uint8_t nbitsig;
115 uint8_t tmp_uint8;
116 uint8_t tmp_uint8;
116 uint8_t *pt_uint8; // pointer on unsigned 8-bit bytes
117 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
117 int8_t expmin; // 8 bits signed
118 int8_t expmin; // 8-bit signed integer
118 int8_t expmax;
119 int8_t expmax;
119 int16_t rangesig; // 16 bits unsigned
120 uint16_t rangesig; // 16-bit unsigned integer
120 uint16_t psd;
121 uint16_t psd;
121 uint16_t exp;
122 uint16_t exp;
122 uint16_t tmp_uint16;
123 uint16_t tmp_uint16;
@@ -161,9 +162,9 void BP1_set( float * compressed_spec_ma
161 exponent = expmax;
162 exponent = expmax;
162 significand = 1.0; // max value that can be recorded
163 significand = 1.0; // max value that can be recorded
163 }
164 }
164 if (significand == 0) {// in that case exponent == 0 too
165 if (significand == 0) { // in that case exponent == 0 too
165 exponent = expmin;
166 exponent = expmin;
166 significand = 0.5; // min value that can be recorded
167 significand = 0.5; // min value that can be recorded
167 }
168 }
168
169
169 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
170 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
@@ -259,16 +260,16 void BP1_set( float * compressed_spec_ma
259 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
260 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
260 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
261 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
261
262
262 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
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
263 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
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
264 pt_uint8 = (uint8_t*) &NVEC_V2; // affect an uint8_t pointer with the adress of NVEC_V2
265 pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2
265 #ifdef LSB_FIRST_TCH
266 #ifdef LSB_FIRST_TCH
266 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)
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)
267 // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
268 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
268 #endif
269 #endif
269 #ifdef MSB_FIRST_TCH
270 #ifdef MSB_FIRST_TCH
270 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)
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)
271 // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
272 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
272 #endif
273 #endif
273 #ifdef DEBUG_TCH
274 #ifdef DEBUG_TCH
274 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
275 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
@@ -280,13 +281,13 void BP1_set( float * compressed_spec_ma
280 #endif
281 #endif
281 //=======================================================
282 //=======================================================
282 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
283 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
283 aux = 2*tmp / PSDB; // compute the ellipticity
284 aux = 2*tmp / PSDB; // Compute the ellipticity
284
285
285 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // shift and cast into a 8-bit uint8_t with rounding
286 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
286 // where just the first 4 bits are used (0, ..., 15)
287 // where just the first 4 bits are used (0, ..., 15)
287 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
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
288 // of the sign bit of NVEC_V2 (recorded
289 // of the sign bit of NVEC_V2 (recorded
289 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
290 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
290 #ifdef DEBUG_TCH
291 #ifdef DEBUG_TCH
291 printf("ellipticity : %16.8e\n",aux);
292 printf("ellipticity : %16.8e\n",aux);
292 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
293 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
@@ -304,12 +305,12 void BP1_set( float * compressed_spec_ma
304 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
305 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
305 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
306 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
306 aux = PSDB*PSDB;
307 aux = PSDB*PSDB;
307 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // compute the degree of polarisation
308 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation
308
309
309 tmp_uint8 = (uint8_t) (tmp*7 + 0.5);// shift and cast into a 8-bit uint8_t with rounding
310 tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
310 // where just the first 3 bits are used (0, ..., 7)
311 // where just the first 3 bits are used (0, ..., 7)
311 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
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
312 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
313 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
313 #ifdef DEBUG_TCH
314 #ifdef DEBUG_TCH
314 printf("DOP : %16.8e\n",tmp);
315 printf("DOP : %16.8e\n",tmp);
315 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
316 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
@@ -348,21 +349,21 void BP1_set( float * compressed_spec_ma
348 #ifdef DEBUG_TCH
349 #ifdef DEBUG_TCH
349 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
350 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
350 #endif
351 #endif
351 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
352 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
352 #ifdef LSB_FIRST_TCH
353 #ifdef LSB_FIRST_TCH
353 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)
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)
354 // Record it at the 8th bit position (from the right to the left)
355 // Record it at the 8th bit position (from the right to the left)
355 // of lfr_bp1[i*NB_BYTES_BP1+1]
356 // of lfr_bp1[i*NB_BYTES_BP1+1]
356 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
357 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
357 #endif
358 #endif
358 #ifdef MSB_FIRST_TCH
359 #ifdef MSB_FIRST_TCH
359 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)
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)
360 // Record it at the 8th bit position (from the right to the left)
361 // Record it at the 8th bit position (from the right to the left)
361 // of lfr_bp1[i*NB_BYTES_BP1+1]
362 // of lfr_bp1[i*NB_BYTES_BP1+1]
362 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
363 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
363 #endif
364 #endif
364 significand = frexpf(e_cross_b_re/2, &exponent);// 0.5 <= significand < 1
365 significand = frexpf(e_cross_b_re/2, &exponent); // 0.5 <= significand < 1
365 // ReaSX/2 = significand * 2^exponent
366 // ReaSX/2 = significand * 2^exponent
366 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
367 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
367 // Should be reconsidered by taking into account the k-coefficients ...
368 // Should be reconsidered by taking into account the k-coefficients ...
368
369
@@ -374,15 +375,15 void BP1_set( float * compressed_spec_ma
374 exponent = expmax;
375 exponent = expmax;
375 significand = 1.0; // max value that can be recorded
376 significand = 1.0; // max value that can be recorded
376 }
377 }
377 if (significand == 0) {// in that case exponent == 0 too
378 if (significand == 0) { // in that case exponent == 0 too
378 exponent = expmin;
379 exponent = expmin;
379 significand = 0.5; // min value that can be recorded
380 significand = 0.5; // min value that can be recorded
380 }
381 }
381
382
382 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
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
383 // where just the first 3 bits are used (0, ..., 7)
384 // where just the first 3 bits are used (0, ..., 7)
384 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
385 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
385 // just the first 5 bits are used (0, ..., 2^5-1)
386 // just the first 5 bits are used (0, ..., 2^5-1)
386 #ifdef DEBUG_TCH
387 #ifdef DEBUG_TCH
387 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
388 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
388 printf("significand : %16.8e\n",significand);
389 printf("significand : %16.8e\n",significand);
@@ -390,8 +391,8 void BP1_set( float * compressed_spec_ma
390 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
391 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
391 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
392 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
392 #endif
393 #endif
393 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
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
394 // with lfr_bp1[i*NB_BYTES_BP1+7]
395 // with lfr_bp1[i*NB_BYTES_BP1+7]
395 #ifdef DEBUG_TCH
396 #ifdef DEBUG_TCH
396 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
397 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
397 printf("lfr_bp1[i*NB_BYTES_BP1+1] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+1]);
398 printf("lfr_bp1[i*NB_BYTES_BP1+1] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+1]);
@@ -399,15 +400,15 void BP1_set( float * compressed_spec_ma
399 #endif
400 #endif
400 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
401 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
401 #ifdef LSB_FIRST_TCH
402 #ifdef LSB_FIRST_TCH
402 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX|
403 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX|
403 #endif
404 #endif
404 #ifdef MSB_FIRST_TCH
405 #ifdef MSB_FIRST_TCH
405 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX|
406 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX|
406 #endif
407 #endif
407 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
408 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
408 // an unsigned 8-bit char with 01000000; otherwise with null.
409 // an unsigned 8-bit char with 01000000; otherwise with null.
409 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
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
410 // to the left) of lfr_bp1[i*NB_BYTES_BP1+1], by simple logical addition.
411 // to the left) of lfr_bp1[i*NB_BYTES_BP1+1], by simple logical addition.
411 #ifdef DEBUG_TCH
412 #ifdef DEBUG_TCH
412 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
413 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
413 printf("ArgSX sign : %u\n",tmp_uint8);
414 printf("ArgSX sign : %u\n",tmp_uint8);
@@ -462,7 +463,7 void BP1_set( float * compressed_spec_ma
462 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
463 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
463 #endif
464 #endif
464 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
465 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
465 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
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
466 #ifdef LSB_FIRST_TCH
467 #ifdef LSB_FIRST_TCH
467 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)
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)
468 // Record it at the 8th bit position (from the right to the left)
469 // Record it at the 8th bit position (from the right to the left)
@@ -477,8 +478,8 void BP1_set( float * compressed_spec_ma
477 #endif
478 #endif
478 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
479 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
479
480
480 significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1
481 significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1
481 // vphi/2 = significand * 2^exponent
482 // vphi/2 = significand * 2^exponent
482 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
483 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
483 // Should be reconsidered by taking into account the k-coefficients ...
484 // Should be reconsidered by taking into account the k-coefficients ...
484
485
@@ -500,9 +501,9 void BP1_set( float * compressed_spec_ma
500 printf("exponent : %d\n" ,exponent);
501 printf("exponent : %d\n" ,exponent);
501 #endif
502 #endif
502 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
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
503 // where just the first 3 bits are used (0, ..., 7)
504 // where just the first 3 bits are used (0, ..., 7)
504 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
505 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
505 // just the first 5 bits are used (0, ..., 2^5-1)
506 // just the first 5 bits are used (0, ..., 2^5-1)
506 #ifdef DEBUG_TCH
507 #ifdef DEBUG_TCH
507 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
508 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
508 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
509 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
@@ -515,15 +516,15 void BP1_set( float * compressed_spec_ma
515 #endif
516 #endif
516 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
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
517 #ifdef LSB_FIRST_TCH
518 #ifdef LSB_FIRST_TCH
518 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX|
519 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX|
519 #endif
520 #endif
520 #ifdef MSB_FIRST_TCH
521 #ifdef MSB_FIRST_TCH
521 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX|
522 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX|
522 #endif
523 #endif
523 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
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
524 // an unsigned 8-bit char with 01000000; otherwise with null.
525 // an unsigned 8-bit char with 01000000; otherwise with null.
525 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
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
526 // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition.
527 // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition.
527 #ifdef DEBUG_TCH
528 #ifdef DEBUG_TCH
528 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
529 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
529 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
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);
@@ -535,12 +536,21 void BP1_set( float * compressed_spec_ma
535
536
536 void BP2_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp2 )
537 void BP2_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp2 )
537 {
538 {
538 int i, exponent;
539 float cross_re; // 32-bit floating point
539 float aux, significand, cross_re, cross_im;
540 float cross_im;
540 int8_t nbitexp, nbitsig, expmin, expmax; // 8 bits
541 float aux;
541 int16_t rangesig; // 16 bits
542 float significand;
542 uint16_t autocor, tmp_uint16; // 16 bits
543 int exponent; // 32-bit signed integer
543 uint16_t *pt_u_short_int; // pointer on unsigned 16-bit words
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;
544
554
545 #ifdef DEBUG_TCH
555 #ifdef DEBUG_TCH
546 printf("BP2 : \n");
556 printf("BP2 : \n");
@@ -548,8 +558,8 void BP2_set( float * compressed_spec_ma
548 #endif
558 #endif
549
559
550 // For floating point data to be recorded on 16-bit words :
560 // For floating point data to be recorded on 16-bit words :
551 nbitexp = 6; // number of bits for the exponent
561 nbitexp = 6; // number of bits for the exponent
552 nbitsig = 16 - nbitexp; // number of bits for the significand
562 nbitsig = 16 - nbitexp; // number of bits for the significand
553 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
563 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
554 expmax = 32;
564 expmax = 32;
555 expmin = expmax - (1 << nbitexp) + 1;
565 expmin = expmax - (1 << nbitexp) + 1;
@@ -586,8 +596,8 void BP2_set( float * compressed_spec_ma
586 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
596 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
587 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
597 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
588 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
598 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
589 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
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
590 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
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
591 #ifdef DEBUG_TCH
601 #ifdef DEBUG_TCH
592 printf("\nBin number: %d\n", i);
602 printf("\nBin number: %d\n", i);
593 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
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]);
@@ -597,8 +607,8 void BP2_set( float * compressed_spec_ma
597 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
607 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
598 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
608 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
599 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
609 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
600 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
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
601 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
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
602 #ifdef DEBUG_TCH
612 #ifdef DEBUG_TCH
603 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
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]);
604 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
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]);
@@ -607,8 +617,8 void BP2_set( float * compressed_spec_ma
607 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
617 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
608 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
618 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
609 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
619 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
610 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
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
611 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
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
612 #ifdef DEBUG_TCH
622 #ifdef DEBUG_TCH
613 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
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]);
614 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
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]);
@@ -617,8 +627,8 void BP2_set( float * compressed_spec_ma
617 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
627 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
618 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
628 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
619 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
629 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
620 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
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
621 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
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
622 #ifdef DEBUG_TCH
632 #ifdef DEBUG_TCH
623 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
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]);
624 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
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]);
@@ -627,8 +637,8 void BP2_set( float * compressed_spec_ma
627 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
637 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
628 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
638 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
629 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
639 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
630 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
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
631 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
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
632 #ifdef DEBUG_TCH
642 #ifdef DEBUG_TCH
633 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
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]);
634 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
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]);
@@ -637,8 +647,8 void BP2_set( float * compressed_spec_ma
637 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
647 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
638 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
648 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
639 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
649 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
640 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
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
641 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
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
642 #ifdef DEBUG_TCH
652 #ifdef DEBUG_TCH
643 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
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]);
644 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
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]);
@@ -647,8 +657,8 void BP2_set( float * compressed_spec_ma
647 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
657 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
648 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
658 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
649 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
659 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
650 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
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
651 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
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
652 #ifdef DEBUG_TCH
662 #ifdef DEBUG_TCH
653 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
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]);
654 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
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]);
@@ -657,8 +667,8 void BP2_set( float * compressed_spec_ma
657 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
667 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
658 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
668 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
659 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
669 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
660 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
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
661 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
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
662 #ifdef DEBUG_TCH
672 #ifdef DEBUG_TCH
663 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
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]);
664 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
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]);
@@ -667,8 +677,8 void BP2_set( float * compressed_spec_ma
667 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
677 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
668 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
678 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
669 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
679 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
670 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
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
671 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
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
672 #ifdef DEBUG_TCH
682 #ifdef DEBUG_TCH
673 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
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]);
674 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
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]);
@@ -677,8 +687,8 void BP2_set( float * compressed_spec_ma
677 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
687 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
678 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
688 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
679 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
689 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
680 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
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
681 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
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
682 #ifdef DEBUG_TCH
692 #ifdef DEBUG_TCH
683 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
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]);
684 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
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]);
@@ -692,7 +702,7 void BP2_set( float * compressed_spec_ma
692 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
702 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
693 // S11
703 // S11
694 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
704 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
695 // S11 = significand * 2^exponent
705 // S11 = significand * 2^exponent
696 #ifdef DEBUG_TCH
706 #ifdef DEBUG_TCH
697 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
707 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
698 printf("significand : %16.8e\n",significand);
708 printf("significand : %16.8e\n",significand);
@@ -706,30 +716,38 void BP2_set( float * compressed_spec_ma
706 exponent = expmax;
716 exponent = expmax;
707 significand = 1.0; // max value that can be recorded
717 significand = 1.0; // max value that can be recorded
708 }
718 }
709 if (significand == 0) {// in that case exponent == 0 too
719 if (significand == 0) { // in that case exponent == 0 too
710 exponent = expmin;
720 exponent = expmin;
711 significand = 0.5; // min value that can be recorded
721 significand = 0.5; // min value that can be recorded
712 }
722 }
713
723
714 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
724 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
715 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
725 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
716 tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
726 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
717 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
727 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
718 pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+0]; // Affect an uint16_t pointer with the
728 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
719 // adress where the 16-bit word result will be stored
729 // left place of the significand bits (nbitsig),
720 *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the
730 // making the 16-bit word to be recorded
721 // left place of the significand bits (nbitsig), making
731 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
722 // the 16-bit word to be recorded, and record it using the pointer
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
723 #ifdef DEBUG_TCH
740 #ifdef DEBUG_TCH
724 printf("autocor for S11 significand : %u\n",autocor );
741 printf("autocor for S11 significand : %u\n",autocor);
725 printf("tmp_uint8 for S11 exponent : %u\n",tmp_uint16 );
742 printf("exp for S11 exponent : %u\n",exp);
726 printf("*pt_u_short_int for S11 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
743 printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
727 printf("lfr_bp2[i*NB_BYTES_BP2+1] : %u or %x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]);
744 printf("pt_uint8[0] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
728 printf("lfr_bp2[i*NB_BYTES_BP2+0] : %u or %x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+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]);
729 #endif
747 #endif
730 // S22
748 // S22
731 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
749 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
732 // S22 = significand * 2^exponent
750 // S22 = significand * 2^exponent
733 #ifdef DEBUG_TCH
751 #ifdef DEBUG_TCH
734 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
752 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
735 printf("significand : %16.8e\n",significand);
753 printf("significand : %16.8e\n",significand);
@@ -743,30 +761,38 void BP2_set( float * compressed_spec_ma
743 exponent = expmax;
761 exponent = expmax;
744 significand = 1.0; // max value that can be recorded
762 significand = 1.0; // max value that can be recorded
745 }
763 }
746 if (significand == 0) {// in that case exponent == 0 too
764 if (significand == 0) { // in that case exponent == 0 too
747 exponent = expmin;
765 exponent = expmin;
748 significand = 0.5; // min value that can be recorded
766 significand = 0.5; // min value that can be recorded
749 }
767 }
750
768
751 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
769 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
752 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
770 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
753 tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
771 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
754 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
772 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
755 pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+2]; // Affect an uint16_t pointer with the
773 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
756 // adress where the 16-bit word result will be stored
774 // left place of the significand bits (nbitsig),
757 *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the
775 // making the 16-bit word to be recorded
758 // left place of the significand bits (nbitsig), making
776 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
759 // the 16-bit word to be recorded, and record it using the pointer
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
760 #ifdef DEBUG_TCH
785 #ifdef DEBUG_TCH
761 printf("autocor for S22 significand : %d\n",autocor );
786 printf("autocor for S22 significand : %u\n",autocor);
762 printf("tmp_uint8 for S22 exponent : %d\n",tmp_uint16 );
787 printf("exp for S11 exponent : %u\n",exp);
763 printf("*pt_u_short_int for S22 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
788 printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
764 printf("lfr_bp2[i*NB_BYTES_BP2+3] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]);
789 printf("pt_uint8[0] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
765 printf("lfr_bp2[i*NB_BYTES_BP2+2] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]);
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]);
766 #endif
792 #endif
767 // S33
793 // S33
768 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
794 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
769 // S33 = significand * 2^exponent
795 // S33 = significand * 2^exponent
770 #ifdef DEBUG_TCH
796 #ifdef DEBUG_TCH
771 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
797 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
772 printf("significand : %16.8e\n",significand);
798 printf("significand : %16.8e\n",significand);
@@ -780,30 +806,38 void BP2_set( float * compressed_spec_ma
780 exponent = expmax;
806 exponent = expmax;
781 significand = 1.0; // max value that can be recorded
807 significand = 1.0; // max value that can be recorded
782 }
808 }
783 if (significand == 0) {// in that case exponent == 0 too
809 if (significand == 0) { // in that case exponent == 0 too
784 exponent = expmin;
810 exponent = expmin;
785 significand = 0.5; // min value that can be recorded
811 significand = 0.5; // min value that can be recorded
786 }
812 }
787
813
788 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
814 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
789 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
815 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
790 tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
816 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
791 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
817 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
792 pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+4]; // Affect an uint16_t pointer with the
818 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
793 // adress where the 16-bit word result will be stored
819 // left place of the significand bits (nbitsig),
794 *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the
820 // making the 16-bit word to be recorded
795 // left place of the significand bits (nbitsig), making
821 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
796 // the 16-bit word to be recorded, and record it using the pointer
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
797 #ifdef DEBUG_TCH
830 #ifdef DEBUG_TCH
798 printf("autocor for S33 significand : %d\n",autocor );
831 printf("autocor for S33 significand : %u\n",autocor);
799 printf("tmp_uint8 for S33 exponent : %d\n",tmp_uint16 );
832 printf("exp for S33 exponent : %u\n",exp);
800 printf("*pt_u_short_int for S33 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
833 printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
801 printf("lfr_bp2[i*NB_BYTES_BP2+5] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]);
834 printf("pt_uint8[0] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
802 printf("lfr_bp2[i*NB_BYTES_BP2+4] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]);
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]);
803 #endif
837 #endif
804 // S44
838 // S44
805 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
839 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
806 // S44 = significand * 2^exponent
840 // S44 = significand * 2^exponent
807 #ifdef DEBUG_TCH
841 #ifdef DEBUG_TCH
808 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
842 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
809 printf("significand : %16.8e\n",significand);
843 printf("significand : %16.8e\n",significand);
@@ -818,30 +852,38 void BP2_set( float * compressed_spec_ma
818 exponent = expmax;
852 exponent = expmax;
819 significand = 1.0; // max value that can be recorded
853 significand = 1.0; // max value that can be recorded
820 }
854 }
821 if (significand == 0) {// in that case exponent == 0 too
855 if (significand == 0) { // in that case exponent == 0 too
822 exponent = expmin;
856 exponent = expmin;
823 significand = 0.5; // min value that can be recorded
857 significand = 0.5; // min value that can be recorded
824 }
858 }
825
859
826 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
860 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
827 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
861 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
828 tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
862 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
829 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
863 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
830 pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+6]; // Affect an uint16_t pointer with the
864 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
831 // adress where the 16-bit word result will be stored
865 // left place of the significand bits (nbitsig),
832 *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the
866 // making the 16-bit word to be recorded
833 // left place of the significand bits (nbitsig), making
867 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
834 // the 16-bit word to be recorded, and record it using the pointer
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
835 #ifdef DEBUG_TCH
876 #ifdef DEBUG_TCH
836 printf("autocor for S44 significand : %d\n",autocor );
877 printf("autocor for S44 significand : %u\n",autocor);
837 printf("tmp_uint8 for S44 exponent : %d\n",tmp_uint16 );
878 printf("exp for S44 exponent : %u\n",exp);
838 printf("*pt_u_short_int for S44 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
879 printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
839 printf("lfr_bp2[i*NB_BYTES_BP2+7] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]);
880 printf("pt_uint8[0] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
840 printf("lfr_bp2[i*NB_BYTES_BP2+6] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]);
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]);
841 #endif
883 #endif
842 // S55
884 // S55
843 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
885 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
844 // S55 = significand * 2^exponent
886 // S55 = significand * 2^exponent
845 #ifdef DEBUG_TCH
887 #ifdef DEBUG_TCH
846 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
888 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
847 printf("significand : %16.8e\n",significand);
889 printf("significand : %16.8e\n",significand);
@@ -855,26 +897,34 void BP2_set( float * compressed_spec_ma
855 exponent = expmax;
897 exponent = expmax;
856 significand = 1.0; // max value that can be recorded
898 significand = 1.0; // max value that can be recorded
857 }
899 }
858 if (significand == 0) {// in that case exponent == 0 too
900 if (significand == 0) { // in that case exponent == 0 too
859 exponent = expmin;
901 exponent = expmin;
860 significand = 0.5; // min value that can be recorded
902 significand = 0.5; // min value that can be recorded
861 }
903 }
862
904
863 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
905 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
864 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
906 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
865 tmp_uint16 = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
907 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
866 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
908 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
867 pt_u_short_int = (uint16_t*) &lfr_bp2[i*NB_BYTES_BP2+8]; // Affect an uint16_t pointer with the
909 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
868 // adress where the 16-bit word result will be stored
910 // left place of the significand bits (nbitsig),
869 *pt_u_short_int = autocor | (tmp_uint16 << nbitsig); // Put the exponent bits (nbitexp) next to the
911 // making the 16-bit word to be recorded
870 // left place of the significand bits (nbitsig), making
912 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
871 // the 16-bit word to be recorded, and record it using the pointer
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
872 #ifdef DEBUG_TCH
921 #ifdef DEBUG_TCH
873 printf("autocor for S55 significand : %d\n",autocor );
922 printf("autocor for S55 significand : %u\n",autocor);
874 printf("tmp_uint8 for S55 exponent : %d\n",tmp_uint16 );
923 printf("exp for S55 exponent : %u\n",exp);
875 printf("*pt_u_short_int for S55 exponent + significand : %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
924 printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
876 printf("lfr_bp2[i*NB_BYTES_BP2+9] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]);
925 printf("pt_uint8[0] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
877 printf("lfr_bp2[i*NB_BYTES_BP2+8] : %.3d or %x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]);
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]);
878 #endif
928 #endif
879 }
929 }
880 }
930 }
@@ -2,12 +2,13
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5
6
6 #ifndef BASIC_PARAMETERS_H_INCLUDED
7 #ifndef BASIC_PARAMETERS_H_INCLUDED
7 #define BASIC_PARAMETERS_H_INCLUDED
8 #define BASIC_PARAMETERS_H_INCLUDED
8
9
9 #define NB_VALUES_PER_SPECTRAL_MATRIX 25
10 #define NB_VALUES_PER_SPECTRAL_MATRIX 25
10 #define NB_BINS_COMPRESSED_MATRIX_f0 1
11 #define NB_BINS_COMPRESSED_MATRIX_f0 11
11
12
12 #define NB_BYTES_BP1 9
13 #define NB_BYTES_BP1 9
13 #define NB_BYTES_BP2 30
14 #define NB_BYTES_BP2 30
@@ -2,6 +2,7
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5
6
6 #include <file_utilities.h>
7 #include <file_utilities.h>
7
8
@@ -17,10 +18,11 int lecture_file_sm(const char *fileName
17 }
18 }
18 (void) fread(compressed_spectral_matrix_f0, sizeof(compressed_spectral_matrix_f0), 1, infile);
19 (void) fread(compressed_spectral_matrix_f0, sizeof(compressed_spectral_matrix_f0), 1, infile);
19 (void) fclose(infile);
20 (void) fclose(infile);
20 printf("size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0));
21 printf("Number of bins: %d\n\n", NB_BINS_COMPRESSED_MATRIX_f0);
22
21
23 printf("compressed_spectral_matrix_f0 : \n");
22 printf("Compressed_spectral_matrix_f0 : \n");
23 printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0);
24 printf("Number of values per spectral matrix: %d\n", NB_VALUES_PER_SPECTRAL_MATRIX);
25 printf("Size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0));
24
26
25 for(i=0; i<NB_BINS_COMPRESSED_MATRIX_f0; i++){
27 for(i=0; i<NB_BINS_COMPRESSED_MATRIX_f0; i++){
26
28
@@ -2,6 +2,7
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5
6
6 #ifndef FILE_UTILITIES_H
7 #ifndef FILE_UTILITIES_H
7 #define FILE_UTILITIES_H
8 #define FILE_UTILITIES_H
@@ -2,6 +2,7
2 // version 1.O: 31/07/2013
2 // version 1.O: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5
6
6 #include <stdio.h>
7 #include <stdio.h>
7 #include <basic_parameters.h>
8 #include <basic_parameters.h>