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