blob: 39c8dddc16fbdadc1444ad547c99f38bfb17d7d4 [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
Eric Wildd8a1dee2024-02-21 19:33:09 +010034 SCH,
Alexander Chemerisf9e78be2017-03-17 15:00:34 -070035 EDGE, ///< timeslot should contain an EDGE burst
36 IDLE ///< timeslot is an idle (or dummy) burst
37};
38
Alexander Chemeris4aa548f2017-03-17 15:23:06 -070039enum SignalError {
Tom Tsou577cd022015-05-18 13:57:54 -070040 SIGERR_NONE,
41 SIGERR_BOUNDS,
42 SIGERR_CLIP,
43 SIGERR_UNSUPPORTED,
44 SIGERR_INTERNAL,
45};
46
Alexander Chemerisb34e60c2017-03-17 15:29:09 -070047/*
48 * Burst detection threshold
49 *
50 * Decision threshold value for burst gating on peak-to-average value of
51 * correlated synchronization sequences. Lower values pass more bursts up
52 * to upper layers but will increase the false detection rate.
53 */
54#define BURST_THRESH 4.0
55
dburgessb3a0ca42011-10-12 07:44:40 +000056/** Setup the signal processing library */
Tom Tsou2079a3c2016-03-06 00:58:56 -080057bool sigProcLibSetup();
dburgessb3a0ca42011-10-12 07:44:40 +000058
59/** Destroy the signal processing library */
60void sigProcLibDestroy(void);
61
Alexander Chemeris132fb242017-03-17 17:22:33 -070062/** Operate soft slicer on a soft-bit vector */
Pau Espin Pedrol7dc07b92019-07-01 17:55:01 +020063void vectorSlicer(float *dest, const float *src, size_t len);
dburgessb3a0ca42011-10-12 07:44:40 +000064
65/** GMSK modulate a GSM burst of bits */
66signalVector *modulateBurst(const BitVector &wBurst,
Alexander Chemeris0229d222017-03-17 16:03:17 -070067 int guardPeriodLength,
68 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +000069
Tom Tsoud3253432016-03-06 03:08:01 -080070/** 8-PSK modulate a burst of bits */
71signalVector *modulateEdgeBurst(const BitVector &bits,
72 int sps, bool emptyPulse = false);
73
74/** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */
75signalVector *generateEdgeBurst(int tsc);
76
Tom Tsou8ee2f382016-03-06 20:57:34 -080077/** Generate an empty burst - 4 or 1 SPS */
78signalVector *generateEmptyBurst(int sps, int tn);
79
80/** Generate a normal GSM burst with random payload - 4 or 1 SPS */
81signalVector *genRandNormalBurst(int tsc, int sps, int tn);
82
Alexander Chemeris5efe0502016-03-23 17:06:32 +030083/** Generate an access GSM burst with random payload - 4 or 1 SPS */
Alexander Chemeris37c52c72016-03-25 18:28:34 +030084signalVector *genRandAccessBurst(int delay, int sps, int tn);
Alexander Chemeris5efe0502016-03-23 17:06:32 +030085
Tom Tsou8ee2f382016-03-06 20:57:34 -080086/** Generate a dummy GSM burst - 4 or 1 SPS */
87signalVector *generateDummyBurst(int sps, int tn);
88
dburgessb3a0ca42011-10-12 07:44:40 +000089/**
90 Apply a scalar to a vector.
91 @param x The vector of interest.
92 @param scale The scalar.
93*/
94void scaleVector(signalVector &x,
Alexander Chemeris0229d222017-03-17 16:03:17 -070095 complex scale);
dburgessb3a0ca42011-10-12 07:44:40 +000096
Eric Wildd8a1dee2024-02-21 19:33:09 +010097signalVector *delayVector(const signalVector *in, signalVector *out, float delay);
98
dburgessb3a0ca42011-10-12 07:44:40 +000099/**
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300100 Rough energy estimator.
101 @param rxBurst A GSM burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000102 @param windowLength The number of burst samples used to compute burst energy
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300103 @return The average power of the received burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000104*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700105float energyDetect(const signalVector &rxBurst,
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300106 unsigned windowLength);
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200107
108/** Struct used to fill out parameters in detectAnyBurst(): estimated burst parameters
109@param amplitude The estimated amplitude of received TSC burst.
110@param toa The estimated time-of-arrival of received TSC burst (in symbols).
Pau Espin Pedrolc3d68c12019-07-04 16:27:47 +0200111@param tsc The TSC used to detect the burst.
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200112*/
113struct estim_burst_params {
114 complex amp;
115 float toa;
Pau Espin Pedrolc3d68c12019-07-04 16:27:47 +0200116 uint8_t tsc;
Sylvain Munautb49a42e2019-05-14 18:23:29 +0200117 float ci;
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200118};
Tom Tsoud3253432016-03-06 03:08:01 -0800119/**
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700120 8-PSK/GMSK/RACH burst detector
121 @param burst The received GSM burst of interest
122 @param tsc Midamble type (0..7) also known as TSC
123 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
124 @param sps The number of samples per GSM symbol.
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700125 @param max_toa The maximum expected time-of-arrival (in symbols).
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200126 @param ebp The estimated parameters of the detected burst.
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700127 @return positive value (CorrType) if threshold value is reached,
128 negative value (-SignalError) on error,
129 zero (SIGERR_NONE) if no burst is detected
130*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700131int detectAnyBurst(const signalVector &burst,
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700132 unsigned tsc,
133 float threshold,
134 int sps,
135 CorrType type,
Pau Espin Pedrol7ee2d102019-07-04 13:02:12 +0200136 unsigned max_toa,
137 struct estim_burst_params *ebp);
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700138
Eric Wildd8a1dee2024-02-21 19:33:09 +0100139enum class sch_detect_type {
140 SCH_DETECT_FULL,
141 SCH_DETECT_NARROW,
142 SCH_DETECT_BUFFER,
143};
144
145int detectSCHBurst(signalVector &rxBurst,
146 float detectThreshold,
147 int sps,
148 sch_detect_type state, struct estim_burst_params *ebp);
149
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700150/** Demodulate burst basde on type and output soft bits */
Sylvain Munautad202d72021-02-04 20:37:01 +0100151SoftVector *demodAnyBurst(const signalVector &burst, CorrType type,
152 int sps, struct estim_burst_params *ebp);
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700153
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000154#endif /* SIGPROCLIB_H */