dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Free Software Foundation, Inc. |
| 3 | * |
Martin Hauke | 066fd04 | 2019-10-13 19:08:00 +0200 | [diff] [blame^] | 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribution. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 5 | * |
| 6 | * This use of this software may be subject to additional restrictions. |
| 7 | * See the LEGAL file in the main directory for details. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | |
| 13 | */ |
| 14 | |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 15 | #ifndef SIGPROCLIB_H |
| 16 | #define SIGPROCLIB_H |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 17 | |
| 18 | #include "Vector.h" |
| 19 | #include "Complex.h" |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 20 | #include "BitVector.h" |
Thomas Tsou | 20eb6d6 | 2013-11-09 14:30:41 -0500 | [diff] [blame] | 21 | #include "signalVector.h" |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 22 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 23 | /* Burst lengths */ |
Alexander Chemeris | 0229d22 | 2017-03-17 16:03:17 -0700 | [diff] [blame] | 24 | #define NORMAL_BURST_NBITS 148 |
| 25 | #define EDGE_BURST_NBITS 444 |
| 26 | #define EDGE_BURST_NSYMS (EDGE_BURST_NBITS / 3) |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 27 | |
Alexander Chemeris | f9e78be | 2017-03-17 15:00:34 -0700 | [diff] [blame] | 28 | /** Codes for burst types of received bursts*/ |
| 29 | enum CorrType{ |
| 30 | OFF, ///< timeslot is off |
| 31 | TSC, ///< timeslot should contain a normal burst |
Vadim Yanitskiy | 444ff34 | 2018-10-22 02:25:23 +0200 | [diff] [blame] | 32 | EXT_RACH, ///< timeslot should contain an extended access burst |
Alexander Chemeris | f9e78be | 2017-03-17 15:00:34 -0700 | [diff] [blame] | 33 | RACH, ///< timeslot should contain an access burst |
| 34 | EDGE, ///< timeslot should contain an EDGE burst |
| 35 | IDLE ///< timeslot is an idle (or dummy) burst |
| 36 | }; |
| 37 | |
Alexander Chemeris | 4aa548f | 2017-03-17 15:23:06 -0700 | [diff] [blame] | 38 | enum SignalError { |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 39 | SIGERR_NONE, |
| 40 | SIGERR_BOUNDS, |
| 41 | SIGERR_CLIP, |
| 42 | SIGERR_UNSUPPORTED, |
| 43 | SIGERR_INTERNAL, |
| 44 | }; |
| 45 | |
Alexander Chemeris | b34e60c | 2017-03-17 15:29:09 -0700 | [diff] [blame] | 46 | /* |
| 47 | * Burst detection threshold |
| 48 | * |
| 49 | * Decision threshold value for burst gating on peak-to-average value of |
| 50 | * correlated synchronization sequences. Lower values pass more bursts up |
| 51 | * to upper layers but will increase the false detection rate. |
| 52 | */ |
| 53 | #define BURST_THRESH 4.0 |
| 54 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 55 | /** Setup the signal processing library */ |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 56 | bool sigProcLibSetup(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 57 | |
| 58 | /** Destroy the signal processing library */ |
| 59 | void sigProcLibDestroy(void); |
| 60 | |
Alexander Chemeris | 132fb24 | 2017-03-17 17:22:33 -0700 | [diff] [blame] | 61 | /** Operate soft slicer on a soft-bit vector */ |
Pau Espin Pedrol | 7dc07b9 | 2019-07-01 17:55:01 +0200 | [diff] [blame] | 62 | void vectorSlicer(float *dest, const float *src, size_t len); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 63 | |
| 64 | /** GMSK modulate a GSM burst of bits */ |
| 65 | signalVector *modulateBurst(const BitVector &wBurst, |
Alexander Chemeris | 0229d22 | 2017-03-17 16:03:17 -0700 | [diff] [blame] | 66 | int guardPeriodLength, |
| 67 | int sps, bool emptyPulse = false); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 68 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 69 | /** 8-PSK modulate a burst of bits */ |
| 70 | signalVector *modulateEdgeBurst(const BitVector &bits, |
| 71 | int sps, bool emptyPulse = false); |
| 72 | |
| 73 | /** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */ |
| 74 | signalVector *generateEdgeBurst(int tsc); |
| 75 | |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 76 | /** Generate an empty burst - 4 or 1 SPS */ |
| 77 | signalVector *generateEmptyBurst(int sps, int tn); |
| 78 | |
| 79 | /** Generate a normal GSM burst with random payload - 4 or 1 SPS */ |
| 80 | signalVector *genRandNormalBurst(int tsc, int sps, int tn); |
| 81 | |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 82 | /** Generate an access GSM burst with random payload - 4 or 1 SPS */ |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 83 | signalVector *genRandAccessBurst(int delay, int sps, int tn); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 84 | |
Tom Tsou | 8ee2f38 | 2016-03-06 20:57:34 -0800 | [diff] [blame] | 85 | /** Generate a dummy GSM burst - 4 or 1 SPS */ |
| 86 | signalVector *generateDummyBurst(int sps, int tn); |
| 87 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 88 | /** |
| 89 | Apply a scalar to a vector. |
| 90 | @param x The vector of interest. |
| 91 | @param scale The scalar. |
| 92 | */ |
| 93 | void scaleVector(signalVector &x, |
Alexander Chemeris | 0229d22 | 2017-03-17 16:03:17 -0700 | [diff] [blame] | 94 | complex scale); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 95 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 96 | /** |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 97 | Rough energy estimator. |
| 98 | @param rxBurst A GSM burst. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 99 | @param windowLength The number of burst samples used to compute burst energy |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 100 | @return The average power of the received burst. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 101 | */ |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 102 | float energyDetect(const signalVector &rxBurst, |
Alexander Chemeris | 1dd05cf | 2017-03-15 23:23:36 +0300 | [diff] [blame] | 103 | unsigned windowLength); |
Pau Espin Pedrol | 7ee2d10 | 2019-07-04 13:02:12 +0200 | [diff] [blame] | 104 | |
| 105 | /** Struct used to fill out parameters in detectAnyBurst(): estimated burst parameters |
| 106 | @param amplitude The estimated amplitude of received TSC burst. |
| 107 | @param toa The estimated time-of-arrival of received TSC burst (in symbols). |
Pau Espin Pedrol | c3d68c1 | 2019-07-04 16:27:47 +0200 | [diff] [blame] | 108 | @param tsc The TSC used to detect the burst. |
Pau Espin Pedrol | 7ee2d10 | 2019-07-04 13:02:12 +0200 | [diff] [blame] | 109 | */ |
| 110 | struct estim_burst_params { |
| 111 | complex amp; |
| 112 | float toa; |
Pau Espin Pedrol | c3d68c1 | 2019-07-04 16:27:47 +0200 | [diff] [blame] | 113 | uint8_t tsc; |
Sylvain Munaut | b49a42e | 2019-05-14 18:23:29 +0200 | [diff] [blame] | 114 | float ci; |
Pau Espin Pedrol | 7ee2d10 | 2019-07-04 13:02:12 +0200 | [diff] [blame] | 115 | }; |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame] | 116 | /** |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 117 | 8-PSK/GMSK/RACH burst detector |
| 118 | @param burst The received GSM burst of interest |
| 119 | @param tsc Midamble type (0..7) also known as TSC |
| 120 | @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. |
| 121 | @param sps The number of samples per GSM symbol. |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 122 | @param max_toa The maximum expected time-of-arrival (in symbols). |
Pau Espin Pedrol | 7ee2d10 | 2019-07-04 13:02:12 +0200 | [diff] [blame] | 123 | @param ebp The estimated parameters of the detected burst. |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 124 | @return positive value (CorrType) if threshold value is reached, |
| 125 | negative value (-SignalError) on error, |
| 126 | zero (SIGERR_NONE) if no burst is detected |
| 127 | */ |
Alexander Chemeris | 1470fcd | 2017-03-17 22:35:02 -0700 | [diff] [blame] | 128 | int detectAnyBurst(const signalVector &burst, |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 129 | unsigned tsc, |
| 130 | float threshold, |
| 131 | int sps, |
| 132 | CorrType type, |
Pau Espin Pedrol | 7ee2d10 | 2019-07-04 13:02:12 +0200 | [diff] [blame] | 133 | unsigned max_toa, |
| 134 | struct estim_burst_params *ebp); |
Alexander Chemeris | 4e6c938 | 2017-03-17 15:24:18 -0700 | [diff] [blame] | 135 | |
Alexander Chemeris | 6e1dffd | 2017-03-17 16:13:51 -0700 | [diff] [blame] | 136 | /** Demodulate burst basde on type and output soft bits */ |
Alexander Chemeris | e0c1218 | 2017-03-18 13:27:48 -0700 | [diff] [blame] | 137 | SoftVector *demodAnyBurst(const signalVector &burst, int sps, |
Alexander Chemeris | 6e1dffd | 2017-03-17 16:13:51 -0700 | [diff] [blame] | 138 | complex amp, float toa, CorrType type); |
| 139 | |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 140 | #endif /* SIGPROCLIB_H */ |