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