From 70134a01eb5b70c69a4a3b86467d99b5286b4ec6 Mon Sep 17 00:00:00 2001 From: Tom Tsou Date: Mon, 12 Jun 2017 14:23:53 -0700 Subject: sigProcLib: Remove unused functions from public interface Also remove entirely completely unused calls. Most of these calls have been around since OpenBTS conception. Nearly a decade is long enough time for deprecation. Change-Id: Ifc122aaff23414c363b4b00f99061eed8a6902d0 --- Transceiver52M/sigProcLib.cpp | 316 +++++++----------------------------------- Transceiver52M/sigProcLib.h | 203 --------------------------- 2 files changed, 52 insertions(+), 467 deletions(-) diff --git a/Transceiver52M/sigProcLib.cpp b/Transceiver52M/sigProcLib.cpp index 9a8c824..3a9a529 100644 --- a/Transceiver52M/sigProcLib.cpp +++ b/Transceiver52M/sigProcLib.cpp @@ -46,9 +46,9 @@ using namespace GSM; #define CLIP_THRESH 30000.0f /** Lookup tables for trigonometric approximation */ -float cosTable[TABLESIZE+1]; // add 1 element for wrap around -float sinTable[TABLESIZE+1]; -float sincTable[TABLESIZE+1]; +static float cosTable[TABLESIZE+1]; // add 1 element for wrap around +static float sinTable[TABLESIZE+1]; +static float sincTable[TABLESIZE+1]; /** Constants */ static const float M_PI_F = (float)M_PI; @@ -64,7 +64,7 @@ static signalVector *GMSKReverseRotation1 = NULL; /* Precomputed fractional delay filters */ static signalVector *delayFilters[DELAYFILTS]; -static Complex psk8_table[8] = { +static const Complex psk8_table[8] = { Complex(-0.70710678, 0.70710678), Complex( 0.0, -1.0), Complex( 0.0, 1.0), @@ -172,67 +172,7 @@ void sigProcLibDestroy() GSMPulse4 = NULL; } -// dB relative to 1.0. -// if > 1.0, then return 0 dB -float dB(float x) { - - float arg = 1.0F; - float dB = 0.0F; - - if (x >= 1.0F) return 0.0F; - if (x <= 0.0F) return -200.0F; - - float prevArg = arg; - float prevdB = dB; - float stepSize = 16.0F; - float dBstepSize = 12.0F; - while (stepSize > 1.0F) { - do { - prevArg = arg; - prevdB = dB; - arg /= stepSize; - dB -= dBstepSize; - } while (arg > x); - arg = prevArg; - dB = prevdB; - stepSize *= 0.5F; - dBstepSize -= 3.0F; - } - return ((arg-x)*(dB-3.0F) + (x-arg*0.5F)*dB)/(arg - arg*0.5F); - -} - -// 10^(-dB/10), inverse of dB func. -float dBinv(float x) { - - float arg = 1.0F; - float dB = 0.0F; - - if (x >= 0.0F) return 1.0F; - if (x <= -200.0F) return 0.0F; - - float prevArg = arg; - float prevdB = dB; - float stepSize = 16.0F; - float dBstepSize = 12.0F; - while (stepSize > 1.0F) { - do { - prevArg = arg; - prevdB = dB; - arg /= stepSize; - dB -= dBstepSize; - } while (dB > x); - arg = prevArg; - dB = prevdB; - stepSize *= 0.5F; - dBstepSize -= 3.0F; - } - - return ((dB-x)*(arg*0.5F)+(x-(dB-3.0F))*(arg))/3.0F; - -} - -float vectorNorm2(const signalVector &x) +static float vectorNorm2(const signalVector &x) { signalVector::const_iterator xPtr = x.begin(); float Energy = 0.0; @@ -242,41 +182,6 @@ float vectorNorm2(const signalVector &x) return Energy; } - -float vectorPower(const signalVector &x) -{ - return vectorNorm2(x)/x.size(); -} - -/** compute cosine via lookup table */ -float cosLookup(const float x) -{ - float arg = x*M_1_2PI_F; - while (arg > 1.0F) arg -= 1.0F; - while (arg < 0.0F) arg += 1.0F; - - const float argT = arg*((float)TABLESIZE); - const int argI = (int)argT; - const float delta = argT-argI; - const float iDelta = 1.0F-delta; - return iDelta*cosTable[argI] + delta*cosTable[argI+1]; -} - -/** compute sine via lookup table */ -float sinLookup(const float x) -{ - float arg = x*M_1_2PI_F; - while (arg > 1.0F) arg -= 1.0F; - while (arg < 0.0F) arg += 1.0F; - - const float argT = arg*((float)TABLESIZE); - const int argI = (int)argT; - const float delta = argT-argI; - const float iDelta = 1.0F-delta; - return iDelta*sinTable[argI] + delta*sinTable[argI+1]; -} - - /** compute e^(-jx) via lookup table. */ static complex expjLookup(float x) { @@ -401,11 +306,18 @@ static bool GMSKReverseRotate(signalVector &x, int sps) return true; } -signalVector *convolve(const signalVector *x, - const signalVector *h, - signalVector *y, - ConvType spanType, size_t start, - size_t len, size_t step, int offset) +/** Convolution type indicator */ +enum ConvType { + START_ONLY, + NO_DELAY, + CUSTOM, + UNDEFINED, +}; + +static signalVector *convolve(const signalVector *x, const signalVector *h, + signalVector *y, ConvType spanType, + size_t start = 0, size_t len = 0, + size_t step = 1, int offset = 0) { int rc; size_t head = 0, tail = 0; @@ -654,29 +566,6 @@ static PulseSequence *generateGSMPulse(int sps) return pulse; } -signalVector* reverseConjugate(signalVector *b) -{ - signalVector *tmp = new signalVector(b->size()); - tmp->isReal(b->isReal()); - signalVector::iterator bP = b->begin(); - signalVector::iterator bPEnd = b->end(); - signalVector::iterator tmpP = tmp->end()-1; - if (!b->isReal()) { - while (bP < bPEnd) { - *tmpP-- = bP->conj(); - bP++; - } - } - else { - while (bP < bPEnd) { - *tmpP-- = bP->real(); - bP++; - } - } - - return tmp; -} - bool vectorSlicer(SoftVector *x) { SoftVector::iterator xP = x->begin(); @@ -1158,7 +1047,7 @@ static void generateSincTable() } } -float sinc(float x) +static float sinc(float x) { if (fabs(x) >= 8 * M_PI) return 0.0; @@ -1173,7 +1062,7 @@ float sinc(float x) * sinc function generator. The number of filters generated is specified * by the DELAYFILTS value. */ -void generateDelayFilters() +static void generateDelayFilters() { int h_len = 20; complex *data; @@ -1268,31 +1157,8 @@ signalVector *delayVector(const signalVector *in, signalVector *out, float delay return out; } -signalVector *gaussianNoise(int length, - float variance, - complex mean) +static complex interpolatePoint(const signalVector &inSig, float ix) { - - signalVector *noise = new signalVector(length); - signalVector::iterator nPtr = noise->begin(); - float stddev = sqrtf(variance); - while (nPtr < noise->end()) { - float u1 = (float) rand()/ (float) RAND_MAX; - while (u1==0.0) - u1 = (float) rand()/ (float) RAND_MAX; - float u2 = (float) rand()/ (float) RAND_MAX; - float arg = 2.0*M_PI*u2; - *nPtr = mean + stddev*complex(cos(arg),sin(arg))*sqrtf(-2.0*log(u1)); - nPtr++; - } - - return noise; -} - -complex interpolatePoint(const signalVector &inSig, - float ix) -{ - int start = (int) (floor(ix) - 10); if (start < 0) start = 0; int end = (int) (floor(ix) + 11); @@ -1332,12 +1198,9 @@ static complex fastPeakDetect(const signalVector &rxBurst, float *index) return amp; } -complex peakDetect(const signalVector &rxBurst, - float *peakIndex, - float *avgPwr) +static complex peakDetect(const signalVector &rxBurst, + float *peakIndex, float *avgPwr) { - - complex maxVal = 0.0; float maxIndex = -1; float sumPower = 0.0; @@ -1410,7 +1273,7 @@ void scaleVector(signalVector &x, } /** in-place conjugation */ -void conjugateVector(signalVector &x) +static void conjugateVector(signalVector &x) { if (x.isReal()) return; signalVector::iterator xP = x.begin(); @@ -1421,37 +1284,6 @@ void conjugateVector(signalVector &x) } } - -// in-place addition!! -bool addVector(signalVector &x, - signalVector &y) -{ - signalVector::iterator xP = x.begin(); - signalVector::iterator yP = y.begin(); - signalVector::iterator xPEnd = x.end(); - signalVector::iterator yPEnd = y.end(); - while ((xP < xPEnd) && (yP < yPEnd)) { - *xP = *xP + *yP; - xP++; yP++; - } - return true; -} - -// in-place multiplication!! -bool multVector(signalVector &x, - signalVector &y) -{ - signalVector::iterator xP = x.begin(); - signalVector::iterator yP = y.begin(); - signalVector::iterator xPEnd = x.end(); - signalVector::iterator yPEnd = y.end(); - while ((xP < xPEnd) && (yP < yPEnd)) { - *xP = (*xP) * (*yP); - xP++; yP++; - } - return true; -} - static bool generateMidamble(int sps, int tsc) { bool status = true; @@ -1528,7 +1360,7 @@ release: return status; } -CorrelationSequence *generateEdgeMidamble(int tsc) +static CorrelationSequence *generateEdgeMidamble(int tsc) { complex *data = NULL; signalVector *midamble = NULL, *_midamble = NULL; @@ -1682,6 +1514,24 @@ float energyDetect(const signalVector &rxBurst, unsigned windowLength) return energy/windowLength; } +static signalVector *downsampleBurst(const signalVector &burst) +{ + signalVector *in, *out; + + in = new signalVector(DOWNSAMPLE_IN_LEN, dnsampler->len()); + out = new signalVector(DOWNSAMPLE_OUT_LEN); + memcpy(in->begin(), burst.begin(), DOWNSAMPLE_IN_LEN * 2 * sizeof(float)); + + if (dnsampler->rotate((float *) in->begin(), DOWNSAMPLE_IN_LEN, + (float *) out->begin(), DOWNSAMPLE_OUT_LEN) < 0) { + delete out; + out = NULL; + } + + delete in; + return out; +}; + /* * Detect a burst based on correlation and peak-to-average ratio * @@ -1816,12 +1666,8 @@ static int detectGeneralBurst(const signalVector &rxBurst, * head: Search 8 symbols before target * tail: Search 8 symbols + maximum expected delay */ -int detectRACHBurst(const signalVector &burst, - float threshold, - int sps, - complex &litude, - float &toa, - unsigned max_toa) +static int detectRACHBurst(const signalVector &burst, float threshold, int sps, + complex &litude, float &toa, unsigned max_toa) { int rc, target, head, tail; CorrelationSequence *sync; @@ -1845,8 +1691,8 @@ int detectRACHBurst(const signalVector &burst, * head: Search 6 symbols before target * tail: Search 6 symbols + maximum expected delay */ -int analyzeTrafficBurst(const signalVector &burst, unsigned tsc, float threshold, - int sps, complex &litude, float &toa, unsigned max_toa) +static int analyzeTrafficBurst(const signalVector &burst, unsigned tsc, float threshold, + int sps, complex &litude, float &toa, unsigned max_toa) { int rc, target, head, tail; CorrelationSequence *sync; @@ -1864,8 +1710,8 @@ int analyzeTrafficBurst(const signalVector &burst, unsigned tsc, float threshold return rc; } -int detectEdgeBurst(const signalVector &burst, unsigned tsc, float threshold, - int sps, complex &litude, float &toa, unsigned max_toa) +static int detectEdgeBurst(const signalVector &burst, unsigned tsc, float threshold, + int sps, complex &litude, float &toa, unsigned max_toa) { int rc, target, head, tail; CorrelationSequence *sync; @@ -1915,41 +1761,6 @@ int detectAnyBurst(const signalVector &burst, unsigned tsc, float threshold, return rc; } -signalVector *downsampleBurst(const signalVector &burst) -{ - signalVector *in, *out; - - in = new signalVector(DOWNSAMPLE_IN_LEN, dnsampler->len()); - out = new signalVector(DOWNSAMPLE_OUT_LEN); - memcpy(in->begin(), burst.begin(), DOWNSAMPLE_IN_LEN * 2 * sizeof(float)); - - if (dnsampler->rotate((float *) in->begin(), DOWNSAMPLE_IN_LEN, - (float *) out->begin(), DOWNSAMPLE_OUT_LEN) < 0) { - delete out; - out = NULL; - } - - delete in; - return out; -}; - -signalVector *decimateVector(signalVector &wVector, size_t factor) -{ - signalVector *dec; - - if (factor <= 1) - return NULL; - - dec = new signalVector(wVector.size() / factor); - dec->isReal(wVector.isReal()); - - signalVector::iterator itr = dec->begin(); - for (size_t i = 0; i < wVector.size(); i += factor) - *itr++ = wVector[i]; - - return dec; -} - /* * Soft 8-PSK decoding using Manhattan distance metric */ @@ -2046,8 +1857,8 @@ static signalVector *demodCommon(const signalVector &burst, int sps, * 4 SPS (if activated) to minimize distortion through the fractional * delay filters. Symbol rotation and after always operates at 1 SPS. */ -SoftVector *demodGmskBurst(const signalVector &rxBurst, int sps, - complex channel, float TOA) +static SoftVector *demodGmskBurst(const signalVector &rxBurst, + int sps, complex channel, float TOA) { SoftVector *bits; signalVector *dec; @@ -2075,8 +1886,8 @@ SoftVector *demodGmskBurst(const signalVector &rxBurst, int sps, * through the fractional delay filters at 1 SPS renders signal * nearly unrecoverable. */ -SoftVector *demodEdgeBurst(const signalVector &burst, int sps, - complex chan, float toa) +static SoftVector *demodEdgeBurst(const signalVector &burst, + int sps, complex chan, float toa) { SoftVector *bits; signalVector *dec, *rot, *eq; @@ -2137,26 +1948,3 @@ fail: sigProcLibDestroy(); return false; } - -std::string corrTypeToString(CorrType corr) { - switch (corr) { - case OFF: - return "OFF"; - case TSC: - return "TSC"; - case RACH: - return "RACH"; - case EDGE: - return "EDGE"; - case IDLE: - return "IDLE"; - default: - return "unknown"; - } -} - -std::ostream& operator<<(std::ostream& os, CorrType corr) -{ - os << corrTypeToString(corr); - return os; -} diff --git a/Transceiver52M/sigProcLib.h b/Transceiver52M/sigProcLib.h index 4318fe0..9bc7e10 100644 --- a/Transceiver52M/sigProcLib.h +++ b/Transceiver52M/sigProcLib.h @@ -25,14 +25,6 @@ #define EDGE_BURST_NBITS 444 #define EDGE_BURST_NSYMS (EDGE_BURST_NBITS / 3) -/** Convolution type indicator */ -enum ConvType { - START_ONLY, - NO_DELAY, - CUSTOM, - UNDEFINED, -}; - /** Codes for burst types of received bursts*/ enum CorrType{ OFF, ///< timeslot is off @@ -41,8 +33,6 @@ enum CorrType{ EDGE, ///< timeslot should contain an EDGE burst IDLE ///< timeslot is an idle (or dummy) burst }; -std::string corrTypeToString(CorrType corr); -std::ostream& operator<<(std::ostream& os, CorrType corr); enum SignalError { SIGERR_NONE, @@ -61,66 +51,12 @@ enum SignalError { */ #define BURST_THRESH 4.0 -/** Convert a linear number to a dB value */ -float dB(float x); - -/** Convert a dB value into a linear value */ -float dBinv(float x); - -/** Compute the energy of a vector */ -float vectorNorm2(const signalVector &x); - -/** Compute the average power of a vector */ -float vectorPower(const signalVector &x); - /** Setup the signal processing library */ bool sigProcLibSetup(); /** Destroy the signal processing library */ void sigProcLibDestroy(void); -/** - Convolve two vectors. - @param a,b The vectors to be convolved. - @param c, A preallocated vector to hold the convolution result. - @param spanType The type/span of the convolution. - @return The convolution result or NULL on error. -*/ -signalVector *convolve(const signalVector *a, const signalVector *b, - signalVector *c, ConvType spanType, - size_t start = 0, size_t len = 0, - size_t step = 1, int offset = 0); - -/** - Frequency shift a vector. - @param y The frequency shifted vector. - @param x The vector to-be-shifted. - @param freq The digital frequency shift - @param startPhase The starting phase of the oscillator - @param finalPhase The final phase of the oscillator - @return The frequency shifted vector. -*/ -signalVector* frequencyShift(signalVector *y, - signalVector *x, - float freq = 0.0, - float startPhase = 0.0, - float *finalPhase=NULL); - -/** - Correlate two vectors. - @param a,b The vectors to be correlated. - @param c, A preallocated vector to hold the correlation result. - @param spanType The type/span of the correlation. - @return The correlation result. -*/ -signalVector* correlate(signalVector *a, - signalVector *b, - signalVector *c, - ConvType spanType, - bool bReversedConjugated = false, - unsigned startIx = 0, - unsigned len = 0); - /** Operate soft slicer on a soft-bit vector */ bool vectorSlicer(SoftVector *x); @@ -148,45 +84,6 @@ signalVector *genRandAccessBurst(int delay, int sps, int tn); /** Generate a dummy GSM burst - 4 or 1 SPS */ signalVector *generateDummyBurst(int sps, int tn); -/** Sinc function */ -float sinc(float x); - -/** Delay a vector */ -signalVector *delayVector(const signalVector *in, signalVector *out, float delay); - -/** Add two vectors in-place */ -bool addVector(signalVector &x, - signalVector &y); - -/** Multiply two vectors in-place*/ -bool multVector(signalVector &x, - signalVector &y); - -/** Generate a vector of gaussian noise */ -signalVector *gaussianNoise(int length, - float variance = 1.0, - complex mean = complex(0.0)); - -/** - Given a non-integer index, interpolate a sample. - @param inSig The signal from which to interpolate. - @param ix The index. - @return The interpolated signal value. -*/ -complex interpolatePoint(const signalVector &inSig, - float ix); - -/** - Given a correlator output, locate the correlation peak. - @param rxBurst The correlator result. - @param peakIndex Pointer to value to receive interpolated peak index. - @param avgPower Power to value to receive mean power. - @return Peak value. -*/ -complex peakDetect(const signalVector &rxBurst, - float *peakIndex, - float *avgPwr); - /** Apply a scalar to a vector. @param x The vector of interest. @@ -203,68 +100,6 @@ void scaleVector(signalVector &x, */ float energyDetect(const signalVector &rxBurst, unsigned windowLength); - -/** - RACH aka Access Burst correlator/detector. - @param burst The received GSM burst of interest. - @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. - @param sps The number of samples per GSM symbol. - @param amplitude The estimated amplitude of received RACH burst. - @param toa The estimate time-of-arrival of received RACH burst. - @param max_toa The maximum expected time-of-arrival - @return 1 if threshold value is reached, - negative value (-SignalError) on error, - zero (SIGERR_NONE) if no burst is detected -*/ -int detectRACHBurst(const signalVector &burst, - float threshold, - int sps, - complex &litude, - float &toa, - unsigned max_toa); - -/** - GMSK Normal Burst correlator/detector. - @param rxBurst The received GSM burst of interest. - @param tsc Midamble type (0..7) also known as TSC - @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. - @param sps The number of samples per GSM symbol. - @param amplitude The estimated amplitude of received TSC burst. - @param toa The estimate time-of-arrival of received TSC burst. - @param max_toa The maximum expected time-of-arrival - @return 1 if threshold value is reached, - negative value (-SignalError) on error, - zero (SIGERR_NONE) if no burst is detected -*/ -int analyzeTrafficBurst(const signalVector &burst, - unsigned tsc, - float threshold, - int sps, - complex &litude, - float &toa, - unsigned max_toa); - -/** - EDGE/8-PSK Normal Burst correlator/detector - @param burst The received GSM burst of interest - @param tsc Midamble type (0..7) also known as TSC - @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity. - @param sps The number of samples per GSM symbol. - @param amplitude The estimated amplitude of received TSC burst. - @param toa The estimate time-of-arrival of received TSC burst. - @param max_toa The maximum expected time-of-arrival - @return 1 if threshold value is reached, - negative value (-SignalError) on error, - zero (SIGERR_NONE) if no burst is detected -*/ -int detectEdgeBurst(const signalVector &burst, - unsigned tsc, - float threshold, - int sps, - complex &litude, - float &toa, - unsigned max_toa); - /** 8-PSK/GMSK/RACH burst detector @param burst The received GSM burst of interest @@ -287,44 +122,6 @@ int detectAnyBurst(const signalVector &burst, float &toa, unsigned max_toa); -/** - Downsample 4 SPS to 1 SPS using a polyphase filterbank - @param burst Input burst of at least 624 symbols - @return Decimated signal vector of 156 symbols -*/ -signalVector *downsampleBurst(const signalVector &burst); - -/** - Decimate a vector. - @param wVector The vector of interest. - @param factor Decimation factor. - @return The decimated signal vector. -*/ -signalVector *decimateVector(signalVector &wVector, size_t factor); - -/** - Demodulates a GMSK burst using a soft-slicer. - @param rxBurst The burst to be demodulated. - @param gsmPulse The GSM pulse. - @param sps The number of samples per GSM symbol. - @param channel The amplitude estimate of the received burst. - @param TOA The time-of-arrival of the received burst. - @return The demodulated bit sequence. -*/ -SoftVector *demodGmskBurst(const signalVector &rxBurst, int sps, - complex channel, float TOA); - -/** - Demodulate 8-PSK EDGE burst with soft symbol ooutput - @param rxBurst The burst to be demodulated. - @param sps The number of samples per GSM symbol. - @param channel The amplitude estimate of the received burst. - @param TOA The time-of-arrival of the received burst. - @return The demodulated bit sequence. -*/ -SoftVector *demodEdgeBurst(const signalVector &rxBurst, int sps, - complex channel, float TOA); - /** Demodulate burst basde on type and output soft bits */ SoftVector *demodAnyBurst(const signalVector &burst, int sps, complex amp, float toa, CorrType type); -- cgit v1.2.3