dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Free Software Foundation, Inc. |
| 3 | * |
| 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. |
| 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 | |
| 23 | /** Convolution type indicator */ |
kurtis.heimerl | 3b8ad24 | 2011-11-26 03:18:19 +0000 | [diff] [blame] | 24 | enum ConvType { |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 25 | START_ONLY, |
| 26 | NO_DELAY, |
| 27 | CUSTOM, |
| 28 | UNDEFINED, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
Tom Tsou | 577cd02 | 2015-05-18 13:57:54 -0700 | [diff] [blame] | 31 | enum signalError { |
| 32 | SIGERR_NONE, |
| 33 | SIGERR_BOUNDS, |
| 34 | SIGERR_CLIP, |
| 35 | SIGERR_UNSUPPORTED, |
| 36 | SIGERR_INTERNAL, |
| 37 | }; |
| 38 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 39 | /** Convert a linear number to a dB value */ |
| 40 | float dB(float x); |
| 41 | |
| 42 | /** Convert a dB value into a linear value */ |
| 43 | float dBinv(float x); |
| 44 | |
| 45 | /** Compute the energy of a vector */ |
| 46 | float vectorNorm2(const signalVector &x); |
| 47 | |
| 48 | /** Compute the average power of a vector */ |
| 49 | float vectorPower(const signalVector &x); |
| 50 | |
| 51 | /** Setup the signal processing library */ |
Tom Tsou | 2079a3c | 2016-03-06 00:58:56 -0800 | [diff] [blame] | 52 | bool sigProcLibSetup(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 53 | |
| 54 | /** Destroy the signal processing library */ |
| 55 | void sigProcLibDestroy(void); |
| 56 | |
| 57 | /** |
| 58 | Convolve two vectors. |
| 59 | @param a,b The vectors to be convolved. |
| 60 | @param c, A preallocated vector to hold the convolution result. |
| 61 | @param spanType The type/span of the convolution. |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 62 | @return The convolution result or NULL on error. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 63 | */ |
Thomas Tsou | 3f32ab5 | 2013-11-15 16:32:54 -0500 | [diff] [blame] | 64 | signalVector *convolve(const signalVector *a, const signalVector *b, |
| 65 | signalVector *c, ConvType spanType, |
| 66 | size_t start = 0, size_t len = 0, |
| 67 | size_t step = 1, int offset = 0); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 70 | Frequency shift a vector. |
| 71 | @param y The frequency shifted vector. |
| 72 | @param x The vector to-be-shifted. |
| 73 | @param freq The digital frequency shift |
| 74 | @param startPhase The starting phase of the oscillator |
| 75 | @param finalPhase The final phase of the oscillator |
| 76 | @return The frequency shifted vector. |
| 77 | */ |
| 78 | signalVector* frequencyShift(signalVector *y, |
| 79 | signalVector *x, |
| 80 | float freq = 0.0, |
| 81 | float startPhase = 0.0, |
| 82 | float *finalPhase=NULL); |
| 83 | |
| 84 | /** |
| 85 | Correlate two vectors. |
| 86 | @param a,b The vectors to be correlated. |
| 87 | @param c, A preallocated vector to hold the correlation result. |
| 88 | @param spanType The type/span of the correlation. |
| 89 | @return The correlation result. |
| 90 | */ |
| 91 | signalVector* correlate(signalVector *a, |
| 92 | signalVector *b, |
| 93 | signalVector *c, |
| 94 | ConvType spanType, |
| 95 | bool bReversedConjugated = false, |
| 96 | unsigned startIx = 0, |
| 97 | unsigned len = 0); |
| 98 | |
| 99 | /** Operate soft slicer on real-valued portion of vector */ |
| 100 | bool vectorSlicer(signalVector *x); |
| 101 | |
| 102 | /** GMSK modulate a GSM burst of bits */ |
| 103 | signalVector *modulateBurst(const BitVector &wBurst, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 104 | int guardPeriodLength, |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 105 | int sps, bool emptyPulse = false); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 106 | |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame^] | 107 | /** 8-PSK modulate a burst of bits */ |
| 108 | signalVector *modulateEdgeBurst(const BitVector &bits, |
| 109 | int sps, bool emptyPulse = false); |
| 110 | |
| 111 | /** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */ |
| 112 | signalVector *generateEdgeBurst(int tsc); |
| 113 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 114 | /** Sinc function */ |
| 115 | float sinc(float x); |
| 116 | |
| 117 | /** Delay a vector */ |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 118 | signalVector *delayVector(signalVector *in, signalVector *out, float delay); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 119 | |
| 120 | /** Add two vectors in-place */ |
| 121 | bool addVector(signalVector &x, |
| 122 | signalVector &y); |
| 123 | |
| 124 | /** Multiply two vectors in-place*/ |
| 125 | bool multVector(signalVector &x, |
| 126 | signalVector &y); |
| 127 | |
| 128 | /** Generate a vector of gaussian noise */ |
| 129 | signalVector *gaussianNoise(int length, |
| 130 | float variance = 1.0, |
| 131 | complex mean = complex(0.0)); |
| 132 | |
| 133 | /** |
| 134 | Given a non-integer index, interpolate a sample. |
| 135 | @param inSig The signal from which to interpolate. |
| 136 | @param ix The index. |
| 137 | @return The interpolated signal value. |
| 138 | */ |
| 139 | complex interpolatePoint(const signalVector &inSig, |
| 140 | float ix); |
| 141 | |
| 142 | /** |
| 143 | Given a correlator output, locate the correlation peak. |
| 144 | @param rxBurst The correlator result. |
| 145 | @param peakIndex Pointer to value to receive interpolated peak index. |
| 146 | @param avgPower Power to value to receive mean power. |
| 147 | @return Peak value. |
| 148 | */ |
| 149 | complex peakDetect(const signalVector &rxBurst, |
| 150 | float *peakIndex, |
| 151 | float *avgPwr); |
| 152 | |
| 153 | /** |
| 154 | Apply a scalar to a vector. |
| 155 | @param x The vector of interest. |
| 156 | @param scale The scalar. |
| 157 | */ |
| 158 | void scaleVector(signalVector &x, |
| 159 | complex scale); |
| 160 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 161 | /** |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 162 | Energy detector, checks to see if received burst energy is above a threshold. |
| 163 | @param rxBurst The received GSM burst of interest. |
| 164 | @param windowLength The number of burst samples used to compute burst energy |
| 165 | @param detectThreshold The detection threshold, a linear value. |
| 166 | @param avgPwr The average power of the received burst. |
| 167 | @return True if burst energy is above threshold. |
| 168 | */ |
| 169 | bool energyDetect(signalVector &rxBurst, |
| 170 | unsigned windowLength, |
| 171 | float detectThreshold, |
| 172 | float *avgPwr = NULL); |
| 173 | |
| 174 | /** |
| 175 | RACH correlator/detector. |
| 176 | @param rxBurst The received GSM burst of interest. |
| 177 | @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 178 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 179 | @param amplitude The estimated amplitude of received RACH burst. |
| 180 | @param TOA The estimate time-of-arrival of received RACH burst. |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 181 | @return positive if threshold value is reached, negative on error, zero otherwise |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 182 | */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 183 | int detectRACHBurst(signalVector &rxBurst, |
| 184 | float detectThreshold, |
| 185 | int sps, |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 186 | complex &litude, |
| 187 | float &TOA); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | Normal burst correlator, detector, channel estimator. |
| 191 | @param rxBurst The received GSM burst of interest. |
| 192 | |
| 193 | @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 194 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 195 | @param amplitude The estimated amplitude of received TSC burst. |
| 196 | @param TOA The estimate time-of-arrival of received TSC burst. |
| 197 | @param maxTOA The maximum expected time-of-arrival |
| 198 | @param requestChannel Set to true if channel estimation is desired. |
| 199 | @param channelResponse The estimated channel. |
| 200 | @param channelResponseOffset The time offset b/w the first sample of the channel response and the reported TOA. |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 201 | @return positive if threshold value is reached, negative on error, zero otherwise |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 202 | */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 203 | int analyzeTrafficBurst(signalVector &rxBurst, |
Alexander Chemeris | 130a800 | 2015-06-09 20:52:11 -0400 | [diff] [blame] | 204 | unsigned TSC, |
| 205 | float detectThreshold, |
| 206 | int sps, |
| 207 | complex &litude, |
| 208 | float &TOA, |
Tom Tsou | 4656940 | 2016-03-06 01:59:38 -0800 | [diff] [blame] | 209 | unsigned maxTOA); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 210 | |
| 211 | /** |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame^] | 212 | EDGE burst detector |
| 213 | @param burst The received GSM burst of interest |
| 214 | |
| 215 | @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. |
| 216 | @param sps The number of samples per GSM symbol. |
| 217 | @param amplitude The estimated amplitude of received TSC burst. |
| 218 | @param TOA The estimate time-of-arrival of received TSC burst. |
| 219 | @param maxTOA The maximum expected time-of-arrival |
| 220 | @return positive if threshold value is reached, negative on error, zero otherwise |
| 221 | */ |
| 222 | int detectEdgeBurst(signalVector &burst, |
| 223 | unsigned TSC, |
| 224 | float detectThreshold, |
| 225 | int sps, |
| 226 | complex &litude, |
| 227 | float &TOA, |
| 228 | unsigned maxTOA); |
| 229 | |
| 230 | /** |
| 231 | Downsample 4 SPS to 1 SPS using a polyphase filterbank |
| 232 | @param burst Input burst of at least 624 symbols |
| 233 | @return Decimated signal vector of 156 symbols |
| 234 | */ |
| 235 | |
| 236 | signalVector *downsampleBurst(signalVector &burst); |
| 237 | |
| 238 | /** |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 239 | Decimate a vector. |
| 240 | @param wVector The vector of interest. |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 241 | @param factor Decimation factor. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 242 | @return The decimated signal vector. |
| 243 | */ |
Thomas Tsou | 94edaae | 2013-11-09 22:19:19 -0500 | [diff] [blame] | 244 | signalVector *decimateVector(signalVector &wVector, size_t factor); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | Demodulates a received burst using a soft-slicer. |
| 248 | @param rxBurst The burst to be demodulated. |
| 249 | @param gsmPulse The GSM pulse. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 250 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 251 | @param channel The amplitude estimate of the received burst. |
| 252 | @param TOA The time-of-arrival of the received burst. |
| 253 | @return The demodulated bit sequence. |
| 254 | */ |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 255 | SoftVector *demodulateBurst(signalVector &rxBurst, int sps, |
| 256 | complex channel, float TOA); |
Tom Tsou | d325343 | 2016-03-06 03:08:01 -0800 | [diff] [blame^] | 257 | |
| 258 | /** |
| 259 | Demodulate 8-PSK EDGE burst with soft symbol ooutput |
| 260 | @param rxBurst The burst to be demodulated. |
| 261 | @param sps The number of samples per GSM symbol. |
| 262 | @param channel The amplitude estimate of the received burst. |
| 263 | @param TOA The time-of-arrival of the received burst. |
| 264 | @return The demodulated bit sequence. |
| 265 | */ |
| 266 | SoftVector *demodEdgeBurst(signalVector &rxBurst, int sps, |
| 267 | complex channel, float TOA); |
| 268 | |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 269 | #endif /* SIGPROCLIB_H */ |