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