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