dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
kurtis.heimerl | a198d45 | 2011-11-26 03:19:28 +0000 | [diff] [blame] | 2 | * Copyright 2008, 2011 Free Software Foundation, Inc. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 3 | * |
| 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 | |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 25 | #ifdef HAVE_CONFIG_H |
| 26 | #include "config.h" |
| 27 | #endif |
| 28 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 29 | #include "sigProcLib.h" |
| 30 | #include "GSMCommon.h" |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 31 | #include "Logger.h" |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 32 | #include "Resampler.h" |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 33 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 34 | extern "C" { |
| 35 | #include "convolve.h" |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 36 | #include "scale.h" |
Thomas Tsou | 0a3dc4c | 2013-11-09 02:29:55 -0500 | [diff] [blame] | 37 | #include "mult.h" |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 40 | using namespace GSM; |
| 41 | |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 42 | #define TABLESIZE 1024 |
| 43 | #define DELAYFILTS 64 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 44 | |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 45 | /* Clipping detection threshold */ |
| 46 | #define CLIP_THRESH 30000.0f |
| 47 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 48 | /** Lookup tables for trigonometric approximation */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 49 | static float cosTable[TABLESIZE+1]; // add 1 element for wrap around |
| 50 | static float sinTable[TABLESIZE+1]; |
| 51 | static float sincTable[TABLESIZE+1]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 52 | |
| 53 | /** Constants */ |
| 54 | static const float M_PI_F = (float)M_PI; |
| 55 | static const float M_2PI_F = (float)(2.0*M_PI); |
| 56 | static const float M_1_2PI_F = 1/M_2PI_F; |
| 57 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 58 | /* Precomputed rotation vectors */ |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 59 | static signalVector *GMSKRotation4 = NULL; |
| 60 | static signalVector *GMSKReverseRotation4 = NULL; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 61 | static signalVector *GMSKRotation1 = NULL; |
| 62 | static signalVector *GMSKReverseRotation1 = NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 63 | |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 64 | /* Precomputed fractional delay filters */ |
| 65 | static signalVector *delayFilters[DELAYFILTS]; |
| 66 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 67 | static const Complex<float> psk8_table[8] = { |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 68 | Complex<float>(-0.70710678, 0.70710678), |
| 69 | Complex<float>( 0.0, -1.0), |
| 70 | Complex<float>( 0.0, 1.0), |
| 71 | Complex<float>( 0.70710678, -0.70710678), |
| 72 | Complex<float>(-1.0, 0.0), |
| 73 | Complex<float>(-0.70710678, -0.70710678), |
| 74 | Complex<float>( 0.70710678, 0.70710678), |
| 75 | Complex<float>( 1.0, 0.0), |
| 76 | }; |
| 77 | |
| 78 | /* Downsampling filterbank - 4 SPS to 1 SPS */ |
| 79 | #define DOWNSAMPLE_IN_LEN 624 |
| 80 | #define DOWNSAMPLE_OUT_LEN 156 |
| 81 | |
| 82 | static Resampler *dnsampler = NULL; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 83 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 84 | /* |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 85 | * RACH and midamble correlation waveforms. Store the buffer separately |
| 86 | * because we need to allocate it explicitly outside of the signal vector |
| 87 | * constructor. This is because C++ (prior to C++11) is unable to natively |
| 88 | * perform 16-byte memory alignment required by many SSE instructions. |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 89 | */ |
| 90 | struct CorrelationSequence { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 91 | CorrelationSequence() : sequence(NULL), buffer(NULL) |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 92 | { |
| 93 | } |
| 94 | |
| 95 | ~CorrelationSequence() |
| 96 | { |
| 97 | delete sequence; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 98 | free(buffer); |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 99 | } |
| 100 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 101 | signalVector *sequence; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 102 | void *buffer; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 103 | float toa; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 104 | complex gain; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 105 | }; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 106 | |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 107 | /* |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 108 | * Gaussian and empty modulation pulses. Like the correlation sequences, |
| 109 | * store the runtime (Gaussian) buffer separately because of needed alignment |
| 110 | * for SSE instructions. |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 111 | */ |
| 112 | struct PulseSequence { |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 113 | PulseSequence() : c0(NULL), c1(NULL), c0_inv(NULL), empty(NULL), |
| 114 | c0_buffer(NULL), c1_buffer(NULL), c0_inv_buffer(NULL) |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 115 | { |
| 116 | } |
| 117 | |
| 118 | ~PulseSequence() |
| 119 | { |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 120 | delete c0; |
| 121 | delete c1; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 122 | delete c0_inv; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 123 | delete empty; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 124 | free(c0_buffer); |
| 125 | free(c1_buffer); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 128 | signalVector *c0; |
| 129 | signalVector *c1; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 130 | signalVector *c0_inv; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 131 | signalVector *empty; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 132 | void *c0_buffer; |
| 133 | void *c1_buffer; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 134 | void *c0_inv_buffer; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 135 | }; |
| 136 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 137 | static CorrelationSequence *gMidambles[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
| 138 | static CorrelationSequence *gEdgeMidambles[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
| 139 | static CorrelationSequence *gRACHSequence = NULL; |
| 140 | static PulseSequence *GSMPulse1 = NULL; |
| 141 | static PulseSequence *GSMPulse4 = NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 142 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 143 | void sigProcLibDestroy() |
| 144 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 145 | for (int i = 0; i < 8; i++) { |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 146 | delete gMidambles[i]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 147 | delete gEdgeMidambles[i]; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 148 | gMidambles[i] = NULL; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 149 | gEdgeMidambles[i] = NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 150 | } |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 151 | |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 152 | for (int i = 0; i < DELAYFILTS; i++) { |
| 153 | delete delayFilters[i]; |
| 154 | delayFilters[i] = NULL; |
| 155 | } |
| 156 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 157 | delete GMSKRotation1; |
| 158 | delete GMSKReverseRotation1; |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 159 | delete GMSKRotation4; |
| 160 | delete GMSKReverseRotation4; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 161 | delete gRACHSequence; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 162 | delete GSMPulse1; |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 163 | delete GSMPulse4; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 164 | delete dnsampler; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 165 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 166 | GMSKRotation1 = NULL; |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 167 | GMSKRotation4 = NULL; |
| 168 | GMSKReverseRotation4 = NULL; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 169 | GMSKReverseRotation1 = NULL; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 170 | gRACHSequence = NULL; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 171 | GSMPulse1 = NULL; |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 172 | GSMPulse4 = NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 175 | static float vectorNorm2(const signalVector &x) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 176 | { |
| 177 | signalVector::const_iterator xPtr = x.begin(); |
| 178 | float Energy = 0.0; |
| 179 | for (;xPtr != x.end();xPtr++) { |
| 180 | Energy += xPtr->norm2(); |
| 181 | } |
| 182 | return Energy; |
| 183 | } |
| 184 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 185 | /** compute e^(-jx) via lookup table. */ |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 186 | static complex expjLookup(float x) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 187 | { |
| 188 | float arg = x*M_1_2PI_F; |
| 189 | while (arg > 1.0F) arg -= 1.0F; |
| 190 | while (arg < 0.0F) arg += 1.0F; |
| 191 | |
| 192 | const float argT = arg*((float)TABLESIZE); |
| 193 | const int argI = (int)argT; |
| 194 | const float delta = argT-argI; |
| 195 | const float iDelta = 1.0F-delta; |
| 196 | return complex(iDelta*cosTable[argI] + delta*cosTable[argI+1], |
| 197 | iDelta*sinTable[argI] + delta*sinTable[argI+1]); |
| 198 | } |
| 199 | |
| 200 | /** Library setup functions */ |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 201 | static void initTrigTables() { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 202 | for (int i = 0; i < TABLESIZE+1; i++) { |
| 203 | cosTable[i] = cos(2.0*M_PI*i/TABLESIZE); |
| 204 | sinTable[i] = sin(2.0*M_PI*i/TABLESIZE); |
| 205 | } |
| 206 | } |
| 207 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 208 | /* |
| 209 | * Initialize 4 sps and 1 sps rotation tables |
| 210 | */ |
| 211 | static void initGMSKRotationTables() |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 212 | { |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 213 | size_t len1 = 157, len4 = 625; |
| 214 | |
| 215 | GMSKRotation4 = new signalVector(len4); |
| 216 | GMSKReverseRotation4 = new signalVector(len4); |
| 217 | signalVector::iterator rotPtr = GMSKRotation4->begin(); |
| 218 | signalVector::iterator revPtr = GMSKReverseRotation4->begin(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 219 | float phase = 0.0; |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 220 | while (rotPtr != GMSKRotation4->end()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 221 | *rotPtr++ = expjLookup(phase); |
| 222 | *revPtr++ = expjLookup(-phase); |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 223 | phase += M_PI_F / 2.0F / 4.0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 224 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 225 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 226 | GMSKRotation1 = new signalVector(len1); |
| 227 | GMSKReverseRotation1 = new signalVector(len1); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 228 | rotPtr = GMSKRotation1->begin(); |
| 229 | revPtr = GMSKReverseRotation1->begin(); |
| 230 | phase = 0.0; |
| 231 | while (rotPtr != GMSKRotation1->end()) { |
| 232 | *rotPtr++ = expjLookup(phase); |
| 233 | *revPtr++ = expjLookup(-phase); |
| 234 | phase += M_PI_F / 2.0F; |
Thomas Tsou | e57004d | 2013-08-20 18:55:33 -0400 | [diff] [blame] | 235 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 238 | static void GMSKRotate(signalVector &x, int sps) |
| 239 | { |
Thomas Tsou | 0a3dc4c | 2013-11-09 02:29:55 -0500 | [diff] [blame] | 240 | #if HAVE_NEON |
| 241 | size_t len; |
| 242 | signalVector *a, *b, *out; |
| 243 | |
| 244 | a = &x; |
| 245 | out = &x; |
| 246 | len = out->size(); |
| 247 | |
| 248 | if (len == 157) |
| 249 | len--; |
| 250 | |
| 251 | if (sps == 1) |
| 252 | b = GMSKRotation1; |
| 253 | else |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 254 | b = GMSKRotation4; |
Thomas Tsou | 0a3dc4c | 2013-11-09 02:29:55 -0500 | [diff] [blame] | 255 | |
| 256 | mul_complex((float *) out->begin(), |
| 257 | (float *) a->begin(), |
| 258 | (float *) b->begin(), len); |
| 259 | #else |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 260 | signalVector::iterator rotPtr, xPtr = x.begin(); |
| 261 | |
| 262 | if (sps == 1) |
| 263 | rotPtr = GMSKRotation1->begin(); |
| 264 | else |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 265 | rotPtr = GMSKRotation4->begin(); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 266 | |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 267 | if (x.isReal()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 268 | while (xPtr < x.end()) { |
| 269 | *xPtr = *rotPtr++ * (xPtr->real()); |
| 270 | xPtr++; |
| 271 | } |
| 272 | } |
| 273 | else { |
| 274 | while (xPtr < x.end()) { |
| 275 | *xPtr = *rotPtr++ * (*xPtr); |
| 276 | xPtr++; |
| 277 | } |
| 278 | } |
Thomas Tsou | 0a3dc4c | 2013-11-09 02:29:55 -0500 | [diff] [blame] | 279 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 282 | static bool GMSKReverseRotate(signalVector &x, int sps) |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 283 | { |
| 284 | signalVector::iterator rotPtr, xPtr= x.begin(); |
| 285 | |
| 286 | if (sps == 1) |
| 287 | rotPtr = GMSKReverseRotation1->begin(); |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 288 | else if (sps == 4) |
| 289 | rotPtr = GMSKReverseRotation4->begin(); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 290 | else |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 291 | return false; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 292 | |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 293 | if (x.isReal()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 294 | while (xPtr < x.end()) { |
| 295 | *xPtr = *rotPtr++ * (xPtr->real()); |
| 296 | xPtr++; |
| 297 | } |
| 298 | } |
| 299 | else { |
| 300 | while (xPtr < x.end()) { |
| 301 | *xPtr = *rotPtr++ * (*xPtr); |
| 302 | xPtr++; |
| 303 | } |
| 304 | } |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 305 | |
| 306 | return true; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 309 | /** Convolution type indicator */ |
| 310 | enum ConvType { |
| 311 | START_ONLY, |
| 312 | NO_DELAY, |
| 313 | CUSTOM, |
| 314 | UNDEFINED, |
| 315 | }; |
| 316 | |
| 317 | static signalVector *convolve(const signalVector *x, const signalVector *h, |
| 318 | signalVector *y, ConvType spanType, |
| 319 | size_t start = 0, size_t len = 0, |
| 320 | size_t step = 1, int offset = 0) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 321 | { |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 322 | int rc; |
| 323 | size_t head = 0, tail = 0; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 324 | bool alloc = false, append = false; |
| 325 | const signalVector *_x = NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 326 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 327 | if (!x || !h) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 328 | return NULL; |
| 329 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 330 | switch (spanType) { |
| 331 | case START_ONLY: |
| 332 | start = 0; |
Thomas Tsou | 6f4906e | 2013-11-09 02:40:18 -0500 | [diff] [blame] | 333 | head = h->size() - 1; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 334 | len = x->size(); |
Thomas Tsou | 6f4906e | 2013-11-09 02:40:18 -0500 | [diff] [blame] | 335 | |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 336 | if (x->getStart() < head) |
Thomas Tsou | 6f4906e | 2013-11-09 02:40:18 -0500 | [diff] [blame] | 337 | append = true; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 338 | break; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 339 | case NO_DELAY: |
| 340 | start = h->size() / 2; |
| 341 | head = start; |
| 342 | tail = start; |
| 343 | len = x->size(); |
| 344 | append = true; |
| 345 | break; |
| 346 | case CUSTOM: |
| 347 | if (start < h->size() - 1) { |
| 348 | head = h->size() - start; |
| 349 | append = true; |
| 350 | } |
| 351 | if (start + len > x->size()) { |
| 352 | tail = start + len - x->size(); |
| 353 | append = true; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 354 | } |
| 355 | break; |
| 356 | default: |
| 357 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 358 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 359 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 360 | /* |
| 361 | * Error if the output vector is too small. Create the output vector |
| 362 | * if the pointer is NULL. |
| 363 | */ |
| 364 | if (y && (len > y->size())) |
| 365 | return NULL; |
| 366 | if (!y) { |
| 367 | y = new signalVector(len); |
| 368 | alloc = true; |
| 369 | } |
| 370 | |
| 371 | /* Prepend or post-pend the input vector if the parameters require it */ |
| 372 | if (append) |
| 373 | _x = new signalVector(*x, head, tail); |
| 374 | else |
| 375 | _x = x; |
| 376 | |
| 377 | /* |
| 378 | * Four convovle types: |
| 379 | * 1. Complex-Real (aligned) |
| 380 | * 2. Complex-Complex (aligned) |
| 381 | * 3. Complex-Real (!aligned) |
| 382 | * 4. Complex-Complex (!aligned) |
| 383 | */ |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 384 | if (h->isReal() && h->isAligned()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 385 | rc = convolve_real((float *) _x->begin(), _x->size(), |
| 386 | (float *) h->begin(), h->size(), |
| 387 | (float *) y->begin(), y->size(), |
| 388 | start, len, step, offset); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 389 | } else if (!h->isReal() && h->isAligned()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 390 | rc = convolve_complex((float *) _x->begin(), _x->size(), |
| 391 | (float *) h->begin(), h->size(), |
| 392 | (float *) y->begin(), y->size(), |
| 393 | start, len, step, offset); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 394 | } else if (h->isReal() && !h->isAligned()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 395 | rc = base_convolve_real((float *) _x->begin(), _x->size(), |
| 396 | (float *) h->begin(), h->size(), |
| 397 | (float *) y->begin(), y->size(), |
| 398 | start, len, step, offset); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 399 | } else if (!h->isReal() && !h->isAligned()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 400 | rc = base_convolve_complex((float *) _x->begin(), _x->size(), |
| 401 | (float *) h->begin(), h->size(), |
| 402 | (float *) y->begin(), y->size(), |
| 403 | start, len, step, offset); |
| 404 | } else { |
| 405 | rc = -1; |
| 406 | } |
| 407 | |
| 408 | if (append) |
| 409 | delete _x; |
| 410 | |
| 411 | if (rc < 0) { |
| 412 | if (alloc) |
| 413 | delete y; |
| 414 | return NULL; |
| 415 | } |
| 416 | |
| 417 | return y; |
| 418 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 419 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 420 | /* |
| 421 | * Generate static EDGE linear equalizer. This equalizer is not adaptive. |
| 422 | * Filter taps are generated from the inverted 1 SPS impulse response of |
| 423 | * the EDGE pulse shape captured after the downsampling filter. |
| 424 | */ |
| 425 | static bool generateInvertC0Pulse(PulseSequence *pulse) |
| 426 | { |
| 427 | if (!pulse) |
| 428 | return false; |
| 429 | |
| 430 | pulse->c0_inv_buffer = convolve_h_alloc(5); |
| 431 | pulse->c0_inv = new signalVector((complex *) pulse->c0_inv_buffer, 0, 5); |
| 432 | pulse->c0_inv->isReal(true); |
| 433 | pulse->c0_inv->setAligned(false); |
| 434 | |
| 435 | signalVector::iterator xP = pulse->c0_inv->begin(); |
| 436 | *xP++ = 0.15884; |
| 437 | *xP++ = -0.43176; |
| 438 | *xP++ = 1.00000; |
| 439 | *xP++ = -0.42608; |
| 440 | *xP++ = 0.14882; |
| 441 | |
| 442 | return true; |
| 443 | } |
| 444 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 445 | static bool generateC1Pulse(int sps, PulseSequence *pulse) |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 446 | { |
| 447 | int len; |
| 448 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 449 | if (!pulse) |
| 450 | return false; |
| 451 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 452 | switch (sps) { |
| 453 | case 4: |
| 454 | len = 8; |
| 455 | break; |
| 456 | default: |
| 457 | return false; |
| 458 | } |
| 459 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 460 | pulse->c1_buffer = convolve_h_alloc(len); |
| 461 | pulse->c1 = new signalVector((complex *) |
| 462 | pulse->c1_buffer, 0, len); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 463 | pulse->c1->isReal(true); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 464 | |
| 465 | /* Enable alignment for SSE usage */ |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 466 | pulse->c1->setAligned(true); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 467 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 468 | signalVector::iterator xP = pulse->c1->begin(); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 469 | |
| 470 | switch (sps) { |
| 471 | case 4: |
| 472 | /* BT = 0.30 */ |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 473 | *xP++ = 0.0; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 474 | *xP++ = 8.16373112e-03; |
| 475 | *xP++ = 2.84385729e-02; |
| 476 | *xP++ = 5.64158904e-02; |
| 477 | *xP++ = 7.05463553e-02; |
| 478 | *xP++ = 5.64158904e-02; |
| 479 | *xP++ = 2.84385729e-02; |
| 480 | *xP++ = 8.16373112e-03; |
| 481 | } |
| 482 | |
| 483 | return true; |
| 484 | } |
| 485 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 486 | static PulseSequence *generateGSMPulse(int sps) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 487 | { |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 488 | int len; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 489 | float arg, avg, center; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 490 | PulseSequence *pulse; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 491 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 492 | if ((sps != 1) && (sps != 4)) |
| 493 | return NULL; |
| 494 | |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 495 | /* Store a single tap filter used for correlation sequence generation */ |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 496 | pulse = new PulseSequence(); |
| 497 | pulse->empty = new signalVector(1); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 498 | pulse->empty->isReal(true); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 499 | *(pulse->empty->begin()) = 1.0f; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 500 | |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 501 | /* |
| 502 | * For 4 samples-per-symbol use a precomputed single pulse Laurent |
| 503 | * approximation. This should yields below 2 degrees of phase error at |
| 504 | * the modulator output. Use the existing pulse approximation for all |
| 505 | * other oversampling factors. |
| 506 | */ |
| 507 | switch (sps) { |
| 508 | case 4: |
| 509 | len = 16; |
| 510 | break; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 511 | case 1: |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 512 | default: |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 513 | len = 4; |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 514 | } |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 515 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 516 | pulse->c0_buffer = convolve_h_alloc(len); |
| 517 | pulse->c0 = new signalVector((complex *) pulse->c0_buffer, 0, len); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 518 | pulse->c0->isReal(true); |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 519 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 520 | /* Enable alingnment for SSE usage */ |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 521 | pulse->c0->setAligned(true); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 522 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 523 | signalVector::iterator xP = pulse->c0->begin(); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 524 | |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 525 | if (sps == 4) { |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 526 | *xP++ = 0.0; |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 527 | *xP++ = 4.46348606e-03; |
| 528 | *xP++ = 2.84385729e-02; |
| 529 | *xP++ = 1.03184855e-01; |
| 530 | *xP++ = 2.56065552e-01; |
| 531 | *xP++ = 4.76375085e-01; |
| 532 | *xP++ = 7.05961177e-01; |
| 533 | *xP++ = 8.71291644e-01; |
| 534 | *xP++ = 9.29453645e-01; |
| 535 | *xP++ = 8.71291644e-01; |
| 536 | *xP++ = 7.05961177e-01; |
| 537 | *xP++ = 4.76375085e-01; |
| 538 | *xP++ = 2.56065552e-01; |
| 539 | *xP++ = 1.03184855e-01; |
| 540 | *xP++ = 2.84385729e-02; |
| 541 | *xP++ = 4.46348606e-03; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 542 | generateC1Pulse(sps, pulse); |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 543 | } else { |
| 544 | center = (float) (len - 1.0) / 2.0; |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 545 | |
Thomas Tsou | 9ccd9f2 | 2013-08-21 13:59:52 -0400 | [diff] [blame] | 546 | /* GSM pulse approximation */ |
| 547 | for (int i = 0; i < len; i++) { |
| 548 | arg = ((float) i - center) / (float) sps; |
| 549 | *xP++ = 0.96 * exp(-1.1380 * arg * arg - |
| 550 | 0.527 * arg * arg * arg * arg); |
| 551 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 552 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 553 | avg = sqrtf(vectorNorm2(*pulse->c0) / sps); |
| 554 | xP = pulse->c0->begin(); |
| 555 | for (int i = 0; i < len; i++) |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 556 | *xP++ /= avg; |
| 557 | } |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 558 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 559 | /* |
| 560 | * Current form of the EDGE equalization filter non-realizable at 4 SPS. |
| 561 | * Load the onto both 1 SPS and 4 SPS objects for convenience. Note that |
| 562 | * the EDGE demodulator downsamples to 1 SPS prior to equalization. |
| 563 | */ |
| 564 | generateInvertC0Pulse(pulse); |
| 565 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 566 | return pulse; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 569 | bool vectorSlicer(SoftVector *x) |
| 570 | { |
| 571 | SoftVector::iterator xP = x->begin(); |
| 572 | SoftVector::iterator xPEnd = x->end(); |
| 573 | while (xP < xPEnd) { |
| 574 | *xP = 0.5 * (*xP + 1.0f); |
| 575 | if (*xP > 1.0) |
| 576 | *xP = 1.0; |
| 577 | if (*xP < 0.0) |
| 578 | *xP = 0.0; |
| 579 | xP++; |
| 580 | } |
| 581 | return true; |
| 582 | } |
| 583 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 584 | static signalVector *rotateBurst(const BitVector &wBurst, |
| 585 | int guardPeriodLength, int sps) |
| 586 | { |
| 587 | int burst_len; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 588 | signalVector *pulse, rotated; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 589 | signalVector::iterator itr; |
| 590 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 591 | pulse = GSMPulse1->empty; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 592 | burst_len = sps * (wBurst.size() + guardPeriodLength); |
| 593 | rotated = signalVector(burst_len); |
| 594 | itr = rotated.begin(); |
| 595 | |
| 596 | for (unsigned i = 0; i < wBurst.size(); i++) { |
| 597 | *itr = 2.0 * (wBurst[i] & 0x01) - 1.0; |
| 598 | itr += sps; |
| 599 | } |
| 600 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 601 | GMSKRotate(rotated, sps); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 602 | rotated.isReal(false); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 603 | |
| 604 | /* Dummy filter operation */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 605 | return convolve(&rotated, pulse, NULL, START_ONLY); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 608 | static void rotateBurst2(signalVector &burst, double phase) |
| 609 | { |
| 610 | Complex<float> rot = Complex<float>(cos(phase), sin(phase)); |
| 611 | |
| 612 | for (size_t i = 0; i < burst.size(); i++) |
| 613 | burst[i] = burst[i] * rot; |
| 614 | } |
| 615 | |
Tom Tsou | 4dfd64a | 2016-03-06 20:31:51 -0800 | [diff] [blame] | 616 | /* |
| 617 | * Ignore the guard length argument in the GMSK modulator interface |
| 618 | * because it results in 624/628 sized bursts instead of the preferred |
| 619 | * burst length of 625. Only 4 SPS is supported. |
| 620 | */ |
| 621 | static signalVector *modulateBurstLaurent(const BitVector &bits) |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 622 | { |
Tom Tsou | 4dfd64a | 2016-03-06 20:31:51 -0800 | [diff] [blame] | 623 | int burst_len, sps = 4; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 624 | float phase; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 625 | signalVector *c0_pulse, *c1_pulse, *c0_shaped, *c1_shaped; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 626 | signalVector::iterator c0_itr, c1_itr; |
| 627 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 628 | c0_pulse = GSMPulse4->c0; |
| 629 | c1_pulse = GSMPulse4->c1; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 630 | |
Tom Tsou | 4dfd64a | 2016-03-06 20:31:51 -0800 | [diff] [blame] | 631 | if (bits.size() > 156) |
| 632 | return NULL; |
| 633 | |
| 634 | burst_len = 625; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 635 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 636 | signalVector c0_burst(burst_len, c0_pulse->size()); |
| 637 | c0_burst.isReal(true); |
| 638 | c0_itr = c0_burst.begin(); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 639 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 640 | signalVector c1_burst(burst_len, c1_pulse->size()); |
| 641 | c1_itr = c1_burst.begin(); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 642 | |
Tom Tsou | aa15d62 | 2016-08-11 14:36:23 -0700 | [diff] [blame] | 643 | /* Padded differential tail bits */ |
| 644 | *c0_itr = 2.0 * (0x00 & 0x01) - 1.0; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 645 | c0_itr += sps; |
| 646 | |
| 647 | /* Main burst bits */ |
| 648 | for (unsigned i = 0; i < bits.size(); i++) { |
| 649 | *c0_itr = 2.0 * (bits[i] & 0x01) - 1.0; |
| 650 | c0_itr += sps; |
| 651 | } |
| 652 | |
Tom Tsou | aa15d62 | 2016-08-11 14:36:23 -0700 | [diff] [blame] | 653 | /* Padded differential tail bits */ |
| 654 | *c0_itr = 2.0 * (0x00 & 0x01) - 1.0; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 655 | |
| 656 | /* Generate C0 phase coefficients */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 657 | GMSKRotate(c0_burst, sps); |
| 658 | c0_burst.isReal(false); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 659 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 660 | c0_itr = c0_burst.begin(); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 661 | c0_itr += sps * 2; |
| 662 | c1_itr += sps * 2; |
| 663 | |
| 664 | /* Start magic */ |
| 665 | phase = 2.0 * ((0x01 & 0x01) ^ (0x01 & 0x01)) - 1.0; |
| 666 | *c1_itr = *c0_itr * Complex<float>(0, phase); |
| 667 | c0_itr += sps; |
| 668 | c1_itr += sps; |
| 669 | |
| 670 | /* Generate C1 phase coefficients */ |
| 671 | for (unsigned i = 2; i < bits.size(); i++) { |
| 672 | phase = 2.0 * ((bits[i - 1] & 0x01) ^ (bits[i - 2] & 0x01)) - 1.0; |
| 673 | *c1_itr = *c0_itr * Complex<float>(0, phase); |
| 674 | |
| 675 | c0_itr += sps; |
| 676 | c1_itr += sps; |
| 677 | } |
| 678 | |
| 679 | /* End magic */ |
| 680 | int i = bits.size(); |
| 681 | phase = 2.0 * ((bits[i-1] & 0x01) ^ (bits[i-2] & 0x01)) - 1.0; |
| 682 | *c1_itr = *c0_itr * Complex<float>(0, phase); |
| 683 | |
| 684 | /* Primary (C0) and secondary (C1) pulse shaping */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 685 | c0_shaped = convolve(&c0_burst, c0_pulse, NULL, START_ONLY); |
| 686 | c1_shaped = convolve(&c1_burst, c1_pulse, NULL, START_ONLY); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 687 | |
| 688 | /* Sum shaped outputs into C0 */ |
| 689 | c0_itr = c0_shaped->begin(); |
| 690 | c1_itr = c1_shaped->begin(); |
| 691 | for (unsigned i = 0; i < c0_shaped->size(); i++ ) |
| 692 | *c0_itr++ += *c1_itr++; |
| 693 | |
| 694 | delete c1_shaped; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 695 | return c0_shaped; |
| 696 | } |
| 697 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 698 | static signalVector *rotateEdgeBurst(const signalVector &symbols, int sps) |
| 699 | { |
| 700 | signalVector *burst; |
| 701 | signalVector::iterator burst_itr; |
| 702 | |
| 703 | burst = new signalVector(symbols.size() * sps); |
| 704 | burst_itr = burst->begin(); |
| 705 | |
| 706 | for (size_t i = 0; i < symbols.size(); i++) { |
| 707 | float phase = i * 3.0f * M_PI / 8.0f; |
| 708 | Complex<float> rot = Complex<float>(cos(phase), sin(phase)); |
| 709 | |
| 710 | *burst_itr = symbols[i] * rot; |
| 711 | burst_itr += sps; |
| 712 | } |
| 713 | |
| 714 | return burst; |
| 715 | } |
| 716 | |
| 717 | static signalVector *derotateEdgeBurst(const signalVector &symbols, int sps) |
| 718 | { |
| 719 | signalVector *burst; |
| 720 | signalVector::iterator burst_itr; |
| 721 | |
| 722 | if (symbols.size() % sps) |
| 723 | return NULL; |
| 724 | |
| 725 | burst = new signalVector(symbols.size() / sps); |
| 726 | burst_itr = burst->begin(); |
| 727 | |
| 728 | for (size_t i = 0; i < burst->size(); i++) { |
| 729 | float phase = (float) (i % 16) * 3.0f * M_PI / 8.0f; |
| 730 | Complex<float> rot = Complex<float>(cosf(phase), -sinf(phase)); |
| 731 | |
| 732 | *burst_itr = symbols[sps * i] * rot; |
| 733 | burst_itr++; |
| 734 | } |
| 735 | |
| 736 | return burst; |
| 737 | } |
| 738 | |
| 739 | static signalVector *mapEdgeSymbols(const BitVector &bits) |
| 740 | { |
| 741 | if (bits.size() % 3) |
| 742 | return NULL; |
| 743 | |
| 744 | signalVector *symbols = new signalVector(bits.size() / 3); |
| 745 | |
| 746 | for (size_t i = 0; i < symbols->size(); i++) { |
| 747 | unsigned index = (((unsigned) bits[3 * i + 0] & 0x01) << 0) | |
| 748 | (((unsigned) bits[3 * i + 1] & 0x01) << 1) | |
| 749 | (((unsigned) bits[3 * i + 2] & 0x01) << 2); |
| 750 | |
| 751 | (*symbols)[i] = psk8_table[index]; |
| 752 | } |
| 753 | |
| 754 | return symbols; |
| 755 | } |
| 756 | |
Tom Tsou | d2b0703 | 2016-04-26 19:28:59 -0700 | [diff] [blame] | 757 | /* |
| 758 | * EDGE 8-PSK rotate and pulse shape |
| 759 | * |
| 760 | * Delay the EDGE downlink bursts by one symbol in order to match GMSK pulse |
| 761 | * shaping group delay. The difference in group delay arises from the dual |
| 762 | * pulse filter combination of the GMSK Laurent represenation whereas 8-PSK |
| 763 | * uses a single pulse linear filter. |
| 764 | */ |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 765 | static signalVector *shapeEdgeBurst(const signalVector &symbols) |
| 766 | { |
Tom Tsou | d2b0703 | 2016-04-26 19:28:59 -0700 | [diff] [blame] | 767 | size_t nsyms, nsamps = 625, sps = 4; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 768 | signalVector::iterator burst_itr; |
| 769 | |
| 770 | nsyms = symbols.size(); |
| 771 | |
Tom Tsou | d2b0703 | 2016-04-26 19:28:59 -0700 | [diff] [blame] | 772 | if (nsyms * sps > nsamps) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 773 | nsyms = 156; |
| 774 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 775 | signalVector burst(nsamps, GSMPulse4->c0->size()); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 776 | |
Tom Tsou | d2b0703 | 2016-04-26 19:28:59 -0700 | [diff] [blame] | 777 | /* Delay burst by 1 symbol */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 778 | burst_itr = burst.begin() + sps; |
Tom Tsou | 06676ea | 2016-07-19 12:50:21 -0700 | [diff] [blame] | 779 | for (size_t i = 0; i < nsyms; i++) { |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 780 | float phase = i * 3.0f * M_PI / 8.0f; |
| 781 | Complex<float> rot = Complex<float>(cos(phase), sin(phase)); |
| 782 | |
| 783 | *burst_itr = symbols[i] * rot; |
Tom Tsou | d2b0703 | 2016-04-26 19:28:59 -0700 | [diff] [blame] | 784 | burst_itr += sps; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /* Single Gaussian pulse approximation shaping */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 788 | return convolve(&burst, GSMPulse4->c0, NULL, START_ONLY); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /* |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 792 | * Generate a random GSM normal burst. |
| 793 | */ |
| 794 | signalVector *genRandNormalBurst(int tsc, int sps, int tn) |
| 795 | { |
| 796 | if ((tsc < 0) || (tsc > 7) || (tn < 0) || (tn > 7)) |
| 797 | return NULL; |
| 798 | if ((sps != 1) && (sps != 4)) |
| 799 | return NULL; |
| 800 | |
| 801 | int i = 0; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 802 | BitVector bits(148); |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 803 | |
| 804 | /* Tail bits */ |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 805 | for (; i < 3; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 806 | bits[i] = 0; |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 807 | |
| 808 | /* Random bits */ |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 809 | for (; i < 60; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 810 | bits[i] = rand() % 2; |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 811 | |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 812 | /* Stealing bit */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 813 | bits[i++] = 0; |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 814 | |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 815 | /* Training sequence */ |
| 816 | for (int n = 0; i < 87; i++, n++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 817 | bits[i] = gTrainingSequence[tsc][n]; |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 818 | |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 819 | /* Stealing bit */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 820 | bits[i++] = 0; |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 821 | |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 822 | /* Random bits */ |
Alexander Chemeris | 5e65b53 | 2017-03-24 23:24:22 -0700 | [diff] [blame] | 823 | for (; i < 145; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 824 | bits[i] = rand() % 2; |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 825 | |
| 826 | /* Tail bits */ |
| 827 | for (; i < 148; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 828 | bits[i] = 0; |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 829 | |
| 830 | int guard = 8 + !(tn % 4); |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 831 | return modulateBurst(bits, guard, sps); |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 834 | /* |
| 835 | * Generate a random GSM access burst. |
| 836 | */ |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 837 | signalVector *genRandAccessBurst(int delay, int sps, int tn) |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 838 | { |
| 839 | if ((tn < 0) || (tn > 7)) |
| 840 | return NULL; |
| 841 | if ((sps != 1) && (sps != 4)) |
| 842 | return NULL; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 843 | if (delay > 68) |
| 844 | return NULL; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 845 | |
| 846 | int i = 0; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 847 | BitVector bits(88 + delay); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 848 | |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 849 | /* delay */ |
| 850 | for (; i < delay; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 851 | bits[i] = 0; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 852 | |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 853 | /* head and synch bits */ |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 854 | for (int n = 0; i < 49+delay; i++, n++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 855 | bits[i] = gRACHBurst[n]; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 856 | |
| 857 | /* Random bits */ |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 858 | for (; i < 85+delay; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 859 | bits[i] = rand() % 2; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 860 | |
| 861 | /* Tail bits */ |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 862 | for (; i < 88+delay; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 863 | bits[i] = 0; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 864 | |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 865 | int guard = 68-delay + !(tn % 4); |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 866 | return modulateBurst(bits, guard, sps); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 867 | } |
| 868 | |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 869 | signalVector *generateEmptyBurst(int sps, int tn) |
| 870 | { |
| 871 | if ((tn < 0) || (tn > 7)) |
| 872 | return NULL; |
| 873 | |
| 874 | if (sps == 4) |
| 875 | return new signalVector(625); |
| 876 | else if (sps == 1) |
| 877 | return new signalVector(148 + 8 + !(tn % 4)); |
| 878 | else |
| 879 | return NULL; |
| 880 | } |
| 881 | |
| 882 | signalVector *generateDummyBurst(int sps, int tn) |
| 883 | { |
| 884 | if (((sps != 1) && (sps != 4)) || (tn < 0) || (tn > 7)) |
| 885 | return NULL; |
| 886 | |
| 887 | return modulateBurst(gDummyBurst, 8 + !(tn % 4), sps); |
| 888 | } |
| 889 | |
| 890 | /* |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 891 | * Generate a random 8-PSK EDGE burst. Only 4 SPS is supported with |
| 892 | * the returned burst being 625 samples in length. |
| 893 | */ |
| 894 | signalVector *generateEdgeBurst(int tsc) |
| 895 | { |
| 896 | int tail = 9 / 3; |
| 897 | int data = 174 / 3; |
| 898 | int train = 78 / 3; |
| 899 | |
| 900 | if ((tsc < 0) || (tsc > 7)) |
| 901 | return NULL; |
| 902 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 903 | signalVector burst(148); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 904 | const BitVector *midamble = &gEdgeTrainingSequence[tsc]; |
| 905 | |
| 906 | /* Tail */ |
| 907 | int n, i = 0; |
| 908 | for (; i < tail; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 909 | burst[i] = psk8_table[7]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 910 | |
| 911 | /* Body */ |
| 912 | for (; i < tail + data; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 913 | burst[i] = psk8_table[rand() % 8]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 914 | |
| 915 | /* TSC */ |
| 916 | for (n = 0; i < tail + data + train; i++, n++) { |
| 917 | unsigned index = (((unsigned) (*midamble)[3 * n + 0] & 0x01) << 0) | |
| 918 | (((unsigned) (*midamble)[3 * n + 1] & 0x01) << 1) | |
| 919 | (((unsigned) (*midamble)[3 * n + 2] & 0x01) << 2); |
| 920 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 921 | burst[i] = psk8_table[index]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /* Body */ |
| 925 | for (; i < tail + data + train + data; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 926 | burst[i] = psk8_table[rand() % 8]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 927 | |
| 928 | /* Tail */ |
| 929 | for (; i < tail + data + train + data + tail; i++) |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 930 | burst[i] = psk8_table[7]; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 931 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 932 | return shapeEdgeBurst(burst); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* |
| 936 | * Modulate 8-PSK burst. When empty pulse shaping (rotation only) |
| 937 | * is enabled, the output vector length will be bit sequence length |
| 938 | * times the SPS value. When pulse shaping is enabled, the output |
Alexander Chemeris | 9270a5a | 2017-03-17 13:03:41 -0700 | [diff] [blame] | 939 | * vector length is fixed at 625 samples (156.25 symbols at 4 SPS). |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 940 | * Pulse shaped bit sequences that go beyond one burst are truncated. |
| 941 | * Pulse shaping at anything but 4 SPS is not supported. |
| 942 | */ |
| 943 | signalVector *modulateEdgeBurst(const BitVector &bits, |
| 944 | int sps, bool empty) |
| 945 | { |
| 946 | signalVector *shape, *burst; |
| 947 | |
| 948 | if ((sps != 4) && !empty) |
| 949 | return NULL; |
| 950 | |
| 951 | burst = mapEdgeSymbols(bits); |
| 952 | if (!burst) |
| 953 | return NULL; |
| 954 | |
| 955 | if (empty) |
| 956 | shape = rotateEdgeBurst(*burst, sps); |
| 957 | else |
| 958 | shape = shapeEdgeBurst(*burst); |
| 959 | |
| 960 | delete burst; |
| 961 | return shape; |
| 962 | } |
| 963 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 964 | static signalVector *modulateBurstBasic(const BitVector &bits, |
| 965 | int guard_len, int sps) |
| 966 | { |
| 967 | int burst_len; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 968 | signalVector *pulse; |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 969 | signalVector::iterator burst_itr; |
| 970 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 971 | if (sps == 1) |
| 972 | pulse = GSMPulse1->c0; |
| 973 | else |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 974 | pulse = GSMPulse4->c0; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 975 | |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 976 | burst_len = sps * (bits.size() + guard_len); |
| 977 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 978 | signalVector burst(burst_len, pulse->size()); |
| 979 | burst.isReal(true); |
| 980 | burst_itr = burst.begin(); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 981 | |
| 982 | /* Raw bits are not differentially encoded */ |
| 983 | for (unsigned i = 0; i < bits.size(); i++) { |
| 984 | *burst_itr = 2.0 * (bits[i] & 0x01) - 1.0; |
| 985 | burst_itr += sps; |
| 986 | } |
| 987 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 988 | GMSKRotate(burst, sps); |
| 989 | burst.isReal(false); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 990 | |
| 991 | /* Single Gaussian pulse approximation shaping */ |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 992 | return convolve(&burst, pulse, NULL, START_ONLY); |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 993 | } |
| 994 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 995 | /* Assume input bits are not differentially encoded */ |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 996 | signalVector *modulateBurst(const BitVector &wBurst, int guardPeriodLength, |
| 997 | int sps, bool emptyPulse) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 998 | { |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 999 | if (emptyPulse) |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 1000 | return rotateBurst(wBurst, guardPeriodLength, sps); |
| 1001 | else if (sps == 4) |
Tom Tsou | 4dfd64a | 2016-03-06 20:31:51 -0800 | [diff] [blame] | 1002 | return modulateBurstLaurent(wBurst); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 1003 | else |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 1004 | return modulateBurstBasic(wBurst, guardPeriodLength, sps); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1007 | static void generateSincTable() |
Thomas Tsou | 0e0e1f4 | 2013-11-09 22:08:51 -0500 | [diff] [blame] | 1008 | { |
| 1009 | float x; |
| 1010 | |
| 1011 | for (int i = 0; i < TABLESIZE; i++) { |
| 1012 | x = (float) i / TABLESIZE * 8 * M_PI; |
| 1013 | if (fabs(x) < 0.01) { |
| 1014 | sincTable[i] = 1.0f; |
| 1015 | continue; |
| 1016 | } |
| 1017 | |
| 1018 | sincTable[i] = sinf(x) / x; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1022 | static float sinc(float x) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1023 | { |
Thomas Tsou | 0e0e1f4 | 2013-11-09 22:08:51 -0500 | [diff] [blame] | 1024 | if (fabs(x) >= 8 * M_PI) |
| 1025 | return 0.0; |
| 1026 | |
| 1027 | int index = (int) floorf(fabs(x) / (8 * M_PI) * TABLESIZE); |
| 1028 | |
| 1029 | return sincTable[index]; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 1032 | /* |
| 1033 | * Create fractional delay filterbank with Blackman-harris windowed |
| 1034 | * sinc function generator. The number of filters generated is specified |
| 1035 | * by the DELAYFILTS value. |
| 1036 | */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1037 | static void generateDelayFilters() |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 1038 | { |
| 1039 | int h_len = 20; |
| 1040 | complex *data; |
| 1041 | signalVector *h; |
| 1042 | signalVector::iterator itr; |
| 1043 | |
| 1044 | float k, sum; |
| 1045 | float a0 = 0.35875; |
| 1046 | float a1 = 0.48829; |
| 1047 | float a2 = 0.14128; |
| 1048 | float a3 = 0.01168; |
| 1049 | |
| 1050 | for (int i = 0; i < DELAYFILTS; i++) { |
| 1051 | data = (complex *) convolve_h_alloc(h_len); |
| 1052 | h = new signalVector(data, 0, h_len); |
| 1053 | h->setAligned(true); |
| 1054 | h->isReal(true); |
| 1055 | |
| 1056 | sum = 0.0; |
| 1057 | itr = h->end(); |
| 1058 | for (int n = 0; n < h_len; n++) { |
| 1059 | k = (float) n; |
| 1060 | *--itr = (complex) sinc(M_PI_F * |
| 1061 | (k - (float) h_len / 2.0 - (float) i / DELAYFILTS)); |
| 1062 | *itr *= a0 - |
| 1063 | a1 * cos(2 * M_PI * n / (h_len - 1)) + |
| 1064 | a2 * cos(4 * M_PI * n / (h_len - 1)) - |
| 1065 | a3 * cos(6 * M_PI * n / (h_len - 1)); |
| 1066 | |
| 1067 | sum += itr->real(); |
| 1068 | } |
| 1069 | |
| 1070 | itr = h->begin(); |
| 1071 | for (int n = 0; n < h_len; n++) |
| 1072 | *itr++ /= sum; |
| 1073 | |
| 1074 | delayFilters[i] = h; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Alexander Chemeris | e0c1218 | 2017-03-18 13:27:48 -0700 | [diff] [blame] | 1078 | signalVector *delayVector(const signalVector *in, signalVector *out, float delay) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1079 | { |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 1080 | int whole, index; |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1081 | float frac; |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1082 | signalVector *h, *shift, *fshift = NULL; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1083 | |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1084 | whole = floor(delay); |
| 1085 | frac = delay - whole; |
| 1086 | |
| 1087 | /* Sinc interpolated fractional shift (if allowable) */ |
| 1088 | if (fabs(frac) > 1e-2) { |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 1089 | index = floorf(frac * (float) DELAYFILTS); |
| 1090 | h = delayFilters[index]; |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1091 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1092 | fshift = convolve(in, h, NULL, NO_DELAY); |
| 1093 | if (!fshift) |
| 1094 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1097 | if (!fshift) |
| 1098 | shift = new signalVector(*in); |
| 1099 | else |
| 1100 | shift = fshift; |
| 1101 | |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1102 | /* Integer sample shift */ |
| 1103 | if (whole < 0) { |
| 1104 | whole = -whole; |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1105 | signalVector::iterator wBurstItr = shift->begin(); |
| 1106 | signalVector::iterator shiftedItr = shift->begin() + whole; |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1107 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1108 | while (shiftedItr < shift->end()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1109 | *wBurstItr++ = *shiftedItr++; |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1110 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1111 | while (wBurstItr < shift->end()) |
| 1112 | *wBurstItr++ = 0.0; |
| 1113 | } else if (whole >= 0) { |
| 1114 | signalVector::iterator wBurstItr = shift->end() - 1; |
| 1115 | signalVector::iterator shiftedItr = shift->end() - 1 - whole; |
| 1116 | |
| 1117 | while (shiftedItr >= shift->begin()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1118 | *wBurstItr-- = *shiftedItr--; |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1119 | |
| 1120 | while (wBurstItr >= shift->begin()) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1121 | *wBurstItr-- = 0.0; |
| 1122 | } |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1123 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1124 | if (!out) |
| 1125 | return shift; |
| 1126 | |
| 1127 | out->clone(*shift); |
| 1128 | delete shift; |
| 1129 | return out; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1130 | } |
Thomas Tsou | 2c282f5 | 2013-10-08 21:34:35 -0400 | [diff] [blame] | 1131 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1132 | static complex interpolatePoint(const signalVector &inSig, float ix) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1133 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1134 | int start = (int) (floor(ix) - 10); |
| 1135 | if (start < 0) start = 0; |
| 1136 | int end = (int) (floor(ix) + 11); |
| 1137 | if ((unsigned) end > inSig.size()-1) end = inSig.size()-1; |
| 1138 | |
| 1139 | complex pVal = 0.0; |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 1140 | if (!inSig.isReal()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1141 | for (int i = start; i < end; i++) |
| 1142 | pVal += inSig[i] * sinc(M_PI_F*(i-ix)); |
| 1143 | } |
| 1144 | else { |
| 1145 | for (int i = start; i < end; i++) |
| 1146 | pVal += inSig[i].real() * sinc(M_PI_F*(i-ix)); |
| 1147 | } |
| 1148 | |
| 1149 | return pVal; |
| 1150 | } |
| 1151 | |
Thomas Tsou | 8181b01 | 2013-08-20 21:17:19 -0400 | [diff] [blame] | 1152 | static complex fastPeakDetect(const signalVector &rxBurst, float *index) |
| 1153 | { |
| 1154 | float val, max = 0.0f; |
| 1155 | complex amp; |
| 1156 | int _index = -1; |
| 1157 | |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 1158 | for (size_t i = 0; i < rxBurst.size(); i++) { |
Thomas Tsou | 8181b01 | 2013-08-20 21:17:19 -0400 | [diff] [blame] | 1159 | val = rxBurst[i].norm2(); |
| 1160 | if (val > max) { |
| 1161 | max = val; |
| 1162 | _index = i; |
| 1163 | amp = rxBurst[i]; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | if (index) |
| 1168 | *index = (float) _index; |
| 1169 | |
| 1170 | return amp; |
| 1171 | } |
| 1172 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1173 | static complex peakDetect(const signalVector &rxBurst, |
| 1174 | float *peakIndex, float *avgPwr) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1175 | { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1176 | complex maxVal = 0.0; |
| 1177 | float maxIndex = -1; |
| 1178 | float sumPower = 0.0; |
| 1179 | |
| 1180 | for (unsigned int i = 0; i < rxBurst.size(); i++) { |
| 1181 | float samplePower = rxBurst[i].norm2(); |
| 1182 | if (samplePower > maxVal.real()) { |
| 1183 | maxVal = samplePower; |
| 1184 | maxIndex = i; |
| 1185 | } |
| 1186 | sumPower += samplePower; |
| 1187 | } |
| 1188 | |
| 1189 | // interpolate around the peak |
| 1190 | // to save computation, we'll use early-late balancing |
| 1191 | float earlyIndex = maxIndex-1; |
| 1192 | float lateIndex = maxIndex+1; |
| 1193 | |
| 1194 | float incr = 0.5; |
| 1195 | while (incr > 1.0/1024.0) { |
| 1196 | complex earlyP = interpolatePoint(rxBurst,earlyIndex); |
| 1197 | complex lateP = interpolatePoint(rxBurst,lateIndex); |
| 1198 | if (earlyP < lateP) |
| 1199 | earlyIndex += incr; |
| 1200 | else if (earlyP > lateP) |
| 1201 | earlyIndex -= incr; |
| 1202 | else break; |
| 1203 | incr /= 2.0; |
| 1204 | lateIndex = earlyIndex + 2.0; |
| 1205 | } |
| 1206 | |
| 1207 | maxIndex = earlyIndex + 1.0; |
| 1208 | maxVal = interpolatePoint(rxBurst,maxIndex); |
| 1209 | |
| 1210 | if (peakIndex!=NULL) |
| 1211 | *peakIndex = maxIndex; |
| 1212 | |
| 1213 | if (avgPwr!=NULL) |
| 1214 | *avgPwr = (sumPower-maxVal.norm2()) / (rxBurst.size()-1); |
| 1215 | |
| 1216 | return maxVal; |
| 1217 | |
| 1218 | } |
| 1219 | |
| 1220 | void scaleVector(signalVector &x, |
| 1221 | complex scale) |
| 1222 | { |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 1223 | #ifdef HAVE_NEON |
| 1224 | int len = x.size(); |
| 1225 | |
| 1226 | scale_complex((float *) x.begin(), |
| 1227 | (float *) x.begin(), |
| 1228 | (float *) &scale, len); |
| 1229 | #else |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1230 | signalVector::iterator xP = x.begin(); |
| 1231 | signalVector::iterator xPEnd = x.end(); |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 1232 | if (!x.isReal()) { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1233 | while (xP < xPEnd) { |
| 1234 | *xP = *xP * scale; |
| 1235 | xP++; |
| 1236 | } |
| 1237 | } |
| 1238 | else { |
| 1239 | while (xP < xPEnd) { |
| 1240 | *xP = xP->real() * scale; |
| 1241 | xP++; |
| 1242 | } |
| 1243 | } |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 1244 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /** in-place conjugation */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1248 | static void conjugateVector(signalVector &x) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1249 | { |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 1250 | if (x.isReal()) return; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1251 | signalVector::iterator xP = x.begin(); |
| 1252 | signalVector::iterator xPEnd = x.end(); |
| 1253 | while (xP < xPEnd) { |
| 1254 | *xP = xP->conj(); |
| 1255 | xP++; |
| 1256 | } |
| 1257 | } |
| 1258 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1259 | static bool generateMidamble(int sps, int tsc) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1260 | { |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1261 | bool status = true; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1262 | float toa; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1263 | complex *data = NULL; |
| 1264 | signalVector *autocorr = NULL, *midamble = NULL; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1265 | signalVector *midMidamble = NULL, *_midMidamble = NULL; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1266 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1267 | if ((tsc < 0) || (tsc > 7)) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1268 | return false; |
| 1269 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1270 | delete gMidambles[tsc]; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1271 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1272 | /* Use middle 16 bits of each TSC. Correlation sequence is not pulse shaped */ |
| 1273 | midMidamble = modulateBurst(gTrainingSequence[tsc].segment(5,16), 0, sps, true); |
| 1274 | if (!midMidamble) |
| 1275 | return false; |
| 1276 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1277 | /* Simulated receive sequence is pulse shaped */ |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1278 | midamble = modulateBurst(gTrainingSequence[tsc], 0, sps, false); |
| 1279 | if (!midamble) { |
| 1280 | status = false; |
| 1281 | goto release; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1282 | } |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1283 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1284 | // NOTE: Because ideal TSC 16-bit midamble is 66 symbols into burst, |
| 1285 | // the ideal TSC has an + 180 degree phase shift, |
| 1286 | // due to the pi/2 frequency shift, that |
| 1287 | // needs to be accounted for. |
| 1288 | // 26-midamble is 61 symbols into burst, has +90 degree phase shift. |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1289 | scaleVector(*midMidamble, complex(-1.0, 0.0)); |
| 1290 | scaleVector(*midamble, complex(0.0, 1.0)); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1291 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1292 | conjugateVector(*midMidamble); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1293 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1294 | /* For SSE alignment, reallocate the midamble sequence on 16-byte boundary */ |
| 1295 | data = (complex *) convolve_h_alloc(midMidamble->size()); |
| 1296 | _midMidamble = new signalVector(data, 0, midMidamble->size()); |
| 1297 | _midMidamble->setAligned(true); |
| 1298 | memcpy(_midMidamble->begin(), midMidamble->begin(), |
| 1299 | midMidamble->size() * sizeof(complex)); |
| 1300 | |
| 1301 | autocorr = convolve(midamble, _midMidamble, NULL, NO_DELAY); |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1302 | if (!autocorr) { |
| 1303 | status = false; |
| 1304 | goto release; |
| 1305 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1306 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1307 | gMidambles[tsc] = new CorrelationSequence; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1308 | gMidambles[tsc]->buffer = data; |
| 1309 | gMidambles[tsc]->sequence = _midMidamble; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1310 | gMidambles[tsc]->gain = peakDetect(*autocorr, &toa, NULL); |
| 1311 | |
| 1312 | /* For 1 sps only |
| 1313 | * (Half of correlation length - 1) + midpoint of pulse shape + remainder |
| 1314 | * 13.5 = (16 / 2 - 1) + 1.5 + (26 - 10) / 2 |
| 1315 | */ |
| 1316 | if (sps == 1) |
| 1317 | gMidambles[tsc]->toa = toa - 13.5; |
| 1318 | else |
| 1319 | gMidambles[tsc]->toa = 0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1320 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1321 | release: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1322 | delete autocorr; |
| 1323 | delete midamble; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1324 | delete midMidamble; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1325 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1326 | if (!status) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1327 | delete _midMidamble; |
| 1328 | free(data); |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1329 | gMidambles[tsc] = NULL; |
| 1330 | } |
| 1331 | |
| 1332 | return status; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1335 | static CorrelationSequence *generateEdgeMidamble(int tsc) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1336 | { |
| 1337 | complex *data = NULL; |
| 1338 | signalVector *midamble = NULL, *_midamble = NULL; |
| 1339 | CorrelationSequence *seq; |
| 1340 | |
| 1341 | if ((tsc < 0) || (tsc > 7)) |
| 1342 | return NULL; |
| 1343 | |
| 1344 | /* Use middle 48 bits of each TSC. Correlation sequence is not pulse shaped */ |
| 1345 | const BitVector *bits = &gEdgeTrainingSequence[tsc]; |
| 1346 | midamble = modulateEdgeBurst(bits->segment(15, 48), 1, true); |
| 1347 | if (!midamble) |
| 1348 | return NULL; |
| 1349 | |
| 1350 | conjugateVector(*midamble); |
| 1351 | |
| 1352 | data = (complex *) convolve_h_alloc(midamble->size()); |
| 1353 | _midamble = new signalVector(data, 0, midamble->size()); |
| 1354 | _midamble->setAligned(true); |
| 1355 | memcpy(_midamble->begin(), midamble->begin(), |
| 1356 | midamble->size() * sizeof(complex)); |
| 1357 | |
| 1358 | /* Channel gain is an empirically measured value */ |
| 1359 | seq = new CorrelationSequence; |
| 1360 | seq->buffer = data; |
| 1361 | seq->sequence = _midamble; |
| 1362 | seq->gain = Complex<float>(-19.6432, 19.5006) / 1.18; |
| 1363 | seq->toa = 0; |
| 1364 | |
| 1365 | delete midamble; |
| 1366 | |
| 1367 | return seq; |
| 1368 | } |
| 1369 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1370 | static bool generateRACHSequence(int sps) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1371 | { |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1372 | bool status = true; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1373 | float toa; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1374 | complex *data = NULL; |
| 1375 | signalVector *autocorr = NULL; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1376 | signalVector *seq0 = NULL, *seq1 = NULL, *_seq1 = NULL; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1377 | |
| 1378 | delete gRACHSequence; |
| 1379 | |
| 1380 | seq0 = modulateBurst(gRACHSynchSequence, 0, sps, false); |
| 1381 | if (!seq0) |
| 1382 | return false; |
| 1383 | |
| 1384 | seq1 = modulateBurst(gRACHSynchSequence.segment(0, 40), 0, sps, true); |
| 1385 | if (!seq1) { |
| 1386 | status = false; |
| 1387 | goto release; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1390 | conjugateVector(*seq1); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1391 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1392 | /* For SSE alignment, reallocate the midamble sequence on 16-byte boundary */ |
| 1393 | data = (complex *) convolve_h_alloc(seq1->size()); |
| 1394 | _seq1 = new signalVector(data, 0, seq1->size()); |
| 1395 | _seq1->setAligned(true); |
| 1396 | memcpy(_seq1->begin(), seq1->begin(), seq1->size() * sizeof(complex)); |
| 1397 | |
| 1398 | autocorr = convolve(seq0, _seq1, autocorr, NO_DELAY); |
| 1399 | if (!autocorr) { |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1400 | status = false; |
| 1401 | goto release; |
| 1402 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1403 | |
| 1404 | gRACHSequence = new CorrelationSequence; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1405 | gRACHSequence->sequence = _seq1; |
| 1406 | gRACHSequence->buffer = data; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1407 | gRACHSequence->gain = peakDetect(*autocorr, &toa, NULL); |
| 1408 | |
| 1409 | /* For 1 sps only |
| 1410 | * (Half of correlation length - 1) + midpoint of pulse shaping filer |
| 1411 | * 20.5 = (40 / 2 - 1) + 1.5 |
| 1412 | */ |
| 1413 | if (sps == 1) |
| 1414 | gRACHSequence->toa = toa - 20.5; |
| 1415 | else |
| 1416 | gRACHSequence->toa = 0.0; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1417 | |
| 1418 | release: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1419 | delete autocorr; |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1420 | delete seq0; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1421 | delete seq1; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1422 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1423 | if (!status) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1424 | delete _seq1; |
| 1425 | free(data); |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1426 | gRACHSequence = NULL; |
| 1427 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1428 | |
Thomas Tsou | e5dcfc4 | 2013-08-20 16:27:12 -0400 | [diff] [blame] | 1429 | return status; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1430 | } |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1431 | |
Tom Tsou | a84e162 | 2016-06-29 14:50:25 -0700 | [diff] [blame] | 1432 | /* |
| 1433 | * Peak-to-average computation +/- range from peak in symbols |
| 1434 | */ |
| 1435 | #define COMPUTE_PEAK_MIN 2 |
| 1436 | #define COMPUTE_PEAK_MAX 5 |
| 1437 | |
| 1438 | /* |
| 1439 | * Minimum number of values needed to compute peak-to-average |
| 1440 | */ |
| 1441 | #define COMPUTE_PEAK_CNT 5 |
| 1442 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1443 | static float computePeakRatio(signalVector *corr, |
| 1444 | int sps, float toa, complex amp) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1445 | { |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1446 | int num = 0; |
| 1447 | complex *peak; |
| 1448 | float rms, avg = 0.0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1449 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1450 | /* Check for bogus results */ |
| 1451 | if ((toa < 0.0) || (toa > corr->size())) |
| 1452 | return 0.0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1453 | |
Alexander Chemeris | 1e9b4d5 | 2015-06-04 19:05:28 -0400 | [diff] [blame] | 1454 | peak = corr->begin() + (int) rint(toa); |
| 1455 | |
Tom Tsou | a84e162 | 2016-06-29 14:50:25 -0700 | [diff] [blame] | 1456 | for (int i = COMPUTE_PEAK_MIN * sps; i <= COMPUTE_PEAK_MAX * sps; i++) { |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1457 | if (peak - i >= corr->begin()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1458 | avg += (peak - i)->norm2(); |
| 1459 | num++; |
| 1460 | } |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1461 | if (peak + i < corr->end()) { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1462 | avg += (peak + i)->norm2(); |
| 1463 | num++; |
| 1464 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Tom Tsou | a84e162 | 2016-06-29 14:50:25 -0700 | [diff] [blame] | 1467 | if (num < COMPUTE_PEAK_CNT) |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1468 | return 0.0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1469 | |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1470 | rms = sqrtf(avg / (float) num) + 0.00001; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1471 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1472 | return (amp.abs()) / rms; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1475 | float energyDetect(const signalVector &rxBurst, unsigned windowLength) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1476 | { |
| 1477 | |
| 1478 | signalVector::const_iterator windowItr = rxBurst.begin(); //+rxBurst.size()/2 - 5*windowLength/2; |
| 1479 | float energy = 0.0; |
Tom Tsou | 2af1440 | 2017-03-23 14:54:00 -0700 | [diff] [blame] | 1480 | if (windowLength == 0) return 0.0; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1481 | if (windowLength > rxBurst.size()) windowLength = rxBurst.size(); |
| 1482 | for (unsigned i = 0; i < windowLength; i++) { |
| 1483 | energy += windowItr->norm2(); |
| 1484 | windowItr+=4; |
| 1485 | } |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 1486 | return energy/windowLength; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1487 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1488 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1489 | static signalVector *downsampleBurst(const signalVector &burst) |
| 1490 | { |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 1491 | signalVector in(DOWNSAMPLE_IN_LEN, dnsampler->len()); |
| 1492 | signalVector *out = new signalVector(DOWNSAMPLE_OUT_LEN); |
| 1493 | memcpy(in.begin(), burst.begin(), DOWNSAMPLE_IN_LEN * 2 * sizeof(float)); |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1494 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 1495 | if (dnsampler->rotate((float *) in.begin(), DOWNSAMPLE_IN_LEN, |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1496 | (float *) out->begin(), DOWNSAMPLE_OUT_LEN) < 0) { |
| 1497 | delete out; |
| 1498 | out = NULL; |
| 1499 | } |
| 1500 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1501 | return out; |
| 1502 | }; |
| 1503 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1504 | /* |
| 1505 | * Detect a burst based on correlation and peak-to-average ratio |
| 1506 | * |
| 1507 | * For one sampler-per-symbol, perform fast peak detection (no interpolation) |
| 1508 | * for initial gating. We do this because energy detection should be disabled. |
| 1509 | * For higher oversampling values, we assume the energy detector is in place |
| 1510 | * and we run full interpolating peak detection. |
| 1511 | */ |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1512 | static int detectBurst(const signalVector &burst, |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1513 | signalVector &corr, CorrelationSequence *sync, |
| 1514 | float thresh, int sps, complex *amp, float *toa, |
| 1515 | int start, int len) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1516 | { |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1517 | const signalVector *corr_in; |
| 1518 | signalVector *dec = NULL; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1519 | |
| 1520 | if (sps == 4) { |
| 1521 | dec = downsampleBurst(burst); |
| 1522 | corr_in = dec; |
| 1523 | sps = 1; |
| 1524 | } else { |
| 1525 | corr_in = &burst; |
| 1526 | } |
| 1527 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1528 | /* Correlate */ |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1529 | if (!convolve(corr_in, sync->sequence, &corr, |
| 1530 | CUSTOM, start, len, 1, 0)) { |
| 1531 | delete dec; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1532 | return -1; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1535 | delete dec; |
| 1536 | |
| 1537 | /* Running at the downsampled rate at this point */ |
| 1538 | sps = 1; |
| 1539 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1540 | /* Peak detection - place restrictions at correlation edges */ |
| 1541 | *amp = fastPeakDetect(corr, toa); |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1542 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1543 | if ((*toa < 3 * sps) || (*toa > len - 3 * sps)) |
| 1544 | return 0; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1545 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1546 | /* Peak -to-average ratio */ |
| 1547 | if (computePeakRatio(&corr, sps, *toa, *amp) < thresh) |
| 1548 | return 0; |
| 1549 | |
| 1550 | /* Compute peak-to-average ratio. Reject if we don't have enough values */ |
| 1551 | *amp = peakDetect(corr, toa, NULL); |
| 1552 | |
| 1553 | /* Normalize our channel gain */ |
| 1554 | *amp = *amp / sync->gain; |
| 1555 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1556 | /* Compensate for residuate time lag */ |
| 1557 | *toa = *toa - sync->toa; |
| 1558 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1559 | return 1; |
| 1560 | } |
| 1561 | |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1562 | static float maxAmplitude(const signalVector &burst) |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1563 | { |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 1564 | float max = 0.0; |
| 1565 | for (size_t i = 0; i < burst.size(); i++) { |
| 1566 | if (fabs(burst[i].real()) > max) |
| 1567 | max = fabs(burst[i].real()); |
| 1568 | if (fabs(burst[i].imag()) > max) |
| 1569 | max = fabs(burst[i].imag()); |
| 1570 | } |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1571 | |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 1572 | return max; |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1575 | /* |
| 1576 | * RACH/Normal burst detection with clipping detection |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1577 | * |
| 1578 | * Correlation window parameters: |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1579 | * target: Tail bits + burst length |
| 1580 | * head: Search symbols before target |
| 1581 | * tail: Search symbols after target |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1582 | */ |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1583 | static int detectGeneralBurst(const signalVector &rxBurst, |
| 1584 | float thresh, |
| 1585 | int sps, |
| 1586 | complex &, |
| 1587 | float &toa, |
| 1588 | int target, int head, int tail, |
| 1589 | CorrelationSequence *sync) |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1590 | { |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1591 | int rc, start, len; |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 1592 | bool clipping = false; |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1593 | |
| 1594 | if ((sps != 1) && (sps != 4)) |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1595 | return -SIGERR_UNSUPPORTED; |
| 1596 | |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 1597 | // Detect potential clipping |
| 1598 | // We still may be able to demod the burst, so we'll give it a try |
| 1599 | // and only report clipping if we can't demod. |
| 1600 | float maxAmpl = maxAmplitude(rxBurst); |
| 1601 | if (maxAmpl > CLIP_THRESH) { |
| 1602 | LOG(DEBUG) << "max burst amplitude: " << maxAmpl << " is above the clipping threshold: " << CLIP_THRESH << std::endl; |
| 1603 | clipping = true; |
| 1604 | } |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1605 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1606 | start = target - head - 1; |
| 1607 | len = head + tail; |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 1608 | signalVector corr(len); |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1609 | |
Tom Tsou | 7278a87 | 2017-06-14 14:50:39 -0700 | [diff] [blame^] | 1610 | rc = detectBurst(rxBurst, corr, sync, |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1611 | thresh, sps, &, &toa, start, len); |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1612 | if (rc < 0) { |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1613 | return -SIGERR_INTERNAL; |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1614 | } else if (!rc) { |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1615 | amp = 0.0f; |
| 1616 | toa = 0.0f; |
Alexander Chemeris | 954b118 | 2015-06-04 15:39:41 -0400 | [diff] [blame] | 1617 | return clipping?-SIGERR_CLIP:SIGERR_NONE; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1620 | /* Subtract forward search bits from delay */ |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1621 | toa -= head; |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1622 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1623 | return 1; |
| 1624 | } |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 1625 | |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1626 | |
| 1627 | /* |
| 1628 | * RACH burst detection |
| 1629 | * |
| 1630 | * Correlation window parameters: |
| 1631 | * target: Tail bits + RACH length (reduced from 41 to a multiple of 4) |
Tom Tsou | e90c24c | 2016-06-21 16:14:39 -0700 | [diff] [blame] | 1632 | * head: Search 8 symbols before target |
| 1633 | * tail: Search 8 symbols + maximum expected delay |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1634 | */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1635 | static int detectRACHBurst(const signalVector &burst, float threshold, int sps, |
| 1636 | complex &litude, float &toa, unsigned max_toa) |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1637 | { |
| 1638 | int rc, target, head, tail; |
| 1639 | CorrelationSequence *sync; |
| 1640 | |
| 1641 | target = 8 + 40; |
Tom Tsou | e90c24c | 2016-06-21 16:14:39 -0700 | [diff] [blame] | 1642 | head = 8; |
Alexander Chemeris | 14d13b6 | 2017-03-17 15:12:17 -0700 | [diff] [blame] | 1643 | tail = 8 + max_toa; |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1644 | sync = gRACHSequence; |
| 1645 | |
Alexander Chemeris | 14d13b6 | 2017-03-17 15:12:17 -0700 | [diff] [blame] | 1646 | rc = detectGeneralBurst(burst, threshold, sps, amplitude, toa, |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1647 | target, head, tail, sync); |
| 1648 | |
| 1649 | return rc; |
| 1650 | } |
| 1651 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1652 | /* |
| 1653 | * Normal burst detection |
| 1654 | * |
| 1655 | * Correlation window parameters: |
| 1656 | * target: Tail + data + mid-midamble + 1/2 remaining midamblebits |
Tom Tsou | e90c24c | 2016-06-21 16:14:39 -0700 | [diff] [blame] | 1657 | * head: Search 6 symbols before target |
| 1658 | * tail: Search 6 symbols + maximum expected delay |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1659 | */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1660 | static int analyzeTrafficBurst(const signalVector &burst, unsigned tsc, float threshold, |
| 1661 | int sps, complex &litude, float &toa, unsigned max_toa) |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1662 | { |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1663 | int rc, target, head, tail; |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1664 | CorrelationSequence *sync; |
| 1665 | |
Tom Tsou | ae91f13 | 2017-03-28 14:40:38 -0700 | [diff] [blame] | 1666 | if (tsc > 7) |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 1667 | return -SIGERR_UNSUPPORTED; |
| 1668 | |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1669 | target = 3 + 58 + 16 + 5; |
Tom Tsou | e90c24c | 2016-06-21 16:14:39 -0700 | [diff] [blame] | 1670 | head = 6; |
| 1671 | tail = 6 + max_toa; |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1672 | sync = gMidambles[tsc]; |
Thomas Tsou | 865bca4 | 2013-08-21 20:58:00 -0400 | [diff] [blame] | 1673 | |
Alexander Chemeris | 14d13b6 | 2017-03-17 15:12:17 -0700 | [diff] [blame] | 1674 | rc = detectGeneralBurst(burst, threshold, sps, amplitude, toa, |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1675 | target, head, tail, sync); |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 1676 | return rc; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1679 | static int detectEdgeBurst(const signalVector &burst, unsigned tsc, float threshold, |
| 1680 | int sps, complex &litude, float &toa, unsigned max_toa) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1681 | { |
| 1682 | int rc, target, head, tail; |
| 1683 | CorrelationSequence *sync; |
| 1684 | |
Tom Tsou | ae91f13 | 2017-03-28 14:40:38 -0700 | [diff] [blame] | 1685 | if (tsc > 7) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1686 | return -SIGERR_UNSUPPORTED; |
| 1687 | |
| 1688 | target = 3 + 58 + 16 + 5; |
Tom Tsou | e90c24c | 2016-06-21 16:14:39 -0700 | [diff] [blame] | 1689 | head = 6; |
| 1690 | tail = 6 + max_toa; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1691 | sync = gEdgeMidambles[tsc]; |
| 1692 | |
Alexander Chemeris | 14d13b6 | 2017-03-17 15:12:17 -0700 | [diff] [blame] | 1693 | rc = detectGeneralBurst(burst, threshold, sps, amplitude, toa, |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1694 | target, head, tail, sync); |
| 1695 | return rc; |
| 1696 | } |
| 1697 | |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 1698 | int detectAnyBurst(const signalVector &burst, unsigned tsc, float threshold, |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 1699 | int sps, CorrType type, complex &, float &toa, |
| 1700 | unsigned max_toa) |
| 1701 | { |
| 1702 | int rc = 0; |
| 1703 | |
| 1704 | switch (type) { |
| 1705 | case EDGE: |
| 1706 | rc = detectEdgeBurst(burst, tsc, threshold, sps, |
| 1707 | amp, toa, max_toa); |
| 1708 | if (rc > 0) |
| 1709 | break; |
| 1710 | else |
| 1711 | type = TSC; |
| 1712 | case TSC: |
| 1713 | rc = analyzeTrafficBurst(burst, tsc, threshold, sps, |
| 1714 | amp, toa, max_toa); |
| 1715 | break; |
| 1716 | case RACH: |
| 1717 | rc = detectRACHBurst(burst, threshold, sps, amp, toa, |
| 1718 | max_toa); |
| 1719 | break; |
| 1720 | default: |
| 1721 | LOG(ERR) << "Invalid correlation type"; |
| 1722 | } |
| 1723 | |
| 1724 | if (rc > 0) |
| 1725 | return type; |
| 1726 | |
| 1727 | return rc; |
| 1728 | } |
| 1729 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1730 | /* |
| 1731 | * Soft 8-PSK decoding using Manhattan distance metric |
| 1732 | */ |
| 1733 | static SoftVector *softSliceEdgeBurst(signalVector &burst) |
| 1734 | { |
| 1735 | size_t nsyms = 148; |
| 1736 | |
| 1737 | if (burst.size() < nsyms) |
| 1738 | return NULL; |
| 1739 | |
| 1740 | signalVector::iterator itr; |
| 1741 | SoftVector *bits = new SoftVector(nsyms * 3); |
| 1742 | |
| 1743 | /* |
| 1744 | * Bits 0 and 1 - First and second bits of the symbol respectively |
| 1745 | */ |
| 1746 | rotateBurst2(burst, -M_PI / 8.0); |
| 1747 | itr = burst.begin(); |
| 1748 | for (size_t i = 0; i < nsyms; i++) { |
| 1749 | (*bits)[3 * i + 0] = -itr->imag(); |
| 1750 | (*bits)[3 * i + 1] = itr->real(); |
| 1751 | itr++; |
| 1752 | } |
| 1753 | |
| 1754 | /* |
| 1755 | * Bit 2 - Collapse symbols into quadrant 0 (positive X and Y). |
| 1756 | * Decision area is then simplified to X=Y axis. Rotate again to |
| 1757 | * place decision boundary on X-axis. |
| 1758 | */ |
| 1759 | itr = burst.begin(); |
| 1760 | for (size_t i = 0; i < burst.size(); i++) { |
| 1761 | burst[i] = Complex<float>(fabs(itr->real()), fabs(itr->imag())); |
| 1762 | itr++; |
| 1763 | } |
| 1764 | |
| 1765 | rotateBurst2(burst, -M_PI / 4.0); |
| 1766 | itr = burst.begin(); |
| 1767 | for (size_t i = 0; i < nsyms; i++) { |
| 1768 | (*bits)[3 * i + 2] = -itr->imag(); |
| 1769 | itr++; |
| 1770 | } |
| 1771 | |
| 1772 | signalVector soft(bits->size()); |
| 1773 | for (size_t i = 0; i < bits->size(); i++) |
| 1774 | soft[i] = (*bits)[i]; |
| 1775 | |
| 1776 | return bits; |
| 1777 | } |
| 1778 | |
| 1779 | /* |
Alexander Chemeris | 132fb24 | 2017-03-17 17:22:33 -0700 | [diff] [blame] | 1780 | * Convert signalVector to SoftVector by taking real part of the signal. |
| 1781 | */ |
| 1782 | static SoftVector *signalToSoftVector(signalVector *dec) |
| 1783 | { |
| 1784 | SoftVector *bits = new SoftVector(dec->size()); |
| 1785 | |
| 1786 | SoftVector::iterator bit_itr = bits->begin(); |
| 1787 | signalVector::iterator burst_itr = dec->begin(); |
| 1788 | |
| 1789 | for (; burst_itr < dec->end(); burst_itr++) |
| 1790 | *bit_itr++ = burst_itr->real(); |
| 1791 | |
| 1792 | return bits; |
| 1793 | } |
| 1794 | |
| 1795 | /* |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1796 | * Shared portion of GMSK and EDGE demodulators consisting of timing |
| 1797 | * recovery and single tap channel correction. For 4 SPS (if activated), |
| 1798 | * the output is downsampled prior to the 1 SPS modulation specific |
| 1799 | * stages. |
| 1800 | */ |
Alexander Chemeris | e0c1218 | 2017-03-18 13:27:48 -0700 | [diff] [blame] | 1801 | static signalVector *demodCommon(const signalVector &burst, int sps, |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1802 | complex chan, float toa) |
| 1803 | { |
| 1804 | signalVector *delay, *dec; |
| 1805 | |
| 1806 | if ((sps != 1) && (sps != 4)) |
| 1807 | return NULL; |
| 1808 | |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1809 | delay = delayVector(&burst, NULL, -toa * (float) sps); |
Alexander Chemeris | e0c1218 | 2017-03-18 13:27:48 -0700 | [diff] [blame] | 1810 | scaleVector(*delay, (complex) 1.0 / chan); |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1811 | |
| 1812 | if (sps == 1) |
| 1813 | return delay; |
| 1814 | |
| 1815 | dec = downsampleBurst(*delay); |
| 1816 | |
| 1817 | delete delay; |
| 1818 | return dec; |
| 1819 | } |
| 1820 | |
| 1821 | /* |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1822 | * Demodulate GSMK burst. Prior to symbol rotation, operate at |
| 1823 | * 4 SPS (if activated) to minimize distortion through the fractional |
| 1824 | * delay filters. Symbol rotation and after always operates at 1 SPS. |
| 1825 | */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1826 | static SoftVector *demodGmskBurst(const signalVector &rxBurst, |
| 1827 | int sps, complex channel, float TOA) |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1828 | { |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1829 | SoftVector *bits; |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1830 | signalVector *dec; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1831 | |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1832 | dec = demodCommon(rxBurst, sps, channel, TOA); |
| 1833 | if (!dec) |
| 1834 | return NULL; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1835 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1836 | /* Shift up by a quarter of a frequency */ |
| 1837 | GMSKReverseRotate(*dec, 1); |
Alexander Chemeris | 132fb24 | 2017-03-17 17:22:33 -0700 | [diff] [blame] | 1838 | /* Take real part of the signal */ |
| 1839 | bits = signalToSoftVector(dec); |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1840 | delete dec; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1841 | |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1842 | return bits; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1843 | } |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 1844 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1845 | /* |
| 1846 | * Demodulate an 8-PSK burst. Prior to symbol rotation, operate at |
| 1847 | * 4 SPS (if activated) to minimize distortion through the fractional |
| 1848 | * delay filters. Symbol rotation and after always operates at 1 SPS. |
| 1849 | * |
| 1850 | * Allow 1 SPS demodulation here, but note that other parts of the |
| 1851 | * transceiver restrict EDGE operatoin to 4 SPS - 8-PSK distortion |
| 1852 | * through the fractional delay filters at 1 SPS renders signal |
| 1853 | * nearly unrecoverable. |
| 1854 | */ |
Tom Tsou | 70134a0 | 2017-06-12 14:23:53 -0700 | [diff] [blame] | 1855 | static SoftVector *demodEdgeBurst(const signalVector &burst, |
| 1856 | int sps, complex chan, float toa) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1857 | { |
| 1858 | SoftVector *bits; |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1859 | signalVector *dec, *rot, *eq; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1860 | |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1861 | dec = demodCommon(burst, sps, chan, toa); |
| 1862 | if (!dec) |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1863 | return NULL; |
| 1864 | |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1865 | /* Equalize and derotate */ |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1866 | eq = convolve(dec, GSMPulse4->c0_inv, NULL, NO_DELAY); |
| 1867 | rot = derotateEdgeBurst(*eq, 1); |
| 1868 | |
Tom Tsou | 7fec303 | 2016-03-06 22:33:20 -0800 | [diff] [blame] | 1869 | /* Soft slice and normalize */ |
Tom Tsou | 0479562 | 2016-04-26 21:17:36 -0700 | [diff] [blame] | 1870 | bits = softSliceEdgeBurst(*rot); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1871 | |
| 1872 | delete dec; |
| 1873 | delete eq; |
| 1874 | delete rot; |
| 1875 | |
| 1876 | return bits; |
| 1877 | } |
| 1878 | |
Alexander Chemeris | e0c1218 | 2017-03-18 13:27:48 -0700 | [diff] [blame] | 1879 | SoftVector *demodAnyBurst(const signalVector &burst, int sps, complex amp, |
Alexander Chemeris | 6e1dffd | 2017-03-17 16:13:51 -0700 | [diff] [blame] | 1880 | float toa, CorrType type) |
| 1881 | { |
| 1882 | if (type == EDGE) |
| 1883 | return demodEdgeBurst(burst, sps, amp, toa); |
| 1884 | else |
| 1885 | return demodGmskBurst(burst, sps, amp, toa); |
| 1886 | } |
| 1887 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1888 | bool sigProcLibSetup() |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1889 | { |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1890 | initTrigTables(); |
Thomas Tsou | 0e0e1f4 | 2013-11-09 22:08:51 -0500 | [diff] [blame] | 1891 | generateSincTable(); |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1892 | initGMSKRotationTables(); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1893 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1894 | GSMPulse1 = generateGSMPulse(1); |
| 1895 | GSMPulse4 = generateGSMPulse(4); |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1896 | |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1897 | generateRACHSequence(1); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1898 | for (int tsc = 0; tsc < 8; tsc++) { |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 1899 | generateMidamble(1, tsc); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1900 | gEdgeMidambles[tsc] = generateEdgeMidamble(tsc); |
| 1901 | } |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1902 | |
Thomas Tsou | f79c4d0 | 2013-11-09 15:51:56 -0600 | [diff] [blame] | 1903 | generateDelayFilters(); |
| 1904 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1905 | dnsampler = new Resampler(1, 4); |
| 1906 | if (!dnsampler->init()) { |
| 1907 | LOG(ALERT) << "Rx resampler failed to initialize"; |
| 1908 | goto fail; |
| 1909 | } |
| 1910 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1911 | return true; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 1912 | |
| 1913 | fail: |
| 1914 | sigProcLibDestroy(); |
| 1915 | return false; |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 1916 | } |