blob: 9bc7e10d02e3138d98dcce4714e2db71c512de38 [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 */
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
32 RACH, ///< timeslot should contain an access burst
33 EDGE, ///< timeslot should contain an EDGE burst
34 IDLE ///< timeslot is an idle (or dummy) burst
35};
36
Alexander Chemeris4aa548f2017-03-17 15:23:06 -070037enum SignalError {
Tom Tsou577cd022015-05-18 13:57:54 -070038 SIGERR_NONE,
39 SIGERR_BOUNDS,
40 SIGERR_CLIP,
41 SIGERR_UNSUPPORTED,
42 SIGERR_INTERNAL,
43};
44
Alexander Chemerisb34e60c2017-03-17 15:29:09 -070045/*
46 * Burst detection threshold
47 *
48 * Decision threshold value for burst gating on peak-to-average value of
49 * correlated synchronization sequences. Lower values pass more bursts up
50 * to upper layers but will increase the false detection rate.
51 */
52#define BURST_THRESH 4.0
53
dburgessb3a0ca42011-10-12 07:44:40 +000054/** Setup the signal processing library */
Tom Tsou2079a3c2016-03-06 00:58:56 -080055bool sigProcLibSetup();
dburgessb3a0ca42011-10-12 07:44:40 +000056
57/** Destroy the signal processing library */
58void sigProcLibDestroy(void);
59
Alexander Chemeris132fb242017-03-17 17:22:33 -070060/** Operate soft slicer on a soft-bit vector */
61bool vectorSlicer(SoftVector *x);
dburgessb3a0ca42011-10-12 07:44:40 +000062
63/** GMSK modulate a GSM burst of bits */
64signalVector *modulateBurst(const BitVector &wBurst,
Alexander Chemeris0229d222017-03-17 16:03:17 -070065 int guardPeriodLength,
66 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +000067
Tom Tsoud3253432016-03-06 03:08:01 -080068/** 8-PSK modulate a burst of bits */
69signalVector *modulateEdgeBurst(const BitVector &bits,
70 int sps, bool emptyPulse = false);
71
72/** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */
73signalVector *generateEdgeBurst(int tsc);
74
Tom Tsou8ee2f382016-03-06 20:57:34 -080075/** Generate an empty burst - 4 or 1 SPS */
76signalVector *generateEmptyBurst(int sps, int tn);
77
78/** Generate a normal GSM burst with random payload - 4 or 1 SPS */
79signalVector *genRandNormalBurst(int tsc, int sps, int tn);
80
Alexander Chemeris5efe0502016-03-23 17:06:32 +030081/** Generate an access GSM burst with random payload - 4 or 1 SPS */
Alexander Chemeris37c52c72016-03-25 18:28:34 +030082signalVector *genRandAccessBurst(int delay, int sps, int tn);
Alexander Chemeris5efe0502016-03-23 17:06:32 +030083
Tom Tsou8ee2f382016-03-06 20:57:34 -080084/** Generate a dummy GSM burst - 4 or 1 SPS */
85signalVector *generateDummyBurst(int sps, int tn);
86
dburgessb3a0ca42011-10-12 07:44:40 +000087/**
88 Apply a scalar to a vector.
89 @param x The vector of interest.
90 @param scale The scalar.
91*/
92void scaleVector(signalVector &x,
Alexander Chemeris0229d222017-03-17 16:03:17 -070093 complex scale);
dburgessb3a0ca42011-10-12 07:44:40 +000094
dburgessb3a0ca42011-10-12 07:44:40 +000095/**
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +030096 Rough energy estimator.
97 @param rxBurst A GSM burst.
dburgessb3a0ca42011-10-12 07:44:40 +000098 @param windowLength The number of burst samples used to compute burst energy
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +030099 @return The average power of the received burst.
dburgessb3a0ca42011-10-12 07:44:40 +0000100*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700101float energyDetect(const signalVector &rxBurst,
Alexander Chemeris1dd05cf2017-03-15 23:23:36 +0300102 unsigned windowLength);
Tom Tsoud3253432016-03-06 03:08:01 -0800103/**
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700104 8-PSK/GMSK/RACH burst detector
105 @param burst The received GSM burst of interest
106 @param tsc Midamble type (0..7) also known as TSC
107 @param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
108 @param sps The number of samples per GSM symbol.
109 @param amplitude The estimated amplitude of received TSC burst.
110 @param toa The estimate time-of-arrival of received TSC burst (in symbols).
111 @param max_toa The maximum expected time-of-arrival (in symbols).
112 @return positive value (CorrType) if threshold value is reached,
113 negative value (-SignalError) on error,
114 zero (SIGERR_NONE) if no burst is detected
115*/
Alexander Chemeris1470fcd2017-03-17 22:35:02 -0700116int detectAnyBurst(const signalVector &burst,
Alexander Chemeris4e6c9382017-03-17 15:24:18 -0700117 unsigned tsc,
118 float threshold,
119 int sps,
120 CorrType type,
121 complex &amp,
122 float &toa,
123 unsigned max_toa);
124
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700125/** Demodulate burst basde on type and output soft bits */
Alexander Chemerise0c12182017-03-18 13:27:48 -0700126SoftVector *demodAnyBurst(const signalVector &burst, int sps,
Alexander Chemeris6e1dffd2017-03-17 16:13:51 -0700127 complex amp, float toa, CorrType type);
128
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000129#endif /* SIGPROCLIB_H */