blob: dd03190520a4a3a675e49d864c449db32c2e1904 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
2* Copyright 2008 Free Software Foundation, Inc.
3*
Martin Hauke066fd042019-10-13 19:08:00 +02004* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribution.
dburgessb3a0ca42011-10-12 07:44:40 +00005*
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 */
Alexander Chemeris0229d222017-03-17 16:03:17 -070024#define NORMAL_BURST_NBITS 148
25#define EDGE_BURST_NBITS 444
26#define EDGE_BURST_NSYMS (EDGE_BURST_NBITS / 3)
Tom Tsoub0aefcb2016-03-06 03:44:34 -080027
Alexander Chemerisf9e78be2017-03-17 15:00:34 -070028/** Codes for burst types of received bursts*/
29enum CorrType{
30 OFF, ///< timeslot is off
31 TSC, ///< timeslot should contain a normal burst
Vadim Yanitskiy444ff342018-10-22 02:25:23 +020032 EXT_RACH, ///< timeslot should contain an extended access burst
Alexander Chemerisf9e78be2017-03-17 15:00:34 -070033 RACH, ///< timeslot should contain an access burst
34 EDGE, ///< timeslot should contain an EDGE burst
35 IDLE ///< timeslot is an idle (or dummy) burst
36};
37
Alexander Chemeris4aa548f2017-03-17 15:23:06 -070038enum SignalError {
Tom Tsou577cd022015-05-18 13:57:54 -070039 SIGERR_NONE,
40 SIGERR_BOUNDS,
41 SIGERR_CLIP,
42 SIGERR_UNSUPPORTED,
43 SIGERR_INTERNAL,
44};
45
Alexander Chemerisb34e60c2017-03-17 15:29:09 -070046/*
47 * Burst detection threshold
48 *
49 * Decision threshold value for burst gating on peak-to-average value of
50 * correlated synchronization sequences. Lower values pass more bursts up
51 * to upper layers but will increase the false detection rate.
52 */
53#define BURST_THRESH 4.0
54
dburgessb3a0ca42011-10-12 07:44:40 +000055/** Setup the signal processing library */
Tom Tsou2079a3c2016-03-06 00:58:56 -080056bool sigProcLibSetup();
dburgessb3a0ca42011-10-12 07:44:40 +000057
58/** Destroy the signal processing library */
59void sigProcLibDestroy(void);
60
Alexander Chemeris132fb242017-03-17 17:22:33 -070061/** Operate soft slicer on a soft-bit vector */
Pau Espin Pedrol7dc07b92019-07-01 17:55:01 +020062void vectorSlicer(float *dest, const float *src, size_t len);
dburgessb3a0ca42011-10-12 07:44:40 +000063
64/** GMSK modulate a GSM burst of bits */
65signalVector *modulateBurst(const BitVector &wBurst,
Alexander Chemeris0229d222017-03-17 16:03:17 -070066 int guardPeriodLength,
67 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +000068
Tom Tsoud3253432016-03-06 03:08:01 -080069/** 8-PSK modulate a burst of bits */
70signalVector *modulateEdgeBurst(const BitVector &bits,
71 int sps, bool emptyPulse = false);
72
73/** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */
74signalVector *generateEdgeBurst(int tsc);
75
Tom Tsou8ee2f382016-03-06 20:57:34 -080076/** Generate an empty burst - 4 or 1 SPS */
77signalVector *generateEmptyBurst(int sps, int tn);
78
79/** Generate a normal GSM burst with random payload - 4 or 1 SPS */
80signalVector *genRandNormalBurst(int tsc, int sps, int tn);
81
Alexander Chemeris5efe0502016-03-23 17:06:32 +030082/** Generate an access GSM burst with random payload - 4 or 1 SPS */
Alexander Chemeris37c52c72016-03-25 18:28:34 +030083signalVector *genRandAccessBurst(int delay, int sps, int tn);
Alexander Chemeris5efe0502016-03-23 17:06:32 +030084
Tom Tsou8ee2f382016-03-06 20:57:34 -080085/** Generate a dummy GSM burst - 4 or 1 SPS */
86signalVector *generateDummyBurst(int sps, int tn);
87
dburgessb3a0ca42011-10-12 07:44:40 +000088/**
89 Apply a scalar to a vector.
90 @param x The vector of interest.
91 @param scale The scalar.
92*/
93void scaleVector(signalVector &x,
Alexander Chemeris0229d222017-03-17 16:03:17 -070094 complex scale);
dburgessb3a0ca42011-10-12 07:44:40 +000095
dburgessb3a0ca42011-10-12 07:44:40 +000096/**
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +030097 Rough energy estimator.
98 @param rxBurst A GSM burst.
dburgessb3a0ca42011-10-12 07:44:40 +000099 @param windowLength The number of burst samples used to compute burst energy
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300100 @return The average power of the received burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000101*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700102float energyDetect(const signalVector &rxBurst,
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300103 unsigned windowLength);
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200104
105/** Struct used to fill out parameters in detectAnyBurst(): estimated burst parameters
106@param amplitude The estimated amplitude of received TSC burst.
107@param toa The estimated time-of-arrival of received TSC burst (in symbols).
Pau Espin Pedrolc3d68c12019-07-04 16:27:47 +0200108@param tsc The TSC used to detect the burst.
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200109*/
110struct estim_burst_params {
111 complex amp;
112 float toa;
Pau Espin Pedrolc3d68c12019-07-04 16:27:47 +0200113 uint8_t tsc;
Sylvain Munautb49a42e2019-05-14 18:23:29 +0200114 float ci;
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200115};
Tom Tsoud3253432016-03-06 03:08:01 -0800116/**
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700117 8-PSK/GMSK/RACH burst detector
118 @param burst The received GSM burst of interest
119 @param tsc Midamble type (0..7) also known as TSC
120 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
121 @param sps The number of samples per GSM symbol.
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700122 @param max_toa The maximum expected time-of-arrival (in symbols).
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200123 @param ebp The estimated parameters of the detected burst.
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700124 @return positive value (CorrType) if threshold value is reached,
125 negative value (-SignalError) on error,
126 zero (SIGERR_NONE) if no burst is detected
127*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700128int detectAnyBurst(const signalVector &burst,
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700129 unsigned tsc,
130 float threshold,
131 int sps,
132 CorrType type,
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200133 unsigned max_toa,
134 struct estim_burst_params *ebp);
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700135
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700136/** Demodulate burst basde on type and output soft bits */
Alexander Chemerise0c12182017-03-18 13:27:48 -0700137SoftVector *demodAnyBurst(const signalVector &burst, int sps,
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700138 complex amp, float toa, CorrType type);
139
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000140#endif /* SIGPROCLIB_H */