blob: 4df7b3f0d85e3f0af40f259f2b95ab8f79634627 [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
dburgessb3a0ca42011-10-12 07:44:40 +000031/** Convert a linear number to a dB value */
32float dB(float x);
33
34/** Convert a dB value into a linear value */
35float dBinv(float x);
36
37/** Compute the energy of a vector */
38float vectorNorm2(const signalVector &x);
39
40/** Compute the average power of a vector */
41float vectorPower(const signalVector &x);
42
43/** Setup the signal processing library */
Thomas Tsoue57004d2013-08-20 18:55:33 -040044bool sigProcLibSetup(int sps);
dburgessb3a0ca42011-10-12 07:44:40 +000045
46/** Destroy the signal processing library */
47void sigProcLibDestroy(void);
48
49/**
50 Convolve two vectors.
51 @param a,b The vectors to be convolved.
52 @param c, A preallocated vector to hold the convolution result.
53 @param spanType The type/span of the convolution.
Thomas Tsou3eaae802013-08-20 19:31:14 -040054 @return The convolution result or NULL on error.
dburgessb3a0ca42011-10-12 07:44:40 +000055*/
Thomas Tsou3eaae802013-08-20 19:31:14 -040056signalVector *convolve(const signalVector *a,
57 const signalVector *b,
58 signalVector *c,
59 ConvType spanType,
60 int start = 0,
61 unsigned len = 0,
62 unsigned step = 1, int offset = 0);
dburgessb3a0ca42011-10-12 07:44:40 +000063
64/**
dburgessb3a0ca42011-10-12 07:44:40 +000065 Frequency shift a vector.
66 @param y The frequency shifted vector.
67 @param x The vector to-be-shifted.
68 @param freq The digital frequency shift
69 @param startPhase The starting phase of the oscillator
70 @param finalPhase The final phase of the oscillator
71 @return The frequency shifted vector.
72*/
73signalVector* frequencyShift(signalVector *y,
74 signalVector *x,
75 float freq = 0.0,
76 float startPhase = 0.0,
77 float *finalPhase=NULL);
78
79/**
80 Correlate two vectors.
81 @param a,b The vectors to be correlated.
82 @param c, A preallocated vector to hold the correlation result.
83 @param spanType The type/span of the correlation.
84 @return The correlation result.
85*/
86signalVector* correlate(signalVector *a,
87 signalVector *b,
88 signalVector *c,
89 ConvType spanType,
90 bool bReversedConjugated = false,
91 unsigned startIx = 0,
92 unsigned len = 0);
93
94/** Operate soft slicer on real-valued portion of vector */
95bool vectorSlicer(signalVector *x);
96
97/** GMSK modulate a GSM burst of bits */
98signalVector *modulateBurst(const BitVector &wBurst,
dburgessb3a0ca42011-10-12 07:44:40 +000099 int guardPeriodLength,
Thomas Tsou83e06892013-08-20 16:10:01 -0400100 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +0000101
102/** Sinc function */
103float sinc(float x);
104
105/** Delay a vector */
Thomas Tsou94edaae2013-11-09 22:19:19 -0500106signalVector *delayVector(signalVector *in, signalVector *out, float delay);
dburgessb3a0ca42011-10-12 07:44:40 +0000107
108/** Add two vectors in-place */
109bool addVector(signalVector &x,
110 signalVector &y);
111
112/** Multiply two vectors in-place*/
113bool multVector(signalVector &x,
114 signalVector &y);
115
116/** Generate a vector of gaussian noise */
117signalVector *gaussianNoise(int length,
118 float variance = 1.0,
119 complex mean = complex(0.0));
120
121/**
122 Given a non-integer index, interpolate a sample.
123 @param inSig The signal from which to interpolate.
124 @param ix The index.
125 @return The interpolated signal value.
126*/
127complex interpolatePoint(const signalVector &inSig,
128 float ix);
129
130/**
131 Given a correlator output, locate the correlation peak.
132 @param rxBurst The correlator result.
133 @param peakIndex Pointer to value to receive interpolated peak index.
134 @param avgPower Power to value to receive mean power.
135 @return Peak value.
136*/
137complex peakDetect(const signalVector &rxBurst,
138 float *peakIndex,
139 float *avgPwr);
140
141/**
142 Apply a scalar to a vector.
143 @param x The vector of interest.
144 @param scale The scalar.
145*/
146void scaleVector(signalVector &x,
147 complex scale);
148
149/**
150 Add a constant offset to a vecotr.
151 @param x The vector of interest.
152 @param offset The offset.
153*/
154void offsetVector(signalVector &x,
155 complex offset);
156
157/**
158 Generate a modulated GSM midamble, stored within the library.
159 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400160 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000161 @param TSC The training sequence [0..7]
162 @return Success.
163*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400164bool generateMidamble(int sps, int tsc);
dburgessb3a0ca42011-10-12 07:44:40 +0000165/**
166 Generate a modulated RACH sequence, stored within the library.
167 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400168 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000169 @return Success.
170*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400171bool generateRACHSequence(int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000172
173/**
174 Energy detector, checks to see if received burst energy is above a threshold.
175 @param rxBurst The received GSM burst of interest.
176 @param windowLength The number of burst samples used to compute burst energy
177 @param detectThreshold The detection threshold, a linear value.
178 @param avgPwr The average power of the received burst.
179 @return True if burst energy is above threshold.
180*/
181bool energyDetect(signalVector &rxBurst,
182 unsigned windowLength,
183 float detectThreshold,
184 float *avgPwr = NULL);
185
186/**
187 RACH correlator/detector.
188 @param rxBurst The received GSM burst of interest.
189 @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 -0400190 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000191 @param amplitude The estimated amplitude of received RACH burst.
192 @param TOA The estimate time-of-arrival of received RACH burst.
Thomas Tsou3eaae802013-08-20 19:31:14 -0400193 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000194*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400195int detectRACHBurst(signalVector &rxBurst,
196 float detectThreshold,
197 int sps,
198 complex *amplitude,
199 float* TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000200
201/**
202 Normal burst correlator, detector, channel estimator.
203 @param rxBurst The received GSM burst of interest.
204
205 @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 -0400206 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000207 @param amplitude The estimated amplitude of received TSC burst.
208 @param TOA The estimate time-of-arrival of received TSC burst.
209 @param maxTOA The maximum expected time-of-arrival
210 @param requestChannel Set to true if channel estimation is desired.
211 @param channelResponse The estimated channel.
212 @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 -0400213 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000214*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400215int analyzeTrafficBurst(signalVector &rxBurst,
216 unsigned TSC,
217 float detectThreshold,
218 int sps,
219 complex *amplitude,
220 float *TOA,
221 unsigned maxTOA,
222 bool requestChannel = false,
223 signalVector** channelResponse = NULL,
224 float *channelResponseOffset = NULL);
dburgessb3a0ca42011-10-12 07:44:40 +0000225
226/**
227 Decimate a vector.
228 @param wVector The vector of interest.
Thomas Tsou94edaae2013-11-09 22:19:19 -0500229 @param factor Decimation factor.
dburgessb3a0ca42011-10-12 07:44:40 +0000230 @return The decimated signal vector.
231*/
Thomas Tsou94edaae2013-11-09 22:19:19 -0500232signalVector *decimateVector(signalVector &wVector, size_t factor);
dburgessb3a0ca42011-10-12 07:44:40 +0000233
234/**
235 Demodulates a received burst using a soft-slicer.
236 @param rxBurst The burst to be demodulated.
237 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400238 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000239 @param channel The amplitude estimate of the received burst.
240 @param TOA The time-of-arrival of the received burst.
241 @return The demodulated bit sequence.
242*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400243SoftVector *demodulateBurst(signalVector &rxBurst, int sps,
244 complex channel, float TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000245
246/**
dburgessb3a0ca42011-10-12 07:44:40 +0000247 Design the necessary filters for a decision-feedback equalizer.
248 @param channelResponse The multipath channel that we're mitigating.
249 @param SNRestimate The signal-to-noise estimate of the channel, a linear value
250 @param Nf The number of taps in the feedforward filter.
251 @param feedForwardFilter The designed feed forward filter.
252 @param feedbackFilter The designed feedback filter.
253 @return True if DFE can be designed.
254*/
255bool designDFE(signalVector &channelResponse,
256 float SNRestimate,
257 int Nf,
258 signalVector **feedForwardFilter,
259 signalVector **feedbackFilter);
260
261/**
262 Equalize/demodulate a received burst via a decision-feedback equalizer.
263 @param rxBurst The received burst to be demodulated.
264 @param TOA The time-of-arrival of the received burst.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400265 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000266 @param w The feed forward filter of the DFE.
267 @param b The feedback filter of the DFE.
268 @return The demodulated bit sequence.
269*/
270SoftVector *equalizeBurst(signalVector &rxBurst,
271 float TOA,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400272 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000273 signalVector &w,
274 signalVector &b);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000275
276#endif /* SIGPROCLIB_H */