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