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