blob: be8b180f5f632962091fb9b6ce8b6bca22c07d85 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
kurtis.heimerla198d452011-11-26 03:19:28 +00002* Copyright 2008, 2011 Free Software Foundation, Inc.
dburgessb3a0ca42011-10-12 07:44:40 +00003*
4* This software is distributed under the terms of the GNU Affero Public License.
5* See the COPYING file in the main directory for details.
6*
7* This use of this software may be subject to additional restrictions.
8* See the LEGAL file in the main directory for details.
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23*/
24
dburgessb3a0ca42011-10-12 07:44:40 +000025#include "sigProcLib.h"
26#include "GSMCommon.h"
kurtis.heimerla198d452011-11-26 03:19:28 +000027#include "sendLPF_961.h"
28#include "rcvLPF_651.h"
dburgessb3a0ca42011-10-12 07:44:40 +000029
Thomas Tsouacc9ee92013-08-20 19:31:14 -040030extern "C" {
31#include "convolve.h"
32}
33
Alexander Chemerisd734e2d2013-06-16 14:30:58 +040034using namespace GSM;
35
dburgessb3a0ca42011-10-12 07:44:40 +000036#define TABLESIZE 1024
37
38/** Lookup tables for trigonometric approximation */
39float cosTable[TABLESIZE+1]; // add 1 element for wrap around
40float sinTable[TABLESIZE+1];
41
42/** Constants */
43static const float M_PI_F = (float)M_PI;
44static const float M_2PI_F = (float)(2.0*M_PI);
45static const float M_1_2PI_F = 1/M_2PI_F;
46
47/** Static vectors that contain a precomputed +/- f_b/4 sinusoid */
48signalVector *GMSKRotation = NULL;
49signalVector *GMSKReverseRotation = NULL;
50
Thomas Tsoud6ed8c02013-08-20 16:27:12 -040051/*
Thomas Tsouacc9ee92013-08-20 19:31:14 -040052 * RACH and midamble correlation waveforms. Store the buffer separately
53 * because we need to allocate it explicitly outside of the signal vector
54 * constructor. This is because C++ (prior to C++11) is unable to natively
55 * perform 16-byte memory alignment required by many SSE instructions.
Thomas Tsoud6ed8c02013-08-20 16:27:12 -040056 */
57struct CorrelationSequence {
Thomas Tsouacc9ee92013-08-20 19:31:14 -040058 CorrelationSequence() : sequence(NULL), buffer(NULL)
Thomas Tsoud6ed8c02013-08-20 16:27:12 -040059 {
60 }
61
62 ~CorrelationSequence()
63 {
64 delete sequence;
Thomas Tsouacc9ee92013-08-20 19:31:14 -040065 free(buffer);
Thomas Tsoud6ed8c02013-08-20 16:27:12 -040066 }
67
dburgessb3a0ca42011-10-12 07:44:40 +000068 signalVector *sequence;
Thomas Tsouacc9ee92013-08-20 19:31:14 -040069 void *buffer;
dburgessb3a0ca42011-10-12 07:44:40 +000070 float TOA;
71 complex gain;
Thomas Tsoud6ed8c02013-08-20 16:27:12 -040072};
dburgessb3a0ca42011-10-12 07:44:40 +000073
Thomas Tsouc8ce8782013-09-02 13:51:11 +080074/*
Thomas Tsouacc9ee92013-08-20 19:31:14 -040075 * Gaussian and empty modulation pulses. Like the correlation sequences,
76 * store the runtime (Gaussian) buffer separately because of needed alignment
77 * for SSE instructions.
Thomas Tsouc8ce8782013-09-02 13:51:11 +080078 */
79struct PulseSequence {
Thomas Tsou3e24f792013-09-05 05:08:09 -040080 PulseSequence() : c0(NULL), c1(NULL), empty(NULL),
81 c0_buffer(NULL), c1_buffer(NULL)
Thomas Tsouc8ce8782013-09-02 13:51:11 +080082 {
83 }
84
85 ~PulseSequence()
86 {
Thomas Tsou3e24f792013-09-05 05:08:09 -040087 delete c0;
88 delete c1;
Thomas Tsouc8ce8782013-09-02 13:51:11 +080089 delete empty;
Thomas Tsou3e24f792013-09-05 05:08:09 -040090 free(c0_buffer);
91 free(c1_buffer);
Thomas Tsouc8ce8782013-09-02 13:51:11 +080092 }
93
Thomas Tsou3e24f792013-09-05 05:08:09 -040094 signalVector *c0;
95 signalVector *c1;
Thomas Tsouc8ce8782013-09-02 13:51:11 +080096 signalVector *empty;
Thomas Tsou3e24f792013-09-05 05:08:09 -040097 void *c0_buffer;
98 void *c1_buffer;
Thomas Tsouc8ce8782013-09-02 13:51:11 +080099};
100
dburgessb3a0ca42011-10-12 07:44:40 +0000101CorrelationSequence *gMidambles[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
102CorrelationSequence *gRACHSequence = NULL;
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800103PulseSequence *GSMPulse = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000104
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400105void sigProcLibDestroy()
106{
dburgessb3a0ca42011-10-12 07:44:40 +0000107 for (int i = 0; i < 8; i++) {
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400108 delete gMidambles[i];
109 gMidambles[i] = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000110 }
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400111
112 delete GMSKRotation;
113 delete GMSKReverseRotation;
114 delete gRACHSequence;
115 delete GSMPulse;
116
117 GMSKRotation = NULL;
118 GMSKReverseRotation = NULL;
119 gRACHSequence = NULL;
120 GSMPulse = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000121}
122
dburgessb3a0ca42011-10-12 07:44:40 +0000123// dB relative to 1.0.
124// if > 1.0, then return 0 dB
125float dB(float x) {
126
127 float arg = 1.0F;
128 float dB = 0.0F;
129
130 if (x >= 1.0F) return 0.0F;
131 if (x <= 0.0F) return -200.0F;
132
133 float prevArg = arg;
134 float prevdB = dB;
135 float stepSize = 16.0F;
136 float dBstepSize = 12.0F;
137 while (stepSize > 1.0F) {
138 do {
139 prevArg = arg;
140 prevdB = dB;
141 arg /= stepSize;
142 dB -= dBstepSize;
143 } while (arg > x);
144 arg = prevArg;
145 dB = prevdB;
146 stepSize *= 0.5F;
147 dBstepSize -= 3.0F;
148 }
149 return ((arg-x)*(dB-3.0F) + (x-arg*0.5F)*dB)/(arg - arg*0.5F);
150
151}
152
153// 10^(-dB/10), inverse of dB func.
154float dBinv(float x) {
155
156 float arg = 1.0F;
157 float dB = 0.0F;
158
159 if (x >= 0.0F) return 1.0F;
160 if (x <= -200.0F) return 0.0F;
161
162 float prevArg = arg;
163 float prevdB = dB;
164 float stepSize = 16.0F;
165 float dBstepSize = 12.0F;
166 while (stepSize > 1.0F) {
167 do {
168 prevArg = arg;
169 prevdB = dB;
170 arg /= stepSize;
171 dB -= dBstepSize;
172 } while (dB > x);
173 arg = prevArg;
174 dB = prevdB;
175 stepSize *= 0.5F;
176 dBstepSize -= 3.0F;
177 }
178
179 return ((dB-x)*(arg*0.5F)+(x-(dB-3.0F))*(arg))/3.0F;
180
181}
182
183float vectorNorm2(const signalVector &x)
184{
185 signalVector::const_iterator xPtr = x.begin();
186 float Energy = 0.0;
187 for (;xPtr != x.end();xPtr++) {
188 Energy += xPtr->norm2();
189 }
190 return Energy;
191}
192
193
194float vectorPower(const signalVector &x)
195{
196 return vectorNorm2(x)/x.size();
197}
198
199/** compute cosine via lookup table */
200float cosLookup(const float x)
201{
202 float arg = x*M_1_2PI_F;
203 while (arg > 1.0F) arg -= 1.0F;
204 while (arg < 0.0F) arg += 1.0F;
205
206 const float argT = arg*((float)TABLESIZE);
207 const int argI = (int)argT;
208 const float delta = argT-argI;
209 const float iDelta = 1.0F-delta;
210 return iDelta*cosTable[argI] + delta*cosTable[argI+1];
211}
212
213/** compute sine via lookup table */
214float sinLookup(const float x)
215{
216 float arg = x*M_1_2PI_F;
217 while (arg > 1.0F) arg -= 1.0F;
218 while (arg < 0.0F) arg += 1.0F;
219
220 const float argT = arg*((float)TABLESIZE);
221 const int argI = (int)argT;
222 const float delta = argT-argI;
223 const float iDelta = 1.0F-delta;
224 return iDelta*sinTable[argI] + delta*sinTable[argI+1];
225}
226
227
228/** compute e^(-jx) via lookup table. */
229complex expjLookup(float x)
230{
231 float arg = x*M_1_2PI_F;
232 while (arg > 1.0F) arg -= 1.0F;
233 while (arg < 0.0F) arg += 1.0F;
234
235 const float argT = arg*((float)TABLESIZE);
236 const int argI = (int)argT;
237 const float delta = argT-argI;
238 const float iDelta = 1.0F-delta;
239 return complex(iDelta*cosTable[argI] + delta*cosTable[argI+1],
240 iDelta*sinTable[argI] + delta*sinTable[argI+1]);
241}
242
243/** Library setup functions */
244void initTrigTables() {
245 for (int i = 0; i < TABLESIZE+1; i++) {
246 cosTable[i] = cos(2.0*M_PI*i/TABLESIZE);
247 sinTable[i] = sin(2.0*M_PI*i/TABLESIZE);
248 }
249}
250
Thomas Tsoue01e1b32013-09-02 13:24:13 +0800251void initGMSKRotationTables(int sps)
252{
253 GMSKRotation = new signalVector(157 * sps);
254 GMSKReverseRotation = new signalVector(157 * sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000255 signalVector::iterator rotPtr = GMSKRotation->begin();
256 signalVector::iterator revPtr = GMSKReverseRotation->begin();
257 float phase = 0.0;
258 while (rotPtr != GMSKRotation->end()) {
259 *rotPtr++ = expjLookup(phase);
260 *revPtr++ = expjLookup(-phase);
Thomas Tsoue01e1b32013-09-02 13:24:13 +0800261 phase += M_PI_F / 2.0F / (float) sps;
dburgessb3a0ca42011-10-12 07:44:40 +0000262 }
263}
264
Thomas Tsou9520ecd2013-08-20 18:55:33 -0400265bool sigProcLibSetup(int sps)
Thomas Tsoue01e1b32013-09-02 13:24:13 +0800266{
Thomas Tsou3e24f792013-09-05 05:08:09 -0400267 if (sps != 4)
Thomas Tsou9520ecd2013-08-20 18:55:33 -0400268 return false;
269
dburgessb3a0ca42011-10-12 07:44:40 +0000270 initTrigTables();
Thomas Tsoue01e1b32013-09-02 13:24:13 +0800271 initGMSKRotationTables(sps);
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800272 generateGSMPulse(sps, 2);
Thomas Tsou9520ecd2013-08-20 18:55:33 -0400273
274 if (!generateRACHSequence(sps)) {
275 sigProcLibDestroy();
276 return false;
277 }
278
279 return true;
dburgessb3a0ca42011-10-12 07:44:40 +0000280}
281
282void GMSKRotate(signalVector &x) {
283 signalVector::iterator xPtr = x.begin();
284 signalVector::iterator rotPtr = GMSKRotation->begin();
285 if (x.isRealOnly()) {
286 while (xPtr < x.end()) {
287 *xPtr = *rotPtr++ * (xPtr->real());
288 xPtr++;
289 }
290 }
291 else {
292 while (xPtr < x.end()) {
293 *xPtr = *rotPtr++ * (*xPtr);
294 xPtr++;
295 }
296 }
297}
298
299void GMSKReverseRotate(signalVector &x) {
300 signalVector::iterator xPtr= x.begin();
301 signalVector::iterator rotPtr = GMSKReverseRotation->begin();
302 if (x.isRealOnly()) {
303 while (xPtr < x.end()) {
304 *xPtr = *rotPtr++ * (xPtr->real());
305 xPtr++;
306 }
307 }
308 else {
309 while (xPtr < x.end()) {
310 *xPtr = *rotPtr++ * (*xPtr);
311 xPtr++;
312 }
313 }
314}
315
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400316signalVector *convolve(const signalVector *x,
317 const signalVector *h,
318 signalVector *y,
319 ConvType spanType, int start,
320 unsigned len, unsigned step, int offset)
dburgessb3a0ca42011-10-12 07:44:40 +0000321{
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400322 int rc, head = 0, tail = 0;
323 bool alloc = false, append = false;
324 const signalVector *_x = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000325
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400326 if (!x || !h)
dburgessb3a0ca42011-10-12 07:44:40 +0000327 return NULL;
328
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400329 switch (spanType) {
330 case START_ONLY:
331 start = 0;
332 head = h->size();
333 len = x->size();
334 append = true;
dburgessb3a0ca42011-10-12 07:44:40 +0000335 break;
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400336 case NO_DELAY:
337 start = h->size() / 2;
338 head = start;
339 tail = start;
340 len = x->size();
341 append = true;
342 break;
343 case CUSTOM:
344 if (start < h->size() - 1) {
345 head = h->size() - start;
346 append = true;
347 }
348 if (start + len > x->size()) {
349 tail = start + len - x->size();
350 append = true;
dburgessb3a0ca42011-10-12 07:44:40 +0000351 }
352 break;
353 default:
354 return NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000355 }
dburgessb3a0ca42011-10-12 07:44:40 +0000356
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400357 /*
358 * Error if the output vector is too small. Create the output vector
359 * if the pointer is NULL.
360 */
361 if (y && (len > y->size()))
362 return NULL;
363 if (!y) {
364 y = new signalVector(len);
365 alloc = true;
366 }
367
368 /* Prepend or post-pend the input vector if the parameters require it */
369 if (append)
370 _x = new signalVector(*x, head, tail);
371 else
372 _x = x;
373
374 /*
375 * Four convovle types:
376 * 1. Complex-Real (aligned)
377 * 2. Complex-Complex (aligned)
378 * 3. Complex-Real (!aligned)
379 * 4. Complex-Complex (!aligned)
380 */
381 if (h->isRealOnly() && h->isAligned()) {
382 rc = convolve_real((float *) _x->begin(), _x->size(),
383 (float *) h->begin(), h->size(),
384 (float *) y->begin(), y->size(),
385 start, len, step, offset);
386 } else if (!h->isRealOnly() && h->isAligned()) {
387 rc = convolve_complex((float *) _x->begin(), _x->size(),
388 (float *) h->begin(), h->size(),
389 (float *) y->begin(), y->size(),
390 start, len, step, offset);
391 } else if (h->isRealOnly() && !h->isAligned()) {
392 rc = base_convolve_real((float *) _x->begin(), _x->size(),
393 (float *) h->begin(), h->size(),
394 (float *) y->begin(), y->size(),
395 start, len, step, offset);
396 } else if (!h->isRealOnly() && !h->isAligned()) {
397 rc = base_convolve_complex((float *) _x->begin(), _x->size(),
398 (float *) h->begin(), h->size(),
399 (float *) y->begin(), y->size(),
400 start, len, step, offset);
401 } else {
402 rc = -1;
403 }
404
405 if (append)
406 delete _x;
407
408 if (rc < 0) {
409 if (alloc)
410 delete y;
411 return NULL;
412 }
413
414 return y;
415}
dburgessb3a0ca42011-10-12 07:44:40 +0000416
Thomas Tsou3e24f792013-09-05 05:08:09 -0400417bool generateC1Pulse(int sps)
418{
419 int len;
420
421 switch (sps) {
422 case 4:
423 len = 8;
424 break;
425 default:
426 return false;
427 }
428
429 GSMPulse->c1_buffer = convolve_h_alloc(len);
430 GSMPulse->c1 = new signalVector((complex *)
431 GSMPulse->c1_buffer, 0, len);
432 GSMPulse->c1->isRealOnly(true);
433
434 /* Enable alignment for SSE usage */
435 GSMPulse->c1->setAligned(true);
436
437 signalVector::iterator xP = GSMPulse->c1->begin();
438
439 switch (sps) {
440 case 4:
441 /* BT = 0.30 */
442 *xP++ = 0.0;
443 *xP++ = 8.16373112e-03;
444 *xP++ = 2.84385729e-02;
445 *xP++ = 5.64158904e-02;
446 *xP++ = 7.05463553e-02;
447 *xP++ = 5.64158904e-02;
448 *xP++ = 2.84385729e-02;
449 *xP++ = 8.16373112e-03;
450 }
451
452 return true;
453}
454
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800455void generateGSMPulse(int sps, int symbolLength)
dburgessb3a0ca42011-10-12 07:44:40 +0000456{
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800457 int len;
Thomas Tsou3e24f792013-09-05 05:08:09 -0400458 float arg, avg, center;
dburgessb3a0ca42011-10-12 07:44:40 +0000459
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800460 delete GSMPulse;
461
462 /* Store a single tap filter used for correlation sequence generation */
463 GSMPulse = new PulseSequence();
464 GSMPulse->empty = new signalVector(1);
465 GSMPulse->empty->isRealOnly(true);
466 *(GSMPulse->empty->begin()) = 1.0f;
467
Thomas Tsou98e58b92013-08-21 13:59:52 -0400468 /*
469 * For 4 samples-per-symbol use a precomputed single pulse Laurent
470 * approximation. This should yields below 2 degrees of phase error at
471 * the modulator output. Use the existing pulse approximation for all
472 * other oversampling factors.
473 */
474 switch (sps) {
475 case 4:
476 len = 16;
477 break;
478 default:
479 len = sps * symbolLength;
480 if (len < 4)
481 len = 4;
482 }
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400483
Thomas Tsou3e24f792013-09-05 05:08:09 -0400484 GSMPulse->c0_buffer = convolve_h_alloc(len);
485 GSMPulse->c0 = new signalVector((complex *)
486 GSMPulse->c0_buffer, 0, len);
487 GSMPulse->c0->isRealOnly(true);
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400488
Thomas Tsou3e24f792013-09-05 05:08:09 -0400489 /* Enable alingnment for SSE usage */
490 GSMPulse->c0->setAligned(true);
491
492 signalVector::iterator xP = GSMPulse->c0->begin();
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800493
Thomas Tsou98e58b92013-08-21 13:59:52 -0400494 if (sps == 4) {
Thomas Tsou3e24f792013-09-05 05:08:09 -0400495 *xP++ = 0.0;
Thomas Tsou98e58b92013-08-21 13:59:52 -0400496 *xP++ = 4.46348606e-03;
497 *xP++ = 2.84385729e-02;
498 *xP++ = 1.03184855e-01;
499 *xP++ = 2.56065552e-01;
500 *xP++ = 4.76375085e-01;
501 *xP++ = 7.05961177e-01;
502 *xP++ = 8.71291644e-01;
503 *xP++ = 9.29453645e-01;
504 *xP++ = 8.71291644e-01;
505 *xP++ = 7.05961177e-01;
506 *xP++ = 4.76375085e-01;
507 *xP++ = 2.56065552e-01;
508 *xP++ = 1.03184855e-01;
509 *xP++ = 2.84385729e-02;
510 *xP++ = 4.46348606e-03;
Thomas Tsou3e24f792013-09-05 05:08:09 -0400511 generateC1Pulse(sps);
Thomas Tsou98e58b92013-08-21 13:59:52 -0400512 } else {
513 center = (float) (len - 1.0) / 2.0;
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800514
Thomas Tsou98e58b92013-08-21 13:59:52 -0400515 /* GSM pulse approximation */
516 for (int i = 0; i < len; i++) {
517 arg = ((float) i - center) / (float) sps;
518 *xP++ = 0.96 * exp(-1.1380 * arg * arg -
519 0.527 * arg * arg * arg * arg);
520 }
dburgessb3a0ca42011-10-12 07:44:40 +0000521
Thomas Tsou3e24f792013-09-05 05:08:09 -0400522 avg = sqrtf(vectorNorm2(*GSMPulse->c0) / sps);
523 xP = GSMPulse->c0->begin();
524 for (int i = 0; i < len; i++)
525 *xP++ /= avg;
526 }
dburgessb3a0ca42011-10-12 07:44:40 +0000527}
528
529signalVector* frequencyShift(signalVector *y,
530 signalVector *x,
531 float freq,
532 float startPhase,
533 float *finalPhase)
534{
535
536 if (!x) return NULL;
537
538 if (y==NULL) {
539 y = new signalVector(x->size());
540 y->isRealOnly(x->isRealOnly());
541 if (y==NULL) return NULL;
542 }
543
544 if (y->size() < x->size()) return NULL;
545
546 float phase = startPhase;
547 signalVector::iterator yP = y->begin();
548 signalVector::iterator xPEnd = x->end();
549 signalVector::iterator xP = x->begin();
550
551 if (x->isRealOnly()) {
552 while (xP < xPEnd) {
553 (*yP++) = expjLookup(phase)*( (xP++)->real() );
554 phase += freq;
555 }
556 }
557 else {
558 while (xP < xPEnd) {
559 (*yP++) = (*xP++)*expjLookup(phase);
560 phase += freq;
561 }
562 }
563
564
565 if (finalPhase) *finalPhase = phase;
566
567 return y;
568}
569
570signalVector* reverseConjugate(signalVector *b)
571{
572 signalVector *tmp = new signalVector(b->size());
573 tmp->isRealOnly(b->isRealOnly());
574 signalVector::iterator bP = b->begin();
575 signalVector::iterator bPEnd = b->end();
576 signalVector::iterator tmpP = tmp->end()-1;
577 if (!b->isRealOnly()) {
578 while (bP < bPEnd) {
579 *tmpP-- = bP->conj();
580 bP++;
581 }
582 }
583 else {
584 while (bP < bPEnd) {
585 *tmpP-- = bP->real();
586 bP++;
587 }
588 }
589
590 return tmp;
591}
592
dburgessb3a0ca42011-10-12 07:44:40 +0000593/* soft output slicer */
594bool vectorSlicer(signalVector *x)
595{
596
597 signalVector::iterator xP = x->begin();
598 signalVector::iterator xPEnd = x->end();
599 while (xP < xPEnd) {
600 *xP = (complex) (0.5*(xP->real()+1.0F));
601 if (xP->real() > 1.0) *xP = 1.0;
602 if (xP->real() < 0.0) *xP = 0.0;
603 xP++;
604 }
605 return true;
606}
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400607
Thomas Tsou3e24f792013-09-05 05:08:09 -0400608static signalVector *rotateBurst(const BitVector &wBurst,
609 int guardPeriodLength, int sps)
610{
611 int burst_len;
612 signalVector *pulse, rotated, *shaped;
613 signalVector::iterator itr;
614
615 pulse = GSMPulse->empty;
616 burst_len = sps * (wBurst.size() + guardPeriodLength);
617 rotated = signalVector(burst_len);
618 itr = rotated.begin();
619
620 for (unsigned i = 0; i < wBurst.size(); i++) {
621 *itr = 2.0 * (wBurst[i] & 0x01) - 1.0;
622 itr += sps;
623 }
624
625 GMSKRotate(rotated);
626 rotated.isRealOnly(false);
627
628 /* Dummy filter operation */
629 shaped = convolve(&rotated, pulse, NULL, START_ONLY);
630 if (!shaped)
631 return NULL;
632
633 return shaped;
634}
635
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400636/* Assume input bits are not differentially encoded */
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800637signalVector *modulateBurst(const BitVector &wBurst, int guardPeriodLength,
638 int sps, bool emptyPulse)
dburgessb3a0ca42011-10-12 07:44:40 +0000639{
Thomas Tsou3e24f792013-09-05 05:08:09 -0400640 int burst_len;
641 float phase;
642 signalVector *c0_pulse, *c1_pulse, c0_burst, c1_burst, *c0_shaped, *c1_shaped;
643 signalVector::iterator c0_itr, c1_itr;
dburgessb3a0ca42011-10-12 07:44:40 +0000644
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800645 if (emptyPulse)
Thomas Tsou3e24f792013-09-05 05:08:09 -0400646 return rotateBurst(wBurst, guardPeriodLength, sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000647
Thomas Tsou3e24f792013-09-05 05:08:09 -0400648 /*
649 * Apply before and after bits to reduce phase error at burst edges.
650 * Make sure there is enough room in the burst to accodmodate the bits.
651 */
652 if (guardPeriodLength < 4)
653 guardPeriodLength = 4;
dburgessb3a0ca42011-10-12 07:44:40 +0000654
Thomas Tsou3e24f792013-09-05 05:08:09 -0400655 c0_pulse = GSMPulse->c0;
656 c1_pulse = GSMPulse->c1;
657
658 burst_len = sps * (wBurst.size() + guardPeriodLength);
659
660 c0_burst = signalVector(burst_len);
661 c0_burst.isRealOnly(true);
662 c0_itr = c0_burst.begin();
663
664 c1_burst = signalVector(burst_len);
665 c1_burst.isRealOnly(true);
666 c1_itr = c1_burst.begin();
667
668 /* Padded differential start bits */
669 *c0_itr = 2.0 * (0x00 & 0x01) - 1.0;
670 c0_itr += sps;
671
672 /* Main burst bits */
673 for (unsigned i = 0; i < wBurst.size(); i++) {
674 *c0_itr = 2.0 * (wBurst[i] & 0x01) - 1.0;
675 c0_itr += sps;
dburgessb3a0ca42011-10-12 07:44:40 +0000676 }
677
Thomas Tsou3e24f792013-09-05 05:08:09 -0400678 /* Padded differential end bits */
679 *c0_itr = 2.0 * (0x01 & 0x01) - 1.0;
Thomas Tsouc8ce8782013-09-02 13:51:11 +0800680
Thomas Tsou3e24f792013-09-05 05:08:09 -0400681 GMSKRotate(c0_burst);
682 c0_burst.isRealOnly(false);
dburgessb3a0ca42011-10-12 07:44:40 +0000683
Thomas Tsou3e24f792013-09-05 05:08:09 -0400684 c0_itr = c0_burst.begin();
685 c0_itr += sps * 2;
686 c1_itr += sps * 2;
dburgessb3a0ca42011-10-12 07:44:40 +0000687
Thomas Tsou3e24f792013-09-05 05:08:09 -0400688 /* Start magic */
689 phase = 2.0 * ((0x01 & 0x01) ^ (0x01 & 0x01)) - 1.0;
690 *c1_itr = *c0_itr * Complex<float>(0, phase);
691 c0_itr += sps;
692 c1_itr += sps;
693
694 /* Generate C1 phase coefficients */
695 for (unsigned i = 2; i < wBurst.size(); i++) {
696 phase = 2.0 * ((wBurst[i - 1] & 0x01) ^ (wBurst[i - 2] & 0x01)) - 1.0;
697 *c1_itr = *c0_itr * Complex<float>(0, phase);
698
699 c0_itr += sps;
700 c1_itr += sps;
701 }
702
703 /* End magic */
704 int i = wBurst.size();
705 phase = 2.0 * ((wBurst[i-1] & 0x01) ^ (wBurst[i-2] & 0x01)) - 1.0;
706 *c1_itr = *c0_itr * Complex<float>(0, phase);
707
708 /* Primary (C0) and secondary (C1) pulse shaping */
709 c0_shaped = convolve(&c0_burst, c0_pulse, NULL, START_ONLY);
710 c1_shaped = convolve(&c1_burst, c1_pulse, NULL, START_ONLY);
711
712 /* Sum pulse shaped outputs */
713 c0_itr = c0_shaped->begin();
714 c1_itr = c1_shaped->begin();
715 for (unsigned i = 0; i < c0_shaped->size(); i++ )
716 *c0_itr++ += *c1_itr++;
717
718 delete c1_shaped;
719
720 return c0_shaped;
dburgessb3a0ca42011-10-12 07:44:40 +0000721}
722
723float sinc(float x)
724{
725 if ((x >= 0.01F) || (x <= -0.01F)) return (sinLookup(x)/x);
726 return 1.0F;
727}
728
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400729bool delayVector(signalVector &wBurst, float delay)
dburgessb3a0ca42011-10-12 07:44:40 +0000730{
731
732 int intOffset = (int) floor(delay);
733 float fracOffset = delay - intOffset;
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400734
dburgessb3a0ca42011-10-12 07:44:40 +0000735 // do fractional shift first, only do it for reasonable offsets
736 if (fabs(fracOffset) > 1e-2) {
737 // create sinc function
738 signalVector sincVector(21);
739 sincVector.isRealOnly(true);
Thomas Tsou0c260ae2013-08-22 18:40:43 -0400740 signalVector::iterator sincBurstItr = sincVector.end();
dburgessb3a0ca42011-10-12 07:44:40 +0000741 for (int i = 0; i < 21; i++)
Thomas Tsou0c260ae2013-08-22 18:40:43 -0400742 *--sincBurstItr = (complex) sinc(M_PI_F*(i-10-fracOffset));
dburgessb3a0ca42011-10-12 07:44:40 +0000743
744 signalVector shiftedBurst(wBurst.size());
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400745 if (!convolve(&wBurst, &sincVector, &shiftedBurst, NO_DELAY))
746 return false;
dburgessb3a0ca42011-10-12 07:44:40 +0000747 wBurst.clone(shiftedBurst);
748 }
749
750 if (intOffset < 0) {
751 intOffset = -intOffset;
752 signalVector::iterator wBurstItr = wBurst.begin();
753 signalVector::iterator shiftedItr = wBurst.begin()+intOffset;
754 while (shiftedItr < wBurst.end())
755 *wBurstItr++ = *shiftedItr++;
756 while (wBurstItr < wBurst.end())
757 *wBurstItr++ = 0.0;
758 }
759 else {
760 signalVector::iterator wBurstItr = wBurst.end()-1;
761 signalVector::iterator shiftedItr = wBurst.end()-1-intOffset;
762 while (shiftedItr >= wBurst.begin())
763 *wBurstItr-- = *shiftedItr--;
764 while (wBurstItr >= wBurst.begin())
765 *wBurstItr-- = 0.0;
766 }
767}
768
769signalVector *gaussianNoise(int length,
770 float variance,
771 complex mean)
772{
773
774 signalVector *noise = new signalVector(length);
775 signalVector::iterator nPtr = noise->begin();
776 float stddev = sqrtf(variance);
777 while (nPtr < noise->end()) {
778 float u1 = (float) rand()/ (float) RAND_MAX;
779 while (u1==0.0)
780 u1 = (float) rand()/ (float) RAND_MAX;
781 float u2 = (float) rand()/ (float) RAND_MAX;
782 float arg = 2.0*M_PI*u2;
783 *nPtr = mean + stddev*complex(cos(arg),sin(arg))*sqrtf(-2.0*log(u1));
784 nPtr++;
785 }
786
787 return noise;
788}
789
790complex interpolatePoint(const signalVector &inSig,
791 float ix)
792{
793
794 int start = (int) (floor(ix) - 10);
795 if (start < 0) start = 0;
796 int end = (int) (floor(ix) + 11);
797 if ((unsigned) end > inSig.size()-1) end = inSig.size()-1;
798
799 complex pVal = 0.0;
800 if (!inSig.isRealOnly()) {
801 for (int i = start; i < end; i++)
802 pVal += inSig[i] * sinc(M_PI_F*(i-ix));
803 }
804 else {
805 for (int i = start; i < end; i++)
806 pVal += inSig[i].real() * sinc(M_PI_F*(i-ix));
807 }
808
809 return pVal;
810}
811
Thomas Tsoufb6e7572013-09-02 14:39:35 +0800812static complex fastPeakDetect(const signalVector &rxBurst, float *index)
813{
814 float val, max = 0.0f;
815 complex amp;
816 int _index = -1;
817
818 for (int i = 0; i < rxBurst.size(); i++) {
819 val = rxBurst[i].norm2();
820 if (val > max) {
821 max = val;
822 _index = i;
823 amp = rxBurst[i];
824 }
825 }
826
827 if (index)
828 *index = (float) _index;
829
830 return amp;
831}
dburgessb3a0ca42011-10-12 07:44:40 +0000832
833complex peakDetect(const signalVector &rxBurst,
834 float *peakIndex,
835 float *avgPwr)
836{
837
838
839 complex maxVal = 0.0;
840 float maxIndex = -1;
841 float sumPower = 0.0;
842
843 for (unsigned int i = 0; i < rxBurst.size(); i++) {
844 float samplePower = rxBurst[i].norm2();
845 if (samplePower > maxVal.real()) {
846 maxVal = samplePower;
847 maxIndex = i;
848 }
849 sumPower += samplePower;
850 }
851
852 // interpolate around the peak
853 // to save computation, we'll use early-late balancing
854 float earlyIndex = maxIndex-1;
855 float lateIndex = maxIndex+1;
856
857 float incr = 0.5;
858 while (incr > 1.0/1024.0) {
859 complex earlyP = interpolatePoint(rxBurst,earlyIndex);
860 complex lateP = interpolatePoint(rxBurst,lateIndex);
861 if (earlyP < lateP)
862 earlyIndex += incr;
863 else if (earlyP > lateP)
864 earlyIndex -= incr;
865 else break;
866 incr /= 2.0;
867 lateIndex = earlyIndex + 2.0;
868 }
869
870 maxIndex = earlyIndex + 1.0;
871 maxVal = interpolatePoint(rxBurst,maxIndex);
872
873 if (peakIndex!=NULL)
874 *peakIndex = maxIndex;
875
876 if (avgPwr!=NULL)
877 *avgPwr = (sumPower-maxVal.norm2()) / (rxBurst.size()-1);
878
879 return maxVal;
880
881}
882
883void scaleVector(signalVector &x,
884 complex scale)
885{
886 signalVector::iterator xP = x.begin();
887 signalVector::iterator xPEnd = x.end();
888 if (!x.isRealOnly()) {
889 while (xP < xPEnd) {
890 *xP = *xP * scale;
891 xP++;
892 }
893 }
894 else {
895 while (xP < xPEnd) {
896 *xP = xP->real() * scale;
897 xP++;
898 }
899 }
900}
901
902/** in-place conjugation */
903void conjugateVector(signalVector &x)
904{
905 if (x.isRealOnly()) return;
906 signalVector::iterator xP = x.begin();
907 signalVector::iterator xPEnd = x.end();
908 while (xP < xPEnd) {
909 *xP = xP->conj();
910 xP++;
911 }
912}
913
914
915// in-place addition!!
916bool addVector(signalVector &x,
917 signalVector &y)
918{
919 signalVector::iterator xP = x.begin();
920 signalVector::iterator yP = y.begin();
921 signalVector::iterator xPEnd = x.end();
922 signalVector::iterator yPEnd = y.end();
923 while ((xP < xPEnd) && (yP < yPEnd)) {
924 *xP = *xP + *yP;
925 xP++; yP++;
926 }
927 return true;
928}
929
930// in-place multiplication!!
931bool multVector(signalVector &x,
932 signalVector &y)
933{
934 signalVector::iterator xP = x.begin();
935 signalVector::iterator yP = y.begin();
936 signalVector::iterator xPEnd = x.end();
937 signalVector::iterator yPEnd = y.end();
938 while ((xP < xPEnd) && (yP < yPEnd)) {
939 *xP = (*xP) * (*yP);
940 xP++; yP++;
941 }
942 return true;
943}
944
945
946void offsetVector(signalVector &x,
947 complex offset)
948{
949 signalVector::iterator xP = x.begin();
950 signalVector::iterator xPEnd = x.end();
951 if (!x.isRealOnly()) {
952 while (xP < xPEnd) {
953 *xP += offset;
954 xP++;
955 }
956 }
957 else {
958 while (xP < xPEnd) {
959 *xP = xP->real() + offset;
960 xP++;
961 }
962 }
963}
964
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400965bool generateMidamble(int sps, int tsc)
dburgessb3a0ca42011-10-12 07:44:40 +0000966{
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400967 bool status = true;
968 complex *data = NULL;
969 signalVector *autocorr = NULL, *midamble = NULL;
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400970 signalVector *midMidamble = NULL, *_midMidamble = NULL;
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400971
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400972 if ((tsc < 0) || (tsc > 7))
dburgessb3a0ca42011-10-12 07:44:40 +0000973 return false;
974
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400975 delete gMidambles[tsc];
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400976
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400977 /* Use middle 16 bits of each TSC. Correlation sequence is not pulse shaped */
978 midMidamble = modulateBurst(gTrainingSequence[tsc].segment(5,16), 0, sps, true);
979 if (!midMidamble)
980 return false;
981
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400982 /* Simulated receive sequence is pulse shaped */
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400983 midamble = modulateBurst(gTrainingSequence[tsc], 0, sps, false);
984 if (!midamble) {
985 status = false;
986 goto release;
dburgessb3a0ca42011-10-12 07:44:40 +0000987 }
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400988
dburgessb3a0ca42011-10-12 07:44:40 +0000989 // NOTE: Because ideal TSC 16-bit midamble is 66 symbols into burst,
990 // the ideal TSC has an + 180 degree phase shift,
991 // due to the pi/2 frequency shift, that
992 // needs to be accounted for.
993 // 26-midamble is 61 symbols into burst, has +90 degree phase shift.
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400994 scaleVector(*midMidamble, complex(-1.0, 0.0));
995 scaleVector(*midamble, complex(0.0, 1.0));
dburgessb3a0ca42011-10-12 07:44:40 +0000996
Thomas Tsoud6ed8c02013-08-20 16:27:12 -0400997 conjugateVector(*midMidamble);
dburgessb3a0ca42011-10-12 07:44:40 +0000998
Thomas Tsouacc9ee92013-08-20 19:31:14 -0400999 /* For SSE alignment, reallocate the midamble sequence on 16-byte boundary */
1000 data = (complex *) convolve_h_alloc(midMidamble->size());
1001 _midMidamble = new signalVector(data, 0, midMidamble->size());
1002 _midMidamble->setAligned(true);
1003 memcpy(_midMidamble->begin(), midMidamble->begin(),
1004 midMidamble->size() * sizeof(complex));
1005
1006 autocorr = convolve(midamble, _midMidamble, NULL, NO_DELAY);
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001007 if (!autocorr) {
1008 status = false;
1009 goto release;
1010 }
dburgessb3a0ca42011-10-12 07:44:40 +00001011
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001012 gMidambles[tsc] = new CorrelationSequence;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001013 gMidambles[tsc]->buffer = data;
1014 gMidambles[tsc]->sequence = _midMidamble;
1015 gMidambles[tsc]->gain = peakDetect(*autocorr,&gMidambles[tsc]->TOA, NULL);
dburgessb3a0ca42011-10-12 07:44:40 +00001016
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001017release:
dburgessb3a0ca42011-10-12 07:44:40 +00001018 delete autocorr;
1019 delete midamble;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001020 delete midMidamble;
dburgessb3a0ca42011-10-12 07:44:40 +00001021
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001022 if (!status) {
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001023 delete _midMidamble;
1024 free(data);
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001025 gMidambles[tsc] = NULL;
1026 }
1027
1028 return status;
dburgessb3a0ca42011-10-12 07:44:40 +00001029}
1030
Thomas Tsouc8ce8782013-09-02 13:51:11 +08001031bool generateRACHSequence(int sps)
dburgessb3a0ca42011-10-12 07:44:40 +00001032{
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001033 bool status = true;
1034 complex *data = NULL;
1035 signalVector *autocorr = NULL;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001036 signalVector *seq0 = NULL, *seq1 = NULL, *_seq1 = NULL;
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001037
1038 delete gRACHSequence;
1039
1040 seq0 = modulateBurst(gRACHSynchSequence, 0, sps, false);
1041 if (!seq0)
1042 return false;
1043
1044 seq1 = modulateBurst(gRACHSynchSequence.segment(0, 40), 0, sps, true);
1045 if (!seq1) {
1046 status = false;
1047 goto release;
dburgessb3a0ca42011-10-12 07:44:40 +00001048 }
1049
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001050 conjugateVector(*seq1);
dburgessb3a0ca42011-10-12 07:44:40 +00001051
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001052 /* For SSE alignment, reallocate the midamble sequence on 16-byte boundary */
1053 data = (complex *) convolve_h_alloc(seq1->size());
1054 _seq1 = new signalVector(data, 0, seq1->size());
1055 _seq1->setAligned(true);
1056 memcpy(_seq1->begin(), seq1->begin(), seq1->size() * sizeof(complex));
1057
1058 autocorr = convolve(seq0, _seq1, autocorr, NO_DELAY);
1059 if (!autocorr) {
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001060 status = false;
1061 goto release;
1062 }
dburgessb3a0ca42011-10-12 07:44:40 +00001063
1064 gRACHSequence = new CorrelationSequence;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001065 gRACHSequence->sequence = _seq1;
1066 gRACHSequence->buffer = data;
1067 gRACHSequence->gain = peakDetect(*autocorr,&gRACHSequence->TOA, NULL);
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001068
1069release:
dburgessb3a0ca42011-10-12 07:44:40 +00001070 delete autocorr;
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001071 delete seq0;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001072 delete seq1;
dburgessb3a0ca42011-10-12 07:44:40 +00001073
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001074 if (!status) {
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001075 delete _seq1;
1076 free(data);
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001077 gRACHSequence = NULL;
1078 }
dburgessb3a0ca42011-10-12 07:44:40 +00001079
Thomas Tsoud6ed8c02013-08-20 16:27:12 -04001080 return status;
dburgessb3a0ca42011-10-12 07:44:40 +00001081}
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001082
Thomas Tsouef7c2582013-08-21 20:58:00 -04001083static float computePeakRatio(signalVector *corr,
1084 int sps, float toa, complex amp)
dburgessb3a0ca42011-10-12 07:44:40 +00001085{
Thomas Tsouef7c2582013-08-21 20:58:00 -04001086 int num = 0;
1087 complex *peak;
1088 float rms, avg = 0.0;
dburgessb3a0ca42011-10-12 07:44:40 +00001089
Thomas Tsouef7c2582013-08-21 20:58:00 -04001090 peak = corr->begin() + (int) rint(toa);
dburgessb3a0ca42011-10-12 07:44:40 +00001091
Thomas Tsouef7c2582013-08-21 20:58:00 -04001092 /* Check for bogus results */
1093 if ((toa < 0.0) || (toa > corr->size()))
1094 return 0.0;
dburgessb3a0ca42011-10-12 07:44:40 +00001095
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001096 for (int i = 2 * sps; i <= 5 * sps; i++) {
Thomas Tsouef7c2582013-08-21 20:58:00 -04001097 if (peak - i >= corr->begin()) {
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001098 avg += (peak - i)->norm2();
1099 num++;
1100 }
Thomas Tsouef7c2582013-08-21 20:58:00 -04001101 if (peak + i < corr->end()) {
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001102 avg += (peak + i)->norm2();
1103 num++;
1104 }
dburgessb3a0ca42011-10-12 07:44:40 +00001105 }
1106
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001107 if (num < 2)
Thomas Tsouef7c2582013-08-21 20:58:00 -04001108 return 0.0;
dburgessb3a0ca42011-10-12 07:44:40 +00001109
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001110 rms = sqrtf(avg / (float) num) + 0.00001;
dburgessb3a0ca42011-10-12 07:44:40 +00001111
Thomas Tsouef7c2582013-08-21 20:58:00 -04001112 return (amp.abs()) / rms;
dburgessb3a0ca42011-10-12 07:44:40 +00001113}
1114
1115bool energyDetect(signalVector &rxBurst,
1116 unsigned windowLength,
1117 float detectThreshold,
1118 float *avgPwr)
1119{
1120
1121 signalVector::const_iterator windowItr = rxBurst.begin(); //+rxBurst.size()/2 - 5*windowLength/2;
1122 float energy = 0.0;
1123 if (windowLength < 0) windowLength = 20;
1124 if (windowLength > rxBurst.size()) windowLength = rxBurst.size();
1125 for (unsigned i = 0; i < windowLength; i++) {
1126 energy += windowItr->norm2();
1127 windowItr+=4;
1128 }
1129 if (avgPwr) *avgPwr = energy/windowLength;
dburgessb3a0ca42011-10-12 07:44:40 +00001130 return (energy/windowLength > detectThreshold*detectThreshold);
1131}
dburgessb3a0ca42011-10-12 07:44:40 +00001132
Thomas Tsouef7c2582013-08-21 20:58:00 -04001133/*
1134 * Detect a burst based on correlation and peak-to-average ratio. Perform
1135 * fast peak detection (no interpolation) for initial gating. Interpolate
1136 * the sub-sample peak after we have detected the burst.
1137 */
1138static int detectBurst(signalVector &burst,
1139 signalVector &corr, CorrelationSequence *sync,
1140 float thresh, int sps, complex *amp, float *toa,
1141 int start, int len)
dburgessb3a0ca42011-10-12 07:44:40 +00001142{
Thomas Tsouef7c2582013-08-21 20:58:00 -04001143 /* Correlate */
1144 if (!convolve(&burst, sync->sequence, &corr,
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001145 CUSTOM, start, len, sps, 0)) {
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001146#ifndef TRX_LOAD_TESTING
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001147 return -1;
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001148#endif
dburgessb3a0ca42011-10-12 07:44:40 +00001149 }
1150
Thomas Tsouef7c2582013-08-21 20:58:00 -04001151 /* Peak detection - place restrictions at correlation edges */
1152 *amp = fastPeakDetect(corr, toa);
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001153
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001154#ifndef TRX_LOAD_TESTING
Thomas Tsouef7c2582013-08-21 20:58:00 -04001155 if ((*toa < 3 * sps) || (*toa > len - 3 * sps))
1156 return 0;
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001157#endif
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001158
Thomas Tsouef7c2582013-08-21 20:58:00 -04001159 /* Peak -to-average ratio */
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001160 if (computePeakRatio(&corr, sps, *toa, *amp) < thresh) {
1161#ifndef TRX_LOAD_TESTING
Thomas Tsouef7c2582013-08-21 20:58:00 -04001162 return 0;
Alexander Chemeris0b8aa002013-09-06 00:35:57 +04001163#endif
1164 }
Thomas Tsouef7c2582013-08-21 20:58:00 -04001165
1166 /* Run the full peak detection when we have a burst */
1167 *amp = peakDetect(corr, toa, NULL);
1168
1169 /* Normalize our channel gain */
1170 *amp = *amp / sync->gain;
1171
1172 return 1;
1173}
1174
1175/*
1176 * RACH burst detection
1177 *
1178 * Correlation window parameters:
1179 * target: Tail bits + RACH length (reduced from 41 to a multiple of 4)
1180 * head: Search 4 symbols before target
1181 * tail: Search 8 symbols after target
1182 */
1183int detectRACHBurst(signalVector &rxBurst,
1184 float thresh,
1185 int sps,
1186 complex *amp,
1187 float *toa)
1188{
1189 int rc, start, target, head, tail, len;
1190 float _toa;
1191 complex _amp;
1192 signalVector corr;
1193 CorrelationSequence *sync;
1194
1195 if ((sps != 1) && (sps != 2) && (sps != 4))
1196 return -1;
1197
1198 target = 8 + 40;
1199 head = 4;
1200 tail = 8;
1201
1202 start = (target - head) * sps - 1;
1203 len = (head + tail) * sps;
1204 sync = gRACHSequence;
1205 corr = signalVector(len);
1206
1207 rc = detectBurst(rxBurst, corr, sync,
1208 thresh, sps, &_amp, &_toa, start, len);
1209 if (rc < 0) {
1210 return -1;
1211 } else if (!rc) {
1212 if (amp)
1213 *amp = 0.0f;
1214 if (toa)
1215 *toa = 0.0f;
1216 return 0;
dburgessb3a0ca42011-10-12 07:44:40 +00001217 }
1218
Thomas Tsouef7c2582013-08-21 20:58:00 -04001219 /* Subtract forward search bits from delay */
1220 if (toa)
1221 *toa = _toa - head * sps;
Thomas Tsou3e24f792013-09-05 05:08:09 -04001222
1223 /* Compensate for unknown rotation */
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001224 if (amp)
Thomas Tsou3e24f792013-09-05 05:08:09 -04001225 *amp = _amp * complex(0.0, 1.0);
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001226
Thomas Tsouef7c2582013-08-21 20:58:00 -04001227 return 1;
1228}
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001229
Thomas Tsouef7c2582013-08-21 20:58:00 -04001230/*
1231 * Normal burst detection
1232 *
1233 * Correlation window parameters:
1234 * target: Tail + data + mid-midamble + 1/2 remaining midamblebits
1235 * head: Search 4 symbols before target
1236 * tail: Search 6 symbols + maximum expected delay
1237 */
1238int analyzeTrafficBurst(signalVector &rxBurst, unsigned tsc, float thresh,
1239 int sps, complex *amp, float *toa, unsigned max_toa,
1240 bool chan_req, signalVector **chan, float *chan_offset)
1241{
1242 int rc, start, target, head, tail, len;
1243 complex _amp;
1244 float _toa;
1245 signalVector corr, *_chan;
1246 CorrelationSequence *sync;
1247
1248 if ((tsc < 0) || (tsc > 7) || ((sps != 1) && (sps != 2) && (sps != 4)))
1249 return -1;
1250
1251 target = 3 + 58 + 16 + 5;
1252 head = 4;
1253 tail = 6 + max_toa;
1254
1255 start = (target - head) * sps - 1;
1256 len = (head + tail) * sps;
1257 sync = gMidambles[tsc];
1258 corr = signalVector(len);
1259
1260 rc = detectBurst(rxBurst, corr, sync,
1261 thresh, sps, &_amp, &_toa, start, len);
1262 if (rc < 0) {
1263 return -1;
1264 } else if (!rc) {
1265 if (amp)
1266 *amp = 0.0f;
1267 if (toa)
1268 *toa = 0.0f;
1269 return 0;
1270 }
1271
1272 /* Subtract forward search bits from delay */
1273 _toa -= head * sps;
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001274 if (toa)
1275 *toa = _toa;
Thomas Tsou3e24f792013-09-05 05:08:09 -04001276
1277 /* Compensate for unknown rotation */
Thomas Tsouef7c2582013-08-21 20:58:00 -04001278 if (amp)
Thomas Tsou3e24f792013-09-05 05:08:09 -04001279 *amp = _amp * complex(0, 1.0);
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001280
Thomas Tsouef7c2582013-08-21 20:58:00 -04001281 /* Equalization not currently supported */
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001282 if (chan_req) {
Thomas Tsouef7c2582013-08-21 20:58:00 -04001283 *chan = new signalVector(6 * sps);
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001284
1285 if (chan_offset)
Thomas Tsouef7c2582013-08-21 20:58:00 -04001286 *chan_offset = 0.0;
dburgessb3a0ca42011-10-12 07:44:40 +00001287 }
1288
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001289 return 1;
dburgessb3a0ca42011-10-12 07:44:40 +00001290}
1291
1292signalVector *decimateVector(signalVector &wVector,
1293 int decimationFactor)
1294{
1295
1296 if (decimationFactor <= 1) return NULL;
1297
1298 signalVector *decVector = new signalVector(wVector.size()/decimationFactor);
1299 decVector->isRealOnly(wVector.isRealOnly());
1300
1301 signalVector::iterator vecItr = decVector->begin();
1302 for (unsigned int i = 0; i < wVector.size();i+=decimationFactor)
1303 *vecItr++ = wVector[i];
1304
1305 return decVector;
1306}
1307
1308
Thomas Tsouc8ce8782013-09-02 13:51:11 +08001309SoftVector *demodulateBurst(signalVector &rxBurst, int sps,
1310 complex channel, float TOA)
dburgessb3a0ca42011-10-12 07:44:40 +00001311{
1312 scaleVector(rxBurst,((complex) 1.0)/channel);
1313 delayVector(rxBurst,-TOA);
1314
1315 signalVector *shapedBurst = &rxBurst;
1316
1317 // shift up by a quarter of a frequency
1318 // ignore starting phase, since spec allows for discontinuous phase
1319 GMSKReverseRotate(*shapedBurst);
1320
1321 // run through slicer
Thomas Tsoue01e1b32013-09-02 13:24:13 +08001322 if (sps > 1) {
1323 signalVector *decShapedBurst = decimateVector(*shapedBurst, sps);
dburgessb3a0ca42011-10-12 07:44:40 +00001324 shapedBurst = decShapedBurst;
1325 }
1326
dburgessb3a0ca42011-10-12 07:44:40 +00001327 vectorSlicer(shapedBurst);
1328
1329 SoftVector *burstBits = new SoftVector(shapedBurst->size());
1330
1331 SoftVector::iterator burstItr = burstBits->begin();
1332 signalVector::iterator shapedItr = shapedBurst->begin();
1333 for (; shapedItr < shapedBurst->end(); shapedItr++)
1334 *burstItr++ = shapedItr->real();
1335
Thomas Tsoue01e1b32013-09-02 13:24:13 +08001336 if (sps > 1)
1337 delete shapedBurst;
dburgessb3a0ca42011-10-12 07:44:40 +00001338
1339 return burstBits;
1340
1341}
1342
1343
1344// 1.0 is sampling frequency
1345// must satisfy cutoffFreq > 1/filterLen
1346signalVector *createLPF(float cutoffFreq,
1347 int filterLen,
1348 float gainDC)
1349{
kurtis.heimerla198d452011-11-26 03:19:28 +00001350#if 0
dburgessb3a0ca42011-10-12 07:44:40 +00001351 signalVector *LPF = new signalVector(filterLen-1);
1352 LPF->isRealOnly(true);
1353 LPF->setSymmetry(ABSSYM);
1354 signalVector::iterator itr = LPF->begin();
1355 double sum = 0.0;
1356 for (int i = 1; i < filterLen; i++) {
1357 float ys = sinc(M_2PI_F*cutoffFreq*((float)i-(float)(filterLen)/2.0F));
1358 float yg = 4.0F * cutoffFreq;
1359 // Blackman -- less brickwall (sloping transition) but larger stopband attenuation
1360 float yw = 0.42 - 0.5*cos(((float)i)*M_2PI_F/(float)(filterLen)) + 0.08*cos(((float)i)*2*M_2PI_F/(float)(filterLen));
1361 // Hamming -- more brickwall with smaller stopband attenuation
1362 //float yw = 0.53836F - 0.46164F * cos(((float)i)*M_2PI_F/(float)(filterLen+1));
1363 *itr++ = (complex) ys*yg*yw;
1364 sum += ys*yg*yw;
1365 }
kurtis.heimerla198d452011-11-26 03:19:28 +00001366#else
1367 double sum = 0.0;
1368 signalVector *LPF;
1369 signalVector::iterator itr;
1370 if (filterLen == 651) { // receive LPF
1371 LPF = new signalVector(651);
1372 LPF->isRealOnly(true);
1373 itr = LPF->begin();
1374 for (int i = 0; i < filterLen; i++) {
1375 *itr++ = complex(rcvLPF_651[i],0.0);
1376 sum += rcvLPF_651[i];
1377 }
1378 }
1379 else {
1380 LPF = new signalVector(961);
1381 LPF->isRealOnly(true);
1382 itr = LPF->begin();
1383 for (int i = 0; i < filterLen; i++) {
1384 *itr++ = complex(sendLPF_961[i],0.0);
1385 sum += sendLPF_961[i];
1386 }
1387 }
1388#endif
1389
dburgessb3a0ca42011-10-12 07:44:40 +00001390 float normFactor = gainDC/sum; //sqrtf(gainDC/vectorNorm2(*LPF));
1391 // normalize power
1392 itr = LPF->begin();
kurtis.heimerla198d452011-11-26 03:19:28 +00001393 for (int i = 0; i < filterLen; i++) {
dburgessb3a0ca42011-10-12 07:44:40 +00001394 *itr = *itr*normFactor;
1395 itr++;
1396 }
1397 return LPF;
1398
1399}
1400
1401
1402
1403#define POLYPHASESPAN 10
1404
1405// assumes filter group delay is 0.5*(length of filter)
1406signalVector *polyphaseResampleVector(signalVector &wVector,
1407 int P, int Q,
1408 signalVector *LPF)
1409
1410{
1411
1412 bool deleteLPF = false;
1413
1414 if (LPF==NULL) {
1415 float cutoffFreq = (P < Q) ? (1.0/(float) Q) : (1.0/(float) P);
1416 LPF = createLPF(cutoffFreq/3.0,100*POLYPHASESPAN+1,Q);
1417 deleteLPF = true;
1418 }
1419
1420 signalVector *resampledVector = new signalVector((int) ceil(wVector.size()*(float) P / (float) Q));
1421 resampledVector->fill(0);
1422 resampledVector->isRealOnly(wVector.isRealOnly());
1423 signalVector::iterator newItr = resampledVector->begin();
1424
1425 //FIXME: need to update for real-only vectors
1426 int outputIx = (LPF->size()+1)/2/Q; //((P > Q) ? P : Q);
1427 while (newItr < resampledVector->end()) {
1428 int outputBranch = (outputIx*Q) % P;
1429 int inputOffset = (outputIx*Q - outputBranch)/P;
1430 signalVector::const_iterator inputItr = wVector.begin() + inputOffset;
1431 signalVector::const_iterator filtItr = LPF->begin() + outputBranch;
1432 while (inputItr >= wVector.end()) {
1433 inputItr--;
1434 filtItr+=P;
1435 }
1436 complex sum = 0.0;
1437 if ((LPF->getSymmetry()!=ABSSYM) || (P>1)) {
1438 if (!LPF->isRealOnly()) {
1439 while ( (inputItr >= wVector.begin()) && (filtItr < LPF->end()) ) {
1440 sum += (*inputItr)*(*filtItr);
1441 inputItr--;
1442 filtItr += P;
1443 }
1444 }
1445 else {
1446 while ( (inputItr >= wVector.begin()) && (filtItr < LPF->end()) ) {
1447 sum += (*inputItr)*(filtItr->real());
1448 inputItr--;
1449 filtItr += P;
1450 }
1451 }
1452 }
1453 else {
1454 signalVector::const_iterator revInputItr = inputItr- LPF->size() + 1;
1455 signalVector::const_iterator filtMidpoint = LPF->begin()+(LPF->size()-1)/2;
1456 if (!LPF->isRealOnly()) {
1457 while (filtItr <= filtMidpoint) {
1458 if (inputItr < revInputItr) break;
1459 if (inputItr == revInputItr)
1460 sum += (*inputItr)*(*filtItr);
1461 else if ( (inputItr < wVector.end()) && (revInputItr >= wVector.begin()) )
1462 sum += (*inputItr + *revInputItr)*(*filtItr);
1463 else if ( inputItr < wVector.end() )
1464 sum += (*inputItr)*(*filtItr);
1465 else if ( revInputItr >= wVector.begin() )
1466 sum += (*revInputItr)*(*filtItr);
1467 inputItr--;
1468 revInputItr++;
1469 filtItr++;
1470 }
1471 }
1472 else {
1473 while (filtItr <= filtMidpoint) {
1474 if (inputItr < revInputItr) break;
1475 if (inputItr == revInputItr)
1476 sum += (*inputItr)*(filtItr->real());
1477 else if ( (inputItr < wVector.end()) && (revInputItr >= wVector.begin()) )
1478 sum += (*inputItr + *revInputItr)*(filtItr->real());
1479 else if ( inputItr < wVector.end() )
1480 sum += (*inputItr)*(filtItr->real());
1481 else if ( revInputItr >= wVector.begin() )
1482 sum += (*revInputItr)*(filtItr->real());
1483 inputItr--;
1484 revInputItr++;
1485 filtItr++;
1486 }
1487 }
1488 }
1489 *newItr = sum;
1490 newItr++;
1491 outputIx++;
1492 }
1493
1494 if (deleteLPF) delete LPF;
1495
1496 return resampledVector;
1497}
1498
1499
1500signalVector *resampleVector(signalVector &wVector,
1501 float expFactor,
1502 complex endPoint)
1503
1504{
1505
1506 if (expFactor < 1.0) return NULL;
1507
1508 signalVector *retVec = new signalVector((int) ceil(wVector.size()*expFactor));
1509
1510 float t = 0.0;
1511
1512 signalVector::iterator retItr = retVec->begin();
1513 while (retItr < retVec->end()) {
1514 unsigned tLow = (unsigned int) floor(t);
1515 unsigned tHigh = tLow + 1;
1516 if (tLow > wVector.size()-1) break;
1517 if (tHigh > wVector.size()) break;
1518 complex lowPoint = wVector[tLow];
1519 complex highPoint = (tHigh == wVector.size()) ? endPoint : wVector[tHigh];
1520 complex a = (tHigh-t);
1521 complex b = (t-tLow);
1522 *retItr = (a*lowPoint + b*highPoint);
1523 t += 1.0/expFactor;
1524 }
1525
1526 return retVec;
1527
1528}
1529
1530
1531// Assumes symbol-spaced sampling!!!
1532// Based upon paper by Al-Dhahir and Cioffi
1533bool designDFE(signalVector &channelResponse,
1534 float SNRestimate,
1535 int Nf,
1536 signalVector **feedForwardFilter,
1537 signalVector **feedbackFilter)
1538{
1539
1540 signalVector G0(Nf);
1541 signalVector G1(Nf);
1542 signalVector::iterator G0ptr = G0.begin();
1543 signalVector::iterator G1ptr = G1.begin();
1544 signalVector::iterator chanPtr = channelResponse.begin();
1545
1546 int nu = channelResponse.size()-1;
1547
1548 *G0ptr = 1.0/sqrtf(SNRestimate);
1549 for(int j = 0; j <= nu; j++) {
1550 *G1ptr = chanPtr->conj();
1551 G1ptr++; chanPtr++;
1552 }
1553
1554 signalVector *L[Nf];
1555 signalVector::iterator Lptr;
1556 float d;
1557 for(int i = 0; i < Nf; i++) {
1558 d = G0.begin()->norm2() + G1.begin()->norm2();
1559 L[i] = new signalVector(Nf+nu);
1560 Lptr = L[i]->begin()+i;
1561 G0ptr = G0.begin(); G1ptr = G1.begin();
1562 while ((G0ptr < G0.end()) && (Lptr < L[i]->end())) {
1563 *Lptr = (*G0ptr*(G0.begin()->conj()) + *G1ptr*(G1.begin()->conj()) )/d;
1564 Lptr++;
1565 G0ptr++;
1566 G1ptr++;
1567 }
1568 complex k = (*G1.begin())/(*G0.begin());
1569
1570 if (i != Nf-1) {
1571 signalVector G0new = G1;
1572 scaleVector(G0new,k.conj());
1573 addVector(G0new,G0);
1574
1575 signalVector G1new = G0;
1576 scaleVector(G1new,k*(-1.0));
1577 addVector(G1new,G1);
1578 delayVector(G1new,-1.0);
1579
1580 scaleVector(G0new,1.0/sqrtf(1.0+k.norm2()));
1581 scaleVector(G1new,1.0/sqrtf(1.0+k.norm2()));
1582 G0 = G0new;
1583 G1 = G1new;
1584 }
1585 }
1586
1587 *feedbackFilter = new signalVector(nu);
1588 L[Nf-1]->segmentCopyTo(**feedbackFilter,Nf,nu);
1589 scaleVector(**feedbackFilter,(complex) -1.0);
1590 conjugateVector(**feedbackFilter);
1591
1592 signalVector v(Nf);
1593 signalVector::iterator vStart = v.begin();
1594 signalVector::iterator vPtr;
1595 *(vStart+Nf-1) = (complex) 1.0;
1596 for(int k = Nf-2; k >= 0; k--) {
1597 Lptr = L[k]->begin()+k+1;
1598 vPtr = vStart + k+1;
1599 complex v_k = 0.0;
1600 for (int j = k+1; j < Nf; j++) {
1601 v_k -= (*vPtr)*(*Lptr);
1602 vPtr++; Lptr++;
1603 }
1604 *(vStart + k) = v_k;
1605 }
1606
1607 *feedForwardFilter = new signalVector(Nf);
Thomas Tsou0c260ae2013-08-22 18:40:43 -04001608 signalVector::iterator w = (*feedForwardFilter)->end();
dburgessb3a0ca42011-10-12 07:44:40 +00001609 for (int i = 0; i < Nf; i++) {
1610 delete L[i];
1611 complex w_i = 0.0;
1612 int endPt = ( nu < (Nf-1-i) ) ? nu : (Nf-1-i);
1613 vPtr = vStart+i;
1614 chanPtr = channelResponse.begin();
1615 for (int k = 0; k < endPt+1; k++) {
1616 w_i += (*vPtr)*(chanPtr->conj());
1617 vPtr++; chanPtr++;
1618 }
Thomas Tsou0c260ae2013-08-22 18:40:43 -04001619 *--w = w_i/d;
dburgessb3a0ca42011-10-12 07:44:40 +00001620 }
1621
1622
1623 return true;
1624
1625}
1626
1627// Assumes symbol-rate sampling!!!!
1628SoftVector *equalizeBurst(signalVector &rxBurst,
1629 float TOA,
Thomas Tsoue01e1b32013-09-02 13:24:13 +08001630 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +00001631 signalVector &w, // feedforward filter
1632 signalVector &b) // feedback filter
1633{
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001634 signalVector *postForwardFull;
dburgessb3a0ca42011-10-12 07:44:40 +00001635
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001636 if (!delayVector(rxBurst, -TOA))
1637 return NULL;
dburgessb3a0ca42011-10-12 07:44:40 +00001638
Thomas Tsouacc9ee92013-08-20 19:31:14 -04001639 postForwardFull = convolve(&rxBurst, &w, NULL,
1640 CUSTOM, 0, rxBurst.size() + w.size() - 1);
1641 if (!postForwardFull)
1642 return NULL;
dburgessb3a0ca42011-10-12 07:44:40 +00001643
1644 signalVector* postForward = new signalVector(rxBurst.size());
1645 postForwardFull->segmentCopyTo(*postForward,w.size()-1,rxBurst.size());
1646 delete postForwardFull;
1647
1648 signalVector::iterator dPtr = postForward->begin();
1649 signalVector::iterator dBackPtr;
1650 signalVector::iterator rotPtr = GMSKRotation->begin();
1651 signalVector::iterator revRotPtr = GMSKReverseRotation->begin();
1652
1653 signalVector *DFEoutput = new signalVector(postForward->size());
1654 signalVector::iterator DFEItr = DFEoutput->begin();
1655
1656 // NOTE: can insert the midamble and/or use midamble to estimate BER
1657 for (; dPtr < postForward->end(); dPtr++) {
1658 dBackPtr = dPtr-1;
1659 signalVector::iterator bPtr = b.begin();
1660 while ( (bPtr < b.end()) && (dBackPtr >= postForward->begin()) ) {
1661 *dPtr = *dPtr + (*bPtr)*(*dBackPtr);
1662 bPtr++;
1663 dBackPtr--;
1664 }
1665 *dPtr = *dPtr * (*revRotPtr);
1666 *DFEItr = *dPtr;
1667 // make decision on symbol
1668 *dPtr = (dPtr->real() > 0.0) ? 1.0 : -1.0;
1669 //*DFEItr = *dPtr;
1670 *dPtr = *dPtr * (*rotPtr);
1671 DFEItr++;
1672 rotPtr++;
1673 revRotPtr++;
1674 }
1675
1676 vectorSlicer(DFEoutput);
1677
1678 SoftVector *burstBits = new SoftVector(postForward->size());
1679 SoftVector::iterator burstItr = burstBits->begin();
1680 DFEItr = DFEoutput->begin();
1681 for (; DFEItr < DFEoutput->end(); DFEItr++)
1682 *burstItr++ = DFEItr->real();
1683
1684 delete postForward;
1685
1686 delete DFEoutput;
1687
1688 return burstBits;
1689}