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 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 31 | /** Convert a linear number to a dB value */ |
| 32 | float dB(float x); |
| 33 | |
| 34 | /** Convert a dB value into a linear value */ |
| 35 | float dBinv(float x); |
| 36 | |
| 37 | /** Compute the energy of a vector */ |
| 38 | float vectorNorm2(const signalVector &x); |
| 39 | |
| 40 | /** Compute the average power of a vector */ |
| 41 | float vectorPower(const signalVector &x); |
| 42 | |
| 43 | /** Setup the signal processing library */ |
Thomas Tsou | e57004d | 2013-08-20 18:55:33 -0400 | [diff] [blame] | 44 | bool sigProcLibSetup(int sps); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 45 | |
| 46 | /** Destroy the signal processing library */ |
| 47 | void sigProcLibDestroy(void); |
| 48 | |
| 49 | /** |
| 50 | Convolve two vectors. |
| 51 | @param a,b The vectors to be convolved. |
| 52 | @param c, A preallocated vector to hold the convolution result. |
| 53 | @param spanType The type/span of the convolution. |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 54 | @return The convolution result or NULL on error. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 55 | */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 56 | signalVector *convolve(const signalVector *a, |
| 57 | const signalVector *b, |
| 58 | signalVector *c, |
| 59 | ConvType spanType, |
| 60 | int start = 0, |
| 61 | unsigned len = 0, |
| 62 | unsigned step = 1, int offset = 0); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 63 | |
| 64 | /** |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 65 | Frequency shift a vector. |
| 66 | @param y The frequency shifted vector. |
| 67 | @param x The vector to-be-shifted. |
| 68 | @param freq The digital frequency shift |
| 69 | @param startPhase The starting phase of the oscillator |
| 70 | @param finalPhase The final phase of the oscillator |
| 71 | @return The frequency shifted vector. |
| 72 | */ |
| 73 | signalVector* frequencyShift(signalVector *y, |
| 74 | signalVector *x, |
| 75 | float freq = 0.0, |
| 76 | float startPhase = 0.0, |
| 77 | float *finalPhase=NULL); |
| 78 | |
| 79 | /** |
| 80 | Correlate two vectors. |
| 81 | @param a,b The vectors to be correlated. |
| 82 | @param c, A preallocated vector to hold the correlation result. |
| 83 | @param spanType The type/span of the correlation. |
| 84 | @return The correlation result. |
| 85 | */ |
| 86 | signalVector* correlate(signalVector *a, |
| 87 | signalVector *b, |
| 88 | signalVector *c, |
| 89 | ConvType spanType, |
| 90 | bool bReversedConjugated = false, |
| 91 | unsigned startIx = 0, |
| 92 | unsigned len = 0); |
| 93 | |
| 94 | /** Operate soft slicer on real-valued portion of vector */ |
| 95 | bool vectorSlicer(signalVector *x); |
| 96 | |
| 97 | /** GMSK modulate a GSM burst of bits */ |
| 98 | signalVector *modulateBurst(const BitVector &wBurst, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 99 | int guardPeriodLength, |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 100 | int sps, bool emptyPulse = false); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 101 | |
| 102 | /** Sinc function */ |
| 103 | float sinc(float x); |
| 104 | |
| 105 | /** Delay a vector */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 106 | bool delayVector(signalVector &wBurst, float delay); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 107 | |
| 108 | /** Add two vectors in-place */ |
| 109 | bool addVector(signalVector &x, |
| 110 | signalVector &y); |
| 111 | |
| 112 | /** Multiply two vectors in-place*/ |
| 113 | bool multVector(signalVector &x, |
| 114 | signalVector &y); |
| 115 | |
| 116 | /** Generate a vector of gaussian noise */ |
| 117 | signalVector *gaussianNoise(int length, |
| 118 | float variance = 1.0, |
| 119 | complex mean = complex(0.0)); |
| 120 | |
| 121 | /** |
| 122 | Given a non-integer index, interpolate a sample. |
| 123 | @param inSig The signal from which to interpolate. |
| 124 | @param ix The index. |
| 125 | @return The interpolated signal value. |
| 126 | */ |
| 127 | complex interpolatePoint(const signalVector &inSig, |
| 128 | float ix); |
| 129 | |
| 130 | /** |
| 131 | Given a correlator output, locate the correlation peak. |
| 132 | @param rxBurst The correlator result. |
| 133 | @param peakIndex Pointer to value to receive interpolated peak index. |
| 134 | @param avgPower Power to value to receive mean power. |
| 135 | @return Peak value. |
| 136 | */ |
| 137 | complex peakDetect(const signalVector &rxBurst, |
| 138 | float *peakIndex, |
| 139 | float *avgPwr); |
| 140 | |
| 141 | /** |
| 142 | Apply a scalar to a vector. |
| 143 | @param x The vector of interest. |
| 144 | @param scale The scalar. |
| 145 | */ |
| 146 | void scaleVector(signalVector &x, |
| 147 | complex scale); |
| 148 | |
| 149 | /** |
| 150 | Add a constant offset to a vecotr. |
| 151 | @param x The vector of interest. |
| 152 | @param offset The offset. |
| 153 | */ |
| 154 | void offsetVector(signalVector &x, |
| 155 | complex offset); |
| 156 | |
| 157 | /** |
| 158 | Generate a modulated GSM midamble, stored within the library. |
| 159 | @param gsmPulse The GSM pulse used for modulation. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 160 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 161 | @param TSC The training sequence [0..7] |
| 162 | @return Success. |
| 163 | */ |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 164 | bool generateMidamble(int sps, int tsc); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 165 | /** |
| 166 | Generate a modulated RACH sequence, stored within the library. |
| 167 | @param gsmPulse The GSM pulse used for modulation. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 168 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 169 | @return Success. |
| 170 | */ |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 171 | bool generateRACHSequence(int sps); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | Energy detector, checks to see if received burst energy is above a threshold. |
| 175 | @param rxBurst The received GSM burst of interest. |
| 176 | @param windowLength The number of burst samples used to compute burst energy |
| 177 | @param detectThreshold The detection threshold, a linear value. |
| 178 | @param avgPwr The average power of the received burst. |
| 179 | @return True if burst energy is above threshold. |
| 180 | */ |
| 181 | bool energyDetect(signalVector &rxBurst, |
| 182 | unsigned windowLength, |
| 183 | float detectThreshold, |
| 184 | float *avgPwr = NULL); |
| 185 | |
| 186 | /** |
| 187 | RACH correlator/detector. |
| 188 | @param rxBurst The received GSM burst of interest. |
| 189 | @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] | 190 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 191 | @param amplitude The estimated amplitude of received RACH burst. |
| 192 | @param TOA The estimate time-of-arrival of received RACH burst. |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 193 | @return positive if threshold value is reached, negative on error, zero otherwise |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 194 | */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 195 | int detectRACHBurst(signalVector &rxBurst, |
| 196 | float detectThreshold, |
| 197 | int sps, |
| 198 | complex *amplitude, |
| 199 | float* TOA); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | Normal burst correlator, detector, channel estimator. |
| 203 | @param rxBurst The received GSM burst of interest. |
| 204 | |
| 205 | @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] | 206 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 207 | @param amplitude The estimated amplitude of received TSC burst. |
| 208 | @param TOA The estimate time-of-arrival of received TSC burst. |
| 209 | @param maxTOA The maximum expected time-of-arrival |
| 210 | @param requestChannel Set to true if channel estimation is desired. |
| 211 | @param channelResponse The estimated channel. |
| 212 | @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] | 213 | @return positive if threshold value is reached, negative on error, zero otherwise |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 214 | */ |
Thomas Tsou | 3eaae80 | 2013-08-20 19:31:14 -0400 | [diff] [blame] | 215 | int analyzeTrafficBurst(signalVector &rxBurst, |
| 216 | unsigned TSC, |
| 217 | float detectThreshold, |
| 218 | int sps, |
| 219 | complex *amplitude, |
| 220 | float *TOA, |
| 221 | unsigned maxTOA, |
| 222 | bool requestChannel = false, |
| 223 | signalVector** channelResponse = NULL, |
| 224 | float *channelResponseOffset = NULL); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 225 | |
| 226 | /** |
| 227 | Decimate a vector. |
| 228 | @param wVector The vector of interest. |
| 229 | @param decimationFactor The amount of decimation, i.e. the decimation factor. |
| 230 | @return The decimated signal vector. |
| 231 | */ |
| 232 | signalVector *decimateVector(signalVector &wVector, |
| 233 | int decimationFactor); |
| 234 | |
| 235 | /** |
| 236 | Demodulates a received burst using a soft-slicer. |
| 237 | @param rxBurst The burst to be demodulated. |
| 238 | @param gsmPulse The GSM pulse. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 239 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 240 | @param channel The amplitude estimate of the received burst. |
| 241 | @param TOA The time-of-arrival of the received burst. |
| 242 | @return The demodulated bit sequence. |
| 243 | */ |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 244 | SoftVector *demodulateBurst(signalVector &rxBurst, int sps, |
| 245 | complex channel, float TOA); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 246 | |
| 247 | /** |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 248 | Design the necessary filters for a decision-feedback equalizer. |
| 249 | @param channelResponse The multipath channel that we're mitigating. |
| 250 | @param SNRestimate The signal-to-noise estimate of the channel, a linear value |
| 251 | @param Nf The number of taps in the feedforward filter. |
| 252 | @param feedForwardFilter The designed feed forward filter. |
| 253 | @param feedbackFilter The designed feedback filter. |
| 254 | @return True if DFE can be designed. |
| 255 | */ |
| 256 | bool designDFE(signalVector &channelResponse, |
| 257 | float SNRestimate, |
| 258 | int Nf, |
| 259 | signalVector **feedForwardFilter, |
| 260 | signalVector **feedbackFilter); |
| 261 | |
| 262 | /** |
| 263 | Equalize/demodulate a received burst via a decision-feedback equalizer. |
| 264 | @param rxBurst The received burst to be demodulated. |
| 265 | @param TOA The time-of-arrival of the received burst. |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 266 | @param sps The number of samples per GSM symbol. |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 267 | @param w The feed forward filter of the DFE. |
| 268 | @param b The feedback filter of the DFE. |
| 269 | @return The demodulated bit sequence. |
| 270 | */ |
| 271 | SoftVector *equalizeBurst(signalVector &rxBurst, |
| 272 | float TOA, |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 273 | int sps, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 274 | signalVector &w, |
| 275 | signalVector &b); |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 276 | |
| 277 | #endif /* SIGPROCLIB_H */ |