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