blob: 211e1a902632085c3b79dc03b31829d6e7ebdb4f [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
Tom Tsoub0aefcb2016-03-06 03:44:34 -080023/* Burst lengths */
24#define NORMAL_BURST_NBITS 148
25#define EDGE_BURST_NBITS 444
26#define EDGE_BURST_NSYMS (EDGE_BURST_NBITS / 3)
27
dburgessb3a0ca42011-10-12 07:44:40 +000028/** Convolution type indicator */
kurtis.heimerl3b8ad242011-11-26 03:18:19 +000029enum ConvType {
Thomas Tsou3eaae802013-08-20 19:31:14 -040030 START_ONLY,
31 NO_DELAY,
32 CUSTOM,
33 UNDEFINED,
dburgessb3a0ca42011-10-12 07:44:40 +000034};
35
Alexander Chemerisf9e78be2017-03-17 15:00:34 -070036/** Codes for burst types of received bursts*/
37enum CorrType{
38 OFF, ///< timeslot is off
39 TSC, ///< timeslot should contain a normal burst
40 RACH, ///< timeslot should contain an access burst
41 EDGE, ///< timeslot should contain an EDGE burst
42 IDLE ///< timeslot is an idle (or dummy) burst
43};
44
Tom Tsou577cd022015-05-18 13:57:54 -070045enum signalError {
46 SIGERR_NONE,
47 SIGERR_BOUNDS,
48 SIGERR_CLIP,
49 SIGERR_UNSUPPORTED,
50 SIGERR_INTERNAL,
51};
52
dburgessb3a0ca42011-10-12 07:44:40 +000053/** Convert a linear number to a dB value */
54float dB(float x);
55
56/** Convert a dB value into a linear value */
57float dBinv(float x);
58
59/** Compute the energy of a vector */
60float vectorNorm2(const signalVector &x);
61
62/** Compute the average power of a vector */
63float vectorPower(const signalVector &x);
64
65/** Setup the signal processing library */
Tom Tsou2079a3c2016-03-06 00:58:56 -080066bool sigProcLibSetup();
dburgessb3a0ca42011-10-12 07:44:40 +000067
68/** Destroy the signal processing library */
69void sigProcLibDestroy(void);
70
71/**
72 Convolve two vectors.
73 @param a,b The vectors to be convolved.
74 @param c, A preallocated vector to hold the convolution result.
75 @param spanType The type/span of the convolution.
Thomas Tsou3eaae802013-08-20 19:31:14 -040076 @return The convolution result or NULL on error.
dburgessb3a0ca42011-10-12 07:44:40 +000077*/
Thomas Tsou3f32ab52013-11-15 16:32:54 -050078signalVector *convolve(const signalVector *a, const signalVector *b,
79 signalVector *c, ConvType spanType,
80 size_t start = 0, size_t len = 0,
81 size_t step = 1, int offset = 0);
dburgessb3a0ca42011-10-12 07:44:40 +000082
83/**
dburgessb3a0ca42011-10-12 07:44:40 +000084 Frequency shift a vector.
85 @param y The frequency shifted vector.
86 @param x The vector to-be-shifted.
87 @param freq The digital frequency shift
88 @param startPhase The starting phase of the oscillator
89 @param finalPhase The final phase of the oscillator
90 @return The frequency shifted vector.
91*/
92signalVector* frequencyShift(signalVector *y,
93 signalVector *x,
94 float freq = 0.0,
95 float startPhase = 0.0,
96 float *finalPhase=NULL);
97
98/**
99 Correlate two vectors.
100 @param a,b The vectors to be correlated.
101 @param c, A preallocated vector to hold the correlation result.
102 @param spanType The type/span of the correlation.
103 @return The correlation result.
104*/
105signalVector* correlate(signalVector *a,
106 signalVector *b,
107 signalVector *c,
108 ConvType spanType,
109 bool bReversedConjugated = false,
110 unsigned startIx = 0,
111 unsigned len = 0);
112
Alexander Chemeris132fb242017-03-17 17:22:33 -0700113/** Operate soft slicer on a soft-bit vector */
114bool vectorSlicer(SoftVector *x);
dburgessb3a0ca42011-10-12 07:44:40 +0000115
116/** GMSK modulate a GSM burst of bits */
117signalVector *modulateBurst(const BitVector &wBurst,
dburgessb3a0ca42011-10-12 07:44:40 +0000118 int guardPeriodLength,
Thomas Tsou83e06892013-08-20 16:10:01 -0400119 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +0000120
Tom Tsoud3253432016-03-06 03:08:01 -0800121/** 8-PSK modulate a burst of bits */
122signalVector *modulateEdgeBurst(const BitVector &bits,
123 int sps, bool emptyPulse = false);
124
125/** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */
126signalVector *generateEdgeBurst(int tsc);
127
Tom Tsou8ee2f382016-03-06 20:57:34 -0800128/** Generate an empty burst - 4 or 1 SPS */
129signalVector *generateEmptyBurst(int sps, int tn);
130
131/** Generate a normal GSM burst with random payload - 4 or 1 SPS */
132signalVector *genRandNormalBurst(int tsc, int sps, int tn);
133
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300134/** Generate an access GSM burst with random payload - 4 or 1 SPS */
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300135signalVector *genRandAccessBurst(int delay, int sps, int tn);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300136
Tom Tsou8ee2f382016-03-06 20:57:34 -0800137/** Generate a dummy GSM burst - 4 or 1 SPS */
138signalVector *generateDummyBurst(int sps, int tn);
139
dburgessb3a0ca42011-10-12 07:44:40 +0000140/** Sinc function */
141float sinc(float x);
142
143/** Delay a vector */
Thomas Tsou94edaae2013-11-09 22:19:19 -0500144signalVector *delayVector(signalVector *in, signalVector *out, float delay);
dburgessb3a0ca42011-10-12 07:44:40 +0000145
146/** Add two vectors in-place */
147bool addVector(signalVector &x,
148 signalVector &y);
149
150/** Multiply two vectors in-place*/
151bool multVector(signalVector &x,
152 signalVector &y);
153
154/** Generate a vector of gaussian noise */
155signalVector *gaussianNoise(int length,
156 float variance = 1.0,
157 complex mean = complex(0.0));
158
159/**
160 Given a non-integer index, interpolate a sample.
161 @param inSig The signal from which to interpolate.
162 @param ix The index.
163 @return The interpolated signal value.
164*/
165complex interpolatePoint(const signalVector &inSig,
166 float ix);
167
168/**
169 Given a correlator output, locate the correlation peak.
170 @param rxBurst The correlator result.
171 @param peakIndex Pointer to value to receive interpolated peak index.
172 @param avgPower Power to value to receive mean power.
173 @return Peak value.
174*/
175complex peakDetect(const signalVector &rxBurst,
176 float *peakIndex,
177 float *avgPwr);
178
179/**
180 Apply a scalar to a vector.
181 @param x The vector of interest.
182 @param scale The scalar.
183*/
184void scaleVector(signalVector &x,
185 complex scale);
186
dburgessb3a0ca42011-10-12 07:44:40 +0000187/**
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300188 Rough energy estimator.
189 @param rxBurst A GSM burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000190 @param windowLength The number of burst samples used to compute burst energy
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300191 @return The average power of the received burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000192*/
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300193float energyDetect(signalVector &rxBurst,
194 unsigned windowLength);
dburgessb3a0ca42011-10-12 07:44:40 +0000195
196/**
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700197 RACH aka Access Burst correlator/detector.
198 @param burst The received GSM burst of interest.
199 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400200 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000201 @param amplitude The estimated amplitude of received RACH burst.
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700202 @param toa The estimate time-of-arrival of received RACH burst.
203 @param max_toa The maximum expected time-of-arrival
204 @return 1 if threshold value is reached,
205 negative value (-SignalError) on error,
206 zero (SIGERR_NONE) if no burst is detected
dburgessb3a0ca42011-10-12 07:44:40 +0000207*/
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700208int detectRACHBurst(signalVector &burst,
209 float threshold,
Thomas Tsou3eaae802013-08-20 19:31:14 -0400210 int sps,
Alexander Chemeris130a8002015-06-09 20:52:11 -0400211 complex &amplitude,
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700212 float &toa,
213 unsigned max_toa);
dburgessb3a0ca42011-10-12 07:44:40 +0000214
215/**
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700216 GMSK Normal Burst correlator/detector.
dburgessb3a0ca42011-10-12 07:44:40 +0000217 @param rxBurst The received GSM burst of interest.
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700218 @param tsc Midamble type (0..7) also known as TSC
219 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400220 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000221 @param amplitude The estimated amplitude of received TSC burst.
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700222 @param toa The estimate time-of-arrival of received TSC burst.
223 @param max_toa The maximum expected time-of-arrival
224 @return 1 if threshold value is reached,
225 negative value (-SignalError) on error,
226 zero (SIGERR_NONE) if no burst is detected
dburgessb3a0ca42011-10-12 07:44:40 +0000227*/
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700228int analyzeTrafficBurst(signalVector &burst,
229 unsigned tsc,
230 float threshold,
Alexander Chemeris130a8002015-06-09 20:52:11 -0400231 int sps,
232 complex &amplitude,
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700233 float &toa,
234 unsigned max_toa);
dburgessb3a0ca42011-10-12 07:44:40 +0000235
236/**
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700237 EDGE/8-PSK Normal Burst correlator/detector
Tom Tsoud3253432016-03-06 03:08:01 -0800238 @param burst The received GSM burst of interest
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700239 @param tsc Midamble type (0..7) also known as TSC
240 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
Tom Tsoud3253432016-03-06 03:08:01 -0800241 @param sps The number of samples per GSM symbol.
242 @param amplitude The estimated amplitude of received TSC burst.
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700243 @param toa The estimate time-of-arrival of received TSC burst.
244 @param max_toa The maximum expected time-of-arrival
245 @return 1 if threshold value is reached,
246 negative value (-SignalError) on error,
247 zero (SIGERR_NONE) if no burst is detected
Tom Tsoud3253432016-03-06 03:08:01 -0800248*/
249int detectEdgeBurst(signalVector &burst,
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700250 unsigned tsc,
251 float threshold,
Tom Tsoud3253432016-03-06 03:08:01 -0800252 int sps,
253 complex &amplitude,
Alexander Chemeris14d13b62017-03-17 15:12:17 -0700254 float &toa,
255 unsigned max_toa);
Tom Tsoud3253432016-03-06 03:08:01 -0800256
257/**
258 Downsample 4 SPS to 1 SPS using a polyphase filterbank
259 @param burst Input burst of at least 624 symbols
260 @return Decimated signal vector of 156 symbols
261*/
Tom Tsoud3253432016-03-06 03:08:01 -0800262signalVector *downsampleBurst(signalVector &burst);
263
264/**
dburgessb3a0ca42011-10-12 07:44:40 +0000265 Decimate a vector.
266 @param wVector The vector of interest.
Thomas Tsou94edaae2013-11-09 22:19:19 -0500267 @param factor Decimation factor.
dburgessb3a0ca42011-10-12 07:44:40 +0000268 @return The decimated signal vector.
269*/
Thomas Tsou94edaae2013-11-09 22:19:19 -0500270signalVector *decimateVector(signalVector &wVector, size_t factor);
dburgessb3a0ca42011-10-12 07:44:40 +0000271
272/**
Alexander Chemeris1c0b8b32017-03-17 16:12:47 -0700273 Demodulates a GMSK burst using a soft-slicer.
274 @param rxBurst The burst to be demodulated.
dburgessb3a0ca42011-10-12 07:44:40 +0000275 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400276 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000277 @param channel The amplitude estimate of the received burst.
278 @param TOA The time-of-arrival of the received burst.
279 @return The demodulated bit sequence.
280*/
Alexander Chemeris1c0b8b32017-03-17 16:12:47 -0700281SoftVector *demodGmskBurst(signalVector &rxBurst, int sps,
282 complex channel, float TOA);
Tom Tsoud3253432016-03-06 03:08:01 -0800283
284/**
285 Demodulate 8-PSK EDGE burst with soft symbol ooutput
286 @param rxBurst The burst to be demodulated.
287 @param sps The number of samples per GSM symbol.
288 @param channel The amplitude estimate of the received burst.
289 @param TOA The time-of-arrival of the received burst.
290 @return The demodulated bit sequence.
291*/
292SoftVector *demodEdgeBurst(signalVector &rxBurst, int sps,
293 complex channel, float TOA);
294
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000295#endif /* SIGPROCLIB_H */