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