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