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