blob: 8ff8246269f947867e706b435b07232b8b68e083 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
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.heimerl8aea56e2011-11-26 03:18:30 +000015#ifndef SIGPROCLIB_H
16#define SIGPROCLIB_H
dburgessb3a0ca42011-10-12 07:44:40 +000017
18#include "Vector.h"
19#include "Complex.h"
Alexander Chemerisd734e2d2013-06-16 14:30:58 +040020#include "BitVector.h"
Thomas Tsou20eb6d62013-11-09 14:30:41 -050021#include "signalVector.h"
dburgessb3a0ca42011-10-12 07:44:40 +000022
23/** Convolution type indicator */
kurtis.heimerl3b8ad242011-11-26 03:18:19 +000024enum ConvType {
Thomas Tsou3eaae802013-08-20 19:31:14 -040025 START_ONLY,
26 NO_DELAY,
27 CUSTOM,
28 UNDEFINED,
dburgessb3a0ca42011-10-12 07:44:40 +000029};
30
Tom Tsou577cd022015-05-18 13:57:54 -070031enum signalError {
32 SIGERR_NONE,
33 SIGERR_BOUNDS,
34 SIGERR_CLIP,
35 SIGERR_UNSUPPORTED,
36 SIGERR_INTERNAL,
37};
38
dburgessb3a0ca42011-10-12 07:44:40 +000039/** Convert a linear number to a dB value */
40float dB(float x);
41
42/** Convert a dB value into a linear value */
43float dBinv(float x);
44
45/** Compute the energy of a vector */
46float vectorNorm2(const signalVector &x);
47
48/** Compute the average power of a vector */
49float vectorPower(const signalVector &x);
50
51/** Setup the signal processing library */
Tom Tsou2079a3c2016-03-06 00:58:56 -080052bool sigProcLibSetup();
dburgessb3a0ca42011-10-12 07:44:40 +000053
54/** Destroy the signal processing library */
55void 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 Tsou3eaae802013-08-20 19:31:14 -040062 @return The convolution result or NULL on error.
dburgessb3a0ca42011-10-12 07:44:40 +000063*/
Thomas Tsou3f32ab52013-11-15 16:32:54 -050064signalVector *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);
dburgessb3a0ca42011-10-12 07:44:40 +000068
69/**
dburgessb3a0ca42011-10-12 07:44:40 +000070 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*/
78signalVector* 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*/
91signalVector* 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 */
100bool vectorSlicer(signalVector *x);
101
102/** GMSK modulate a GSM burst of bits */
103signalVector *modulateBurst(const BitVector &wBurst,
dburgessb3a0ca42011-10-12 07:44:40 +0000104 int guardPeriodLength,
Thomas Tsou83e06892013-08-20 16:10:01 -0400105 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +0000106
107/** Sinc function */
108float sinc(float x);
109
110/** Delay a vector */
Thomas Tsou94edaae2013-11-09 22:19:19 -0500111signalVector *delayVector(signalVector *in, signalVector *out, float delay);
dburgessb3a0ca42011-10-12 07:44:40 +0000112
113/** Add two vectors in-place */
114bool addVector(signalVector &x,
115 signalVector &y);
116
117/** Multiply two vectors in-place*/
118bool multVector(signalVector &x,
119 signalVector &y);
120
121/** Generate a vector of gaussian noise */
122signalVector *gaussianNoise(int length,
123 float variance = 1.0,
124 complex mean = complex(0.0));
125
126/**
127 Given a non-integer index, interpolate a sample.
128 @param inSig The signal from which to interpolate.
129 @param ix The index.
130 @return The interpolated signal value.
131*/
132complex interpolatePoint(const signalVector &inSig,
133 float ix);
134
135/**
136 Given a correlator output, locate the correlation peak.
137 @param rxBurst The correlator result.
138 @param peakIndex Pointer to value to receive interpolated peak index.
139 @param avgPower Power to value to receive mean power.
140 @return Peak value.
141*/
142complex peakDetect(const signalVector &rxBurst,
143 float *peakIndex,
144 float *avgPwr);
145
146/**
147 Apply a scalar to a vector.
148 @param x The vector of interest.
149 @param scale The scalar.
150*/
151void scaleVector(signalVector &x,
152 complex scale);
153
dburgessb3a0ca42011-10-12 07:44:40 +0000154/**
dburgessb3a0ca42011-10-12 07:44:40 +0000155 Energy detector, checks to see if received burst energy is above a threshold.
156 @param rxBurst The received GSM burst of interest.
157 @param windowLength The number of burst samples used to compute burst energy
158 @param detectThreshold The detection threshold, a linear value.
159 @param avgPwr The average power of the received burst.
160 @return True if burst energy is above threshold.
161*/
162bool energyDetect(signalVector &rxBurst,
163 unsigned windowLength,
164 float detectThreshold,
165 float *avgPwr = NULL);
166
167/**
168 RACH correlator/detector.
169 @param rxBurst The received GSM burst of interest.
170 @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400171 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000172 @param amplitude The estimated amplitude of received RACH burst.
173 @param TOA The estimate time-of-arrival of received RACH burst.
Thomas Tsou3eaae802013-08-20 19:31:14 -0400174 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000175*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400176int detectRACHBurst(signalVector &rxBurst,
177 float detectThreshold,
178 int sps,
Alexander Chemeris130a8002015-06-09 20:52:11 -0400179 complex &amplitude,
180 float &TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000181
182/**
183 Normal burst correlator, detector, channel estimator.
184 @param rxBurst The received GSM burst of interest.
185
186 @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400187 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000188 @param amplitude The estimated amplitude of received TSC burst.
189 @param TOA The estimate time-of-arrival of received TSC burst.
190 @param maxTOA The maximum expected time-of-arrival
191 @param requestChannel Set to true if channel estimation is desired.
192 @param channelResponse The estimated channel.
193 @param channelResponseOffset The time offset b/w the first sample of the channel response and the reported TOA.
Thomas Tsou3eaae802013-08-20 19:31:14 -0400194 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000195*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400196int analyzeTrafficBurst(signalVector &rxBurst,
Alexander Chemeris130a8002015-06-09 20:52:11 -0400197 unsigned TSC,
198 float detectThreshold,
199 int sps,
200 complex &amplitude,
201 float &TOA,
Tom Tsou46569402016-03-06 01:59:38 -0800202 unsigned maxTOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000203
204/**
205 Decimate a vector.
206 @param wVector The vector of interest.
Thomas Tsou94edaae2013-11-09 22:19:19 -0500207 @param factor Decimation factor.
dburgessb3a0ca42011-10-12 07:44:40 +0000208 @return The decimated signal vector.
209*/
Thomas Tsou94edaae2013-11-09 22:19:19 -0500210signalVector *decimateVector(signalVector &wVector, size_t factor);
dburgessb3a0ca42011-10-12 07:44:40 +0000211
212/**
213 Demodulates a received burst using a soft-slicer.
214 @param rxBurst The burst to be demodulated.
215 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400216 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000217 @param channel The amplitude estimate of the received burst.
218 @param TOA The time-of-arrival of the received burst.
219 @return The demodulated bit sequence.
220*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400221SoftVector *demodulateBurst(signalVector &rxBurst, int sps,
222 complex channel, float TOA);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000223#endif /* SIGPROCLIB_H */