##// END OF EJS Templates
Initial commit
thomas -
r0:f328b9239ea0 default
parent child
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
This diff has been collapsed as it changes many lines, (743 lines changed) Show them Hide them
@@ -0,0 +1,743
1 #include "basic_parameters_1_ICD_issue1rev6.h"
2 #include <math.h>
3 #include <stdio.h>
4
5 float k44_pe = 1;
6 float k55_pe = 1;
7 float k45_pe_re = 1;
8 float k45_pe_im = 1;
9
10 float k14_sx_re = 1;
11 float k14_sx_im = 1;
12 float k15_sx_re = 1;
13 float k15_sx_im = 1;
14 float k24_sx_re = 1;
15 float k24_sx_im = 1;
16 float k25_sx_re = 1;
17 float k25_sx_im = 1;
18 float k34_sx_re = 1;
19 float k34_sx_im = 1;
20 float k35_sx_re = 1;
21 float k35_sx_im = 1;
22
23 float k24_ny_re = 1;
24 float k24_ny_im = 1;
25 float k25_ny_re = 1;
26 float k25_ny_im = 1;
27 float k34_ny_re = 1;
28 float k34_ny_im = 1;
29 float k35_ny_re = 1;
30 float k35_ny_im = 1;
31
32 float k24_nz_re = 1;
33 float k24_nz_im = 1;
34 float k25_nz_re = 1;
35 float k25_nz_im = 1;
36 float k34_nz_re = 1;
37 float k34_nz_im = 1;
38 float k35_nz_re = 1;
39 float k35_nz_im = 1;
40
41 float alpha_M = 45 * (3.1415927/180);
42
43 void BP1_set(){
44 int i, exponent;
45 // int j;
46 float PSDB, PSDE, tmp, NVEC_V0, NVEC_V1, NVEC_V2, aux, tr_SB_SB,
47 e_cross_b_re, e_cross_b_im,
48 n_cross_e_scal_b_re, n_cross_e_scal_b_im,
49 ny, nz, bx_bx_star, vphi,
50 significand;
51 signed char nbitexp, nbitsig, expmin, expmax; // 8 bits
52 short int rangesig; // 16 bits
53 unsigned short int psd, tmp_u_short_int; // 16 bits
54 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
55 unsigned char tmp_u_char; // 8 bits
56 unsigned char *pt_u_char; // pointer on unsigned 8-bit bytes
57
58 // unsigned char toto_u_char;
59 // unsigned char *pt_toto_u_char;
60 // signed char toto_s_char;
61 // float toto_f;
62
63 printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0);
64 printf("BP1 : \n");
65
66 // initialization for managing the exponents of the floating point data:
67 nbitexp = 5; // number of bits for the exponent
68 expmax = 30; // maximum value of the exponent
69 expmin = expmax - (1 << nbitexp) + 1; // accordingly the minimum exponent value
70 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
71 // for floating point data to be recorded on 12-bit words:
72 nbitsig = 12 - nbitexp; // number of bits for the significand
73 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
74 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
75
76 for(i=0; i<1; i++){
77 //==============================================
78 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
79 PSDB = compressed_spectral_matrix_f0[i*30] // S11
80 + compressed_spectral_matrix_f0[i*30+10] // S22
81 + compressed_spectral_matrix_f0[i*30+18]; // S33
82
83 significand = frexpf(PSDB/3, &exponent); // 0.5 <= significand < 1
84 // PSDB/3 = significand * 2^exponent
85 // the division by 3 is to ensure that max value <= 2^30
86
87 printf("PSDB / 3 : %16.8e\n",PSDB/3);
88 printf("significand : %16.8e\n",significand);
89 printf("exponent : %d\n" ,exponent);
90
91 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
92 exponent = expmin;
93 significand = 0.5; // min value that can be recorded
94 }
95 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
96 exponent = expmax;
97 significand = 1.0; // max value that can be recorded
98 }
99 if (significand == 0) {// in that case exponent == 0 too
100 exponent = expmin;
101 significand = 0.5; // min value that can be recorded
102 }
103
104 psd = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
105 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
106 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
107 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
108 pt_u_short_int = (unsigned short int*) &LFR_BP1_F0[i*9+7]; // affect an unsigned short int pointer with the
109 // adress where the 16-bit word result will be stored
110 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // put the exponent bits (nbitexp) next to the
111 // left place of the significand bits (nbitsig), making
112 // the 16-bit word to be recorded, and record it using the pointer
113 #ifdef DEBUG_TCH
114 printf("psd for PSDB significand : %d\n",psd);
115 printf("tmp_u_short_int for PSDB exponent : %d\n",tmp_u_short_int);
116 printf("*pt_u_short_int for PSDB significand + exponent: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
117 printf("LFR_BP1_F0[i*9+8] : %.3d or %.2x\n",LFR_BP1_F0[i*9+8], LFR_BP1_F0[i*9+8]);
118 printf("LFR_BP1_F0[i*9+7] : %.3d or %.2x\n",LFR_BP1_F0[i*9+7], LFR_BP1_F0[i*9+7]);
119 #endif
120
121 //toto_f = 32768*32768; // max value ?
122 //toto_f = 1./3; // min value ?
123 //significand = frexp(toto_f, &exponent);
124 //printf("toto_f : %16.8e\n",toto_f);
125 //printf("significand : %16.8e\n",significand);
126 //printf("exponent : %d\n" ,exponent);
127
128 //==============================================
129 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
130 PSDE = compressed_spectral_matrix_f0[i*30+24] * k44_pe // S44
131 + compressed_spectral_matrix_f0[i*30+28] * k55_pe // S55
132 + compressed_spectral_matrix_f0[i*30+26] * k45_pe_re // S45 Re
133 - compressed_spectral_matrix_f0[i*30+27] * k45_pe_im; // S45 Im
134
135 significand = frexpf(PSDE/2, &exponent); // 0.5 <= significand < 1
136 // PSDE/2 = significand * 2^exponent
137 // the division by 2 is to ensure that max value <= 2^30
138 // should be reconsidered by taking into account the k-coefficients ...
139
140 printf("PSDE / 2 : %16.8e\n",PSDE/2);
141 printf("significand : %16.8e\n",significand);
142 printf("exponent : %d\n" ,exponent);
143
144 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
145 exponent = expmin;
146 significand = 0.5; // min value that can be recorded
147 }
148 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
149 exponent = expmax;
150 significand = 1.0; // max value that can be recorded
151 }
152 if (significand == 0) {// in that case exponent == 0 too
153 exponent = expmin;
154 significand = 0.5; // min value that can be recorded
155 }
156
157 psd = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
158 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
159 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
160 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
161 pt_u_short_int = (unsigned short int*) &LFR_BP1_F0[i*9+5]; // affect an unsigned short int pointer with the
162 // adress where the 16-bit word result will be stored
163 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // put the exponent bits (nbitexp) next to the
164 // left place of the significand bits (nbitsig), making
165 // the 16-bit word to be recorded, and record it using the pointer
166 printf("psd for PSDE significand : %d\n",psd);
167 printf("tmp_u_short_int for PSDE exponent : %d\n",tmp_u_short_int);
168 printf("*pt_u_short_int for PSDE significand + exponent: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
169 printf("LFR_BP1_F0[i*9+6] : %.3d or %.2x\n",LFR_BP1_F0[i*9+6], LFR_BP1_F0[i*9+6]);
170 printf("LFR_BP1_F0[i*9+5] : %.3d or %.2x\n",LFR_BP1_F0[i*9+5], LFR_BP1_F0[i*9+5]);
171
172 //==============================================================================
173 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
174 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
175 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
176 tmp = sqrt( compressed_spectral_matrix_f0[i*30+3] *compressed_spectral_matrix_f0[i*30+3] //Im S12
177 +compressed_spectral_matrix_f0[i*30+5] *compressed_spectral_matrix_f0[i*30+5] //Im S13
178 +compressed_spectral_matrix_f0[i*30+13]*compressed_spectral_matrix_f0[i*30+13] //Im S23
179 );
180 NVEC_V0 = compressed_spectral_matrix_f0[i*30+13]/ tmp; // S23 Im => n1
181 NVEC_V1 = -compressed_spectral_matrix_f0[i*30+5] / tmp; // S13 Im => n2
182 NVEC_V2 = compressed_spectral_matrix_f0[i*30+3] / tmp; // S12 Im => n3
183
184 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
185 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
186 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
187
188 LFR_BP1_F0[i*9+4] = (unsigned char) (NVEC_V0*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
189 LFR_BP1_F0[i*9+3] = (unsigned char) (NVEC_V1*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
190 pt_u_char = (unsigned char*) &NVEC_V2; // affect an unsigned char pointer with the adress of NVEC_V2
191 LFR_BP1_F0[i*9+2] = pt_u_char[3] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet)
192 // record it at the 8th bit position (from the right to the left) of LFR_BP1_F0[i*9+2]
193
194 printf("LFR_BP1_F0[i*9+4] for NVEC_V0 : %u\n",LFR_BP1_F0[i*9+4]);
195 printf("LFR_BP1_F0[i*9+3] for NVEC_V1 : %u\n",LFR_BP1_F0[i*9+3]);
196 printf("LFR_BP1_F0[i*9+2] for NVEC_V2 : %u\n",LFR_BP1_F0[i*9+2]);
197
198 //toto_f = 128.9999 ;
199 //toto_s_char = (signed char) toto_f;
200 //printf("toto_s_char : %d\n",toto_s_char);
201
202 //toto_f = 255.999 ;
203 //toto_u_char = (unsigned char) (toto_f);
204 //printf("toto_u_char : %d\n",toto_u_char);
205
206 //toto_f = -1110.999 ;
207 //pt_toto_u_char = (unsigned char*) &toto_f;
208 //printf("pt_toto_u_char : %u\n", pt_toto_u_char[3] & 0x80);
209
210 //=======================================================
211 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
212 aux = 2*tmp / PSDB; // compute the ellipticity
213
214 printf("ellipticity : %16.8e\n",aux);
215
216 tmp_u_char = (unsigned char) (aux*15 + 0.5); // shift and cast into a 8-bit unsigned char with rounding
217 // where just the first 4 bits are used (0, ..., 15)
218 LFR_BP1_F0[i*9+2] = LFR_BP1_F0[i*9+2] | (tmp_u_char << 3); // put these 4 bits next to the right place
219 // of the sign bit of NVEC_V2 (recorded
220 // previously in LFR_BP1_F0[i*9+2])
221
222 printf("tmp_u_char for ellipticity : %u\n",tmp_u_char);
223 printf("LFR_BP1_F0[i*9+2] for NVEC_V2 + ellipticity : %u\n",LFR_BP1_F0[i*9+2]);
224
225 //==============================================================
226 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
227 tr_SB_SB = compressed_spectral_matrix_f0[i*30] *compressed_spectral_matrix_f0[i*30]
228 + compressed_spectral_matrix_f0[i*30+10]*compressed_spectral_matrix_f0[i*30+10]
229 + compressed_spectral_matrix_f0[i*30+18]*compressed_spectral_matrix_f0[i*30+18]
230 + 2 * compressed_spectral_matrix_f0[i*30+2] *compressed_spectral_matrix_f0[i*30+2]
231 + 2 * compressed_spectral_matrix_f0[i*30+3] *compressed_spectral_matrix_f0[i*30+3]
232 + 2 * compressed_spectral_matrix_f0[i*30+4] *compressed_spectral_matrix_f0[i*30+4]
233 + 2 * compressed_spectral_matrix_f0[i*30+5] *compressed_spectral_matrix_f0[i*30+5]
234 + 2 * compressed_spectral_matrix_f0[i*30+12]*compressed_spectral_matrix_f0[i*30+12]
235 + 2 * compressed_spectral_matrix_f0[i*30+13]*compressed_spectral_matrix_f0[i*30+13];
236 aux = PSDB*PSDB;
237 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // compute the degree of polarisation
238
239 printf("DOP : %16.8e\n",tmp);
240
241 tmp_u_char = (unsigned char) (tmp*7 + 0.5);// shift and cast into a 8-bit unsigned char with rounding
242 // where just the first 3 bits are used (0, ..., 7)
243 LFR_BP1_F0[i*9+2] = LFR_BP1_F0[i*9+2] | tmp_u_char; // record these 3 bits at the 3 first bit positions
244 // (from the right to the left) of LFR_BP1_F0[i*9+2]
245
246 printf("tmp_u_char for DOP : %u\n",tmp_u_char);
247 printf("LFR_BP1_F0[i*9+2] for NVEC_V2 + ellipticity + DOP : %u\n",LFR_BP1_F0[i*9+2]);
248
249 //=======================================================================================
250 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 8 (+ 2) bits
251 // = 5 bits (exponent) + 3 bits (significand)
252 // + 1 sign bit + 1 argument bit (two sectors)
253 e_cross_b_re = compressed_spectral_matrix_f0[i*30+20]*k34_sx_re //S34 Re
254 + compressed_spectral_matrix_f0[i*30+22]*k35_sx_re //S35 Re
255 + compressed_spectral_matrix_f0[i*30+6] *k14_sx_re //S14 Re
256 + compressed_spectral_matrix_f0[i*30+8] *k15_sx_re //S15 Re
257 + compressed_spectral_matrix_f0[i*30+14]*k24_sx_re //S24 Re
258 + compressed_spectral_matrix_f0[i*30+16]*k25_sx_re //S25 Re
259 + compressed_spectral_matrix_f0[i*30+21]*k34_sx_im //S34 Im
260 + compressed_spectral_matrix_f0[i*30+23]*k35_sx_im //S35 Im
261 + compressed_spectral_matrix_f0[i*30+7] *k14_sx_im //S14 Im
262 + compressed_spectral_matrix_f0[i*30+9] *k15_sx_im //S15 Im
263 + compressed_spectral_matrix_f0[i*30+15]*k24_sx_im //S24 Im
264 + compressed_spectral_matrix_f0[i*30+17]*k25_sx_im; //S25 Im
265 // Im(S_ji) = -Im(S_ij)
266 // k_ji = k_ij
267 e_cross_b_im = compressed_spectral_matrix_f0[i*30+20]*k34_sx_im //S34 Re
268 + compressed_spectral_matrix_f0[i*30+22]*k35_sx_im //S35 Re
269 + compressed_spectral_matrix_f0[i*30+6] *k14_sx_im //S14 Re
270 + compressed_spectral_matrix_f0[i*30+8] *k15_sx_im //S15 Re
271 + compressed_spectral_matrix_f0[i*30+14]*k24_sx_im //S24 Re
272 + compressed_spectral_matrix_f0[i*30+16]*k25_sx_im //S25 Re
273 - compressed_spectral_matrix_f0[i*30+21]*k34_sx_re //S34 Im
274 - compressed_spectral_matrix_f0[i*30+23]*k35_sx_re //S35 Im
275 - compressed_spectral_matrix_f0[i*30+7] *k14_sx_re //S14 Im
276 - compressed_spectral_matrix_f0[i*30+9] *k15_sx_re //S15 Im
277 - compressed_spectral_matrix_f0[i*30+15]*k24_sx_re //S24 Im
278 - compressed_spectral_matrix_f0[i*30+17]*k25_sx_re; //S25 Im
279
280 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
281
282 pt_u_char = (unsigned char*) &e_cross_b_re; // Affect an unsigned char pointer with the adress of e_cross_b_re
283 LFR_BP1_F0[i*9+8] = LFR_BP1_F0[i*9+8] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet)
284 // Record it at the 8th bit position (from the right to the left)
285 // of LFR_BP1_F0[i*9+8]
286 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
287
288 significand = frexpf(e_cross_b_re/2, &exponent);// 0.5 <= significand < 1
289 // ReaSX/2 = significand * 2^exponent
290 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
291 // Should be reconsidered by taking into account the k-coefficients ...
292
293 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
294 exponent = expmin;
295 significand = 0.5; // min value that can be recorded
296 }
297 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
298 exponent = expmax;
299 significand = 1.0; // max value that can be recorded
300 }
301 if (significand == 0) {// in that case exponent == 0 too
302 exponent = expmin;
303 significand = 0.5; // min value that can be recorded
304 }
305 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
306 printf("significand : %16.8e\n",significand);
307 printf("exponent : %d\n" ,exponent);
308
309 LFR_BP1_F0[i*9+1] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
310 // where just the first 3 bits are used (0, ..., 7)
311 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
312 // just the first 5 bits are used (0, ..., 2^5-1)
313 printf("LFR_BP1_F0[i*9+1] for ReaSX significand : %u\n",LFR_BP1_F0[i*9+1]);
314 printf("tmp_u_char for ReaSX exponent : %d\n",tmp_u_char);
315 LFR_BP1_F0[i*9+1] = LFR_BP1_F0[i*9+1] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
316 // with LFR_BP1_F0[i*9+1]
317 printf("LFR_BP1_F0[i*9+1] for ReaSX exponent + significand : %u\n",LFR_BP1_F0[i*9+1]);
318 printf("LFR_BP1_F0[i*9+8] for ReaSX sign + PSDB 'exponent' : %u\n",LFR_BP1_F0[i*9+8]);
319
320 printf("ImaSX / 2 : %16.8e\n",e_cross_b_im/2);
321
322 pt_u_char = (unsigned char*) &e_cross_b_im; // Affect an unsigned char pointer with the adress of e_cross_b_im
323 pt_u_char[3] = pt_u_char[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX|
324 tmp_u_char = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
325 // an unsigned 8-bit char with 01000000; otherwise with null.
326 LFR_BP1_F0[i*9+8] = LFR_BP1_F0[i*9+8] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
327 // to the left) of LFR_BP1_F0[i*9+7], by simple logical addition.
328
329 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
330 printf("ArgSX sign : %u\n",tmp_u_char);
331 printf("LFR_BP1_F0[i*9+8] for ReaSX & ArgSX signs + PSDB 'exponent' : %u\n",LFR_BP1_F0[i*9+8]);
332
333 //======================================================================
334 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 8 (+ 2) bits
335 // = 5 bits (exponent) + 3 bits (significand)
336 // + 1 sign bit + 1 argument bit (two sectors)
337 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
338 nz = NVEC_V0;
339 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spectral_matrix_f0[i*30+10] // S22 Re
340 + sin(alpha_M)*sin(alpha_M)*compressed_spectral_matrix_f0[i*30+18] // S33 Re
341 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spectral_matrix_f0[i*30+12]; // S23 Re
342
343 n_cross_e_scal_b_re = ny * (compressed_spectral_matrix_f0[i*30+14]*k24_ny_re //S24 Re
344 +compressed_spectral_matrix_f0[i*30+16]*k25_ny_re //S25 Re
345 +compressed_spectral_matrix_f0[i*30+20]*k34_ny_re //S34 Re
346 +compressed_spectral_matrix_f0[i*30+22]*k35_ny_re //S35 Re
347 +compressed_spectral_matrix_f0[i*30+15]*k24_ny_im //S24 Im
348 +compressed_spectral_matrix_f0[i*30+17]*k25_ny_im //S25 Im
349 +compressed_spectral_matrix_f0[i*30+21]*k34_ny_im //S34 Im
350 +compressed_spectral_matrix_f0[i*30+23]*k35_ny_im) //S35 Im
351 + nz * (compressed_spectral_matrix_f0[i*30+14]*k24_nz_re //S24 Re
352 +compressed_spectral_matrix_f0[i*30+16]*k25_nz_re //S25 Re
353 +compressed_spectral_matrix_f0[i*30+20]*k34_nz_re //S34 Re
354 +compressed_spectral_matrix_f0[i*30+22]*k35_nz_re //S35 Re
355 +compressed_spectral_matrix_f0[i*30+15]*k24_nz_im //S24 Im
356 +compressed_spectral_matrix_f0[i*30+17]*k25_nz_im //S25 Im
357 +compressed_spectral_matrix_f0[i*30+21]*k34_nz_im //S34 Im
358 +compressed_spectral_matrix_f0[i*30+23]*k35_nz_im);//S35 Im
359 // Im(S_ji) = -Im(S_ij)
360 // k_ji = k_ij
361 n_cross_e_scal_b_im = ny * (compressed_spectral_matrix_f0[i*30+14]*k24_ny_im //S24 Re
362 +compressed_spectral_matrix_f0[i*30+16]*k25_ny_im //S25 Re
363 +compressed_spectral_matrix_f0[i*30+20]*k34_ny_im //S34 Re
364 +compressed_spectral_matrix_f0[i*30+22]*k35_ny_im //S35 Re
365 -compressed_spectral_matrix_f0[i*30+15]*k24_ny_re //S24 Im
366 -compressed_spectral_matrix_f0[i*30+17]*k25_ny_re //S25 Im
367 -compressed_spectral_matrix_f0[i*30+21]*k34_ny_re //S34 Im
368 -compressed_spectral_matrix_f0[i*30+23]*k35_ny_re) //S35 Im
369 + nz * (compressed_spectral_matrix_f0[i*30+14]*k24_nz_im //S24 Re
370 +compressed_spectral_matrix_f0[i*30+16]*k25_nz_im //S25 Re
371 +compressed_spectral_matrix_f0[i*30+20]*k34_nz_im //S34 Re
372 +compressed_spectral_matrix_f0[i*30+22]*k35_nz_im //S35 Re
373 -compressed_spectral_matrix_f0[i*30+15]*k24_nz_re //S24 Im
374 -compressed_spectral_matrix_f0[i*30+17]*k25_nz_re //S25 Im
375 -compressed_spectral_matrix_f0[i*30+21]*k34_nz_re //S34 Im
376 -compressed_spectral_matrix_f0[i*30+23]*k35_nz_re);//S35 Im
377
378 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
379 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
380 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
381 pt_u_char = (unsigned char*) &n_cross_e_scal_b_re; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_re
382 LFR_BP1_F0[i*9+7] = LFR_BP1_F0[i*9+7] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet)
383 // Record it at the 8th bit position (from the right to the left)
384 // of LFR_BP1_F0[i*9+7]
385 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
386 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
387
388 significand = frexpf(vphi/2, &exponent); // 0.5 <= significand < 1
389 // vphi/2 = significand * 2^exponent
390 // The division by 2 is to ensure that max value <= 2^30 (rough estimate)
391 // Should be reconsidered by taking into account the k-coefficients ...
392
393 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
394 exponent = expmin;
395 significand = 0.5; // min value that can be recorded
396 }
397 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
398 exponent = expmax;
399 significand = 1.0; // max value that can be recorded
400 }
401 if (significand == 0) {// in that case exponent == 0 too
402 exponent = expmin;
403 significand = 0.5; // min value that can be recorded
404 }
405 printf("|VPHI| / 2 : %16.8e\n",vphi/2);
406 printf("significand : %16.8e\n",significand);
407 printf("exponent : %d\n" ,exponent);
408
409 LFR_BP1_F0[i*9+0] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
410 // where just the first 3 bits are used (0, ..., 7)
411 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
412 // just the first 5 bits are used (0, ..., 2^5-1)
413 printf("LFR_BP1_F0[i*9+0] for VPHI significand : %u\n",LFR_BP1_F0[i*9+0]);
414 printf("tmp_u_char for VPHI exponent : %d\n",tmp_u_char);
415 LFR_BP1_F0[i*9+0] = LFR_BP1_F0[i*9+0] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
416 // with LFR_BP1_F0[i*9+0]
417 printf("LFR_BP1_F0[i*9+0] for VPHI exponent + significand : %u\n",LFR_BP1_F0[i*9+0]);
418 printf("LFR_BP1_F0[i*9+6] for VPHI sign + PSDE 'exponent' : %u\n",LFR_BP1_F0[i*9+6]);
419
420 pt_u_char = (unsigned char*) &n_cross_e_scal_b_im; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_im
421 pt_u_char[3] = pt_u_char[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaSX|
422 tmp_u_char = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
423 // an unsigned 8-bit char with 01000000; otherwise with null.
424 LFR_BP1_F0[i*9+6] = LFR_BP1_F0[i*9+6] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
425 // to the left) of LFR_BP1_F0[i*9+6], by simple logical addition.
426
427 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
428 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
429 printf("ArgNEBX sign : %u\n",tmp_u_char);
430 printf("LFR_BP1_F0[i*9+6] for VPHI & ArgNEBX signs + PSDE 'exponent' : %u\n",LFR_BP1_F0[i*9+6]);
431
432 }
433 }
434
435 void BP2_set(){
436 int i, exponent;
437 float aux, significand, cross_re, cross_im;
438 signed char nbitexp, nbitsig, expmin, expmax; // 8 bits
439 short int rangesig; // 16 bits
440 unsigned short int autocor, tmp_u_short_int; // 16 bits
441 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
442
443 printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0);
444 printf("BP2 : \n");
445
446 // For floating point data to be recorded on 16-bit words :
447 nbitexp = 6; // number of bits for the exponent
448 nbitsig = 16 - nbitexp; // number of bits for the significand
449 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
450 printf("nbitexp : %d, nbitsig : %d, rangesig : %d\n", nbitexp, nbitsig, rangesig);
451 expmax = 32;
452 expmin = expmax - (1 << nbitexp) + 1;
453 printf("expmin : %d, expmax : %d\n", expmin, expmax);
454
455 for(i = 0; i<1; i++){
456 //==============================================
457 // BP2 normalized cross correlations == PA_LFR_SC_BP2_CROSS_F0 == 10 * (8+8) bits
458 // == PA_LFR_SC_BP2_CROSS_RE_0_F0 == 8 bits
459 // == PA_LFR_SC_BP2_CROSS_IM_0_F0 == 8 bits
460 // == PA_LFR_SC_BP2_CROSS_RE_1_F0 == 8 bits
461 // == PA_LFR_SC_BP2_CROSS_IM_1_F0 == 8 bits
462 // == PA_LFR_SC_BP2_CROSS_RE_2_F0 == 8 bits
463 // == PA_LFR_SC_BP2_CROSS_IM_2_F0 == 8 bits
464 // == PA_LFR_SC_BP2_CROSS_RE_3_F0 == 8 bits
465 // == PA_LFR_SC_BP2_CROSS_IM_3_F0 == 8 bits
466 // == PA_LFR_SC_BP2_CROSS_RE_4_F0 == 8 bits
467 // == PA_LFR_SC_BP2_CROSS_IM_4_F0 == 8 bits
468 // == PA_LFR_SC_BP2_CROSS_RE_5_F0 == 8 bits
469 // == PA_LFR_SC_BP2_CROSS_IM_5_F0 == 8 bits
470 // == PA_LFR_SC_BP2_CROSS_RE_6_F0 == 8 bits
471 // == PA_LFR_SC_BP2_CROSS_IM_6_F0 == 8 bits
472 // == PA_LFR_SC_BP2_CROSS_RE_7_F0 == 8 bits
473 // == PA_LFR_SC_BP2_CROSS_IM_7_F0 == 8 bits
474 // == PA_LFR_SC_BP2_CROSS_RE_8_F0 == 8 bits
475 // == PA_LFR_SC_BP2_CROSS_IM_8_F0 == 8 bits
476 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
477 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
478 // S12
479 aux = sqrt(compressed_spectral_matrix_f0[i*30]*compressed_spectral_matrix_f0[i*30+10]);
480 cross_re = compressed_spectral_matrix_f0[i*30+2] / aux;
481 cross_im = compressed_spectral_matrix_f0[i*30+3] / aux;
482 LFR_BP2_F0[i*30+19] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
483 LFR_BP2_F0[i*30+9] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
484 printf("LFR_BP2_F0[i*30+19] for cross12_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+19]);
485 printf("LFR_BP2_F0[i*30+9] for cross12_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+9]);
486
487 // S13
488 aux = sqrt(compressed_spectral_matrix_f0[i*30]*compressed_spectral_matrix_f0[i*30+18]);
489 cross_re = compressed_spectral_matrix_f0[i*30+4] / aux;
490 cross_im = compressed_spectral_matrix_f0[i*30+5] / aux;
491 LFR_BP2_F0[i*30+18] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
492 LFR_BP2_F0[i*30+8] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
493 printf("LFR_BP2_F0[i*30+18] for cross13_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+18]);
494 printf("LFR_BP2_F0[i*30+8] for cross13_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+8]);
495
496 // S14
497 aux = sqrt(compressed_spectral_matrix_f0[i*30]*compressed_spectral_matrix_f0[i*30+24]);
498 cross_re = compressed_spectral_matrix_f0[i*30+6] / aux;
499 cross_im = compressed_spectral_matrix_f0[i*30+7] / aux;
500 LFR_BP2_F0[i*30+17] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
501 LFR_BP2_F0[i*30+7] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
502 printf("LFR_BP2_F0[i*30+17] for cross14_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+17]);
503 printf("LFR_BP2_F0[i*30+7] for cross14_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+7]);
504 // S15
505 aux = sqrt(compressed_spectral_matrix_f0[i*30]*compressed_spectral_matrix_f0[i*30+28]);
506 cross_re = compressed_spectral_matrix_f0[i*30+8] / aux;
507 cross_im = compressed_spectral_matrix_f0[i*30+9] / aux;
508 LFR_BP2_F0[i*30+16] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
509 LFR_BP2_F0[i*30+6] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
510 printf("LFR_BP2_F0[i*30+16] for cross15_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+16]);
511 printf("LFR_BP2_F0[i*30+6] for cross15_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+6]);
512 // S23
513 aux = sqrt(compressed_spectral_matrix_f0[i*30+10]*compressed_spectral_matrix_f0[i*30+18]);
514 cross_re = compressed_spectral_matrix_f0[i*30+12] / aux;
515 cross_im = compressed_spectral_matrix_f0[i*30+13] / aux;
516 LFR_BP2_F0[i*30+15] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
517 LFR_BP2_F0[i*30+5] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
518 printf("LFR_BP2_F0[i*30+15] for cross23_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+15]);
519 printf("LFR_BP2_F0[i*30+5] for cross23_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+5]);
520 // S24
521 aux = sqrt(compressed_spectral_matrix_f0[i*30+10]*compressed_spectral_matrix_f0[i*30+24]);
522 cross_re = compressed_spectral_matrix_f0[i*30+14] / aux;
523 cross_im = compressed_spectral_matrix_f0[i*30+15] / aux;
524 LFR_BP2_F0[i*30+14] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
525 LFR_BP2_F0[i*30+4] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
526 printf("LFR_BP2_F0[i*30+14] for cross24_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+14]);
527 printf("LFR_BP2_F0[i*30+4] for cross24_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+4]);
528 // S25
529 aux = sqrt(compressed_spectral_matrix_f0[i*30+10]*compressed_spectral_matrix_f0[i*30+28]);
530 cross_re = compressed_spectral_matrix_f0[i*30+16] / aux;
531 cross_im = compressed_spectral_matrix_f0[i*30+17] / aux;
532 LFR_BP2_F0[i*30+13] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
533 LFR_BP2_F0[i*30+3] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
534 printf("LFR_BP2_F0[i*30+13] for cross25_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+13]);
535 printf("LFR_BP2_F0[i*30+3] for cross25_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+3]);
536 // S34
537 aux = sqrt(compressed_spectral_matrix_f0[i*30+18]*compressed_spectral_matrix_f0[i*30+24]);
538 cross_re = compressed_spectral_matrix_f0[i*30+20] / aux;
539 cross_im = compressed_spectral_matrix_f0[i*30+21] / aux;
540 LFR_BP2_F0[i*30+12] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
541 LFR_BP2_F0[i*30+2] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
542 printf("LFR_BP2_F0[i*30+12] for cross34_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+12]);
543 printf("LFR_BP2_F0[i*30+2] for cross34_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+2]);
544 // S35
545 aux = sqrt(compressed_spectral_matrix_f0[i*30+18]*compressed_spectral_matrix_f0[i*30+28]);
546 cross_re = compressed_spectral_matrix_f0[i*30+22] / aux;
547 cross_im = compressed_spectral_matrix_f0[i*30+23] / aux;
548 LFR_BP2_F0[i*30+11] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
549 LFR_BP2_F0[i*30+1] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
550 printf("LFR_BP2_F0[i*30+11] for cross35_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+11]);
551 printf("LFR_BP2_F0[i*30+1] for cross35_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+1]);
552 // S45
553 aux = sqrt(compressed_spectral_matrix_f0[i*30+24]*compressed_spectral_matrix_f0[i*30+28]);
554 cross_re = compressed_spectral_matrix_f0[i*30+26] / aux;
555 cross_im = compressed_spectral_matrix_f0[i*30+27] / aux;
556 LFR_BP2_F0[i*30+10] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
557 LFR_BP2_F0[i*30+0] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
558 printf("LFR_BP2_F0[i*30+10] for cross45_re (%16.8e) : %.3u\n",cross_re, LFR_BP2_F0[i*30+10]);
559 printf("LFR_BP2_F0[i*30+0] for cross45_im (%16.8e) : %.3u\n",cross_im, LFR_BP2_F0[i*30+0]);
560
561 //==============================================
562 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
563 // == PA_LFR_SC_BP2_AUTO_A0_F0 == 16 bits
564 // == PA_LFR_SC_BP2_AUTO_A1_F0 == 16 bits
565 // == PA_LFR_SC_BP2_AUTO_A2_F0 == 16 bits
566 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
567 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
568 // S11
569 significand = frexpf(compressed_spectral_matrix_f0[i*30], &exponent); // 0.5 <= significand < 1
570 // S11 = significand * 2^exponent
571 printf("S11 : %16.8e\n",compressed_spectral_matrix_f0[i*30]);
572 printf("significand : %16.8e\n",significand);
573 printf("exponent : %d\n" ,exponent);
574
575 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
576 exponent = expmin;
577 significand = 0.5; // min value that can be recorded
578 }
579 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
580 exponent = expmax;
581 significand = 1.0; // max value that can be recorded
582 }
583 if (significand == 0) {// in that case exponent == 0 too
584 exponent = expmin;
585 significand = 0.5; // min value that can be recorded
586 }
587
588 autocor = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
589 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
590 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
591 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
592 pt_u_short_int = (unsigned short int*) &LFR_BP2_F0[i*30+28]; // affect an unsigned short int pointer with the
593 // adress where the 16-bit word result will be stored
594 *pt_u_short_int = autocor | (tmp_u_short_int << nbitsig); // put the exponent bits (nbitexp) next to the
595 // left place of the significand bits (nbitsig), making
596 // the 16-bit word to be recorded, and record it using the pointer
597 //printf("size of autocor : %d\n",sizeof(autocor) );
598 //printf("size of tmp_u_short_int : %d\n",sizeof(tmp_u_short_int) );
599 printf("autocor for S11 significand : %u\n",autocor );
600 printf("tmp_u_char for S11 exponent : %u\n",tmp_u_short_int );
601 printf("*pt_u_short_int for S11 significand + exponent: %u or %x\n",*pt_u_short_int, *pt_u_short_int);
602 printf("LFR_BP2_F0[i*30+29] : %u or %x\n",LFR_BP2_F0[i*30+29], LFR_BP2_F0[i*30+29]);
603 printf("LFR_BP2_F0[i*30+28] : %u or %x\n",LFR_BP2_F0[i*30+28], LFR_BP2_F0[i*30+28]);
604 // S22
605 significand = frexpf(compressed_spectral_matrix_f0[i*30+10], &exponent); // 0.5 <= significand < 1
606 // S22 = significand * 2^exponent
607 printf("S22 : %16.8e\n",compressed_spectral_matrix_f0[i*30+10]);
608 printf("significand : %16.8e\n",significand);
609 printf("exponent : %d\n" ,exponent);
610
611 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
612 exponent = expmin;
613 significand = 0.5; // min value that can be recorded
614 }
615 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
616 exponent = expmax;
617 significand = 1.0; // max value that can be recorded
618 }
619 if (significand == 0) {// in that case exponent == 0 too
620 exponent = expmin;
621 significand = 0.5; // min value that can be recorded
622 }
623
624 autocor = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
625 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
626 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
627 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
628 pt_u_short_int = (unsigned short int*) &LFR_BP2_F0[i*30+26]; // affect an unsigned short int pointer with the
629 // adress where the 16-bit word result will be stored
630 *pt_u_short_int = autocor | (tmp_u_short_int << nbitsig); // put the exponent bits (nbitexp) next to the
631 // left place of the significand bits (nbitsig), making
632 // the 16-bit word to be recorded, and record it using the pointer
633 printf("autocor for S22 significand : %d\n",autocor );
634 printf("tmp_u_char for S22 exponent : %d\n",tmp_u_short_int );
635 printf("*pt_u_short_int for S22 significand + exponent: %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
636 printf("LFR_BP2_F0[i*30+27] : %.3d or %x\n",LFR_BP2_F0[i*30+27], LFR_BP2_F0[i*30+27]);
637 printf("LFR_BP2_F0[i*30+26] : %.3d or %x\n",LFR_BP2_F0[i*30+26], LFR_BP2_F0[i*30+26]);
638 // S33
639 significand = frexpf(compressed_spectral_matrix_f0[i*30+18], &exponent); // 0.5 <= significand < 1
640 // S33 = significand * 2^exponent
641 printf("S33 : %16.8e\n",compressed_spectral_matrix_f0[i*30+18]);
642 printf("significand : %16.8e\n",significand);
643 printf("exponent : %d\n" ,exponent);
644
645 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
646 exponent = expmin;
647 significand = 0.5; // min value that can be recorded
648 }
649 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
650 exponent = expmax;
651 significand = 1.0; // max value that can be recorded
652 }
653 if (significand == 0) {// in that case exponent == 0 too
654 exponent = expmin;
655 significand = 0.5; // min value that can be recorded
656 }
657
658 autocor = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
659 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
660 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
661 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
662 pt_u_short_int = (unsigned short int*) &LFR_BP2_F0[i*30+24]; // affect an unsigned short int pointer with the
663 // adress where the 16-bit word result will be stored
664 *pt_u_short_int = autocor | (tmp_u_short_int << nbitsig); // put the exponent bits (nbitexp) next to the
665 // left place of the significand bits (nbitsig), making
666 // the 16-bit word to be recorded, and record it using the pointer
667 printf("autocor for S33 significand : %d\n",autocor );
668 printf("tmp_u_char for S33 exponent : %d\n",tmp_u_short_int );
669 printf("*pt_u_short_int for S33 significand + exponent: %.3d or %x\n",*pt_u_short_int, *pt_u_short_int);
670 printf("LFR_BP2_F0[i*30+25] : %.3d or %x\n",LFR_BP2_F0[i*30+25], LFR_BP2_F0[i*30+25]);
671 printf("LFR_BP2_F0[i*30+24] : %.3d or %x\n",LFR_BP2_F0[i*30+24], LFR_BP2_F0[i*30+24]);
672 // S44
673 significand = frexpf(compressed_spectral_matrix_f0[i*30+24], &exponent); // 0.5 <= significand < 1
674 // S44 = significand * 2^exponent
675 printf("S44 : %16.8e\n",compressed_spectral_matrix_f0[i*30+24]);
676 printf("significand : %16.8e\n",significand);
677 printf("exponent : %d\n" ,exponent);
678
679 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
680 exponent = expmin;
681 significand = 0.5; // min value that can be recorded
682 }
683 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
684 exponent = expmax;
685 significand = 1.0; // max value that can be recorded
686 }
687 if (significand == 0) {// in that case exponent == 0 too
688 exponent = expmin;
689 significand = 0.5; // min value that can be recorded
690 }
691
692 autocor = (unsigned short int) ((significand*2-1)*rangesig + 0.5); // shift and cast into a 16-bit unsigned int with rounding
693 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
694 tmp_u_short_int = (unsigned short int) (exponent-expmin); // shift and cast into a 16-bit unsigned int
695 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
696 pt_u_short_int = (unsigned short int*) &LFR_BP2_F0[i*30+22]; // affect an unsigned short int pointer with the
697 // adress where the 16-bit word result will be stored
698