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