blob: 7dedee423e0adb4d8acabc8d664d843cb83fc973 [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
dburgessb3a0ca42011-10-12 07:44:40 +0000149/**
150 Generate a modulated GSM midamble, stored within the library.
151 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400152 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000153 @param TSC The training sequence [0..7]
154 @return Success.
155*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400156bool generateMidamble(int sps, int tsc);
dburgessb3a0ca42011-10-12 07:44:40 +0000157/**
158 Generate a modulated RACH sequence, 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 @return Success.
162*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400163bool generateRACHSequence(int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000164
165/**
166 Energy detector, checks to see if received burst energy is above a threshold.
167 @param rxBurst The received GSM burst of interest.
168 @param windowLength The number of burst samples used to compute burst energy
169 @param detectThreshold The detection threshold, a linear value.
170 @param avgPwr The average power of the received burst.
171 @return True if burst energy is above threshold.
172*/
173bool energyDetect(signalVector &rxBurst,
174 unsigned windowLength,
175 float detectThreshold,
176 float *avgPwr = NULL);
177
178/**
179 RACH correlator/detector.
180 @param rxBurst The received GSM burst of interest.
181 @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 -0400182 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000183 @param amplitude The estimated amplitude of received RACH burst.
184 @param TOA The estimate time-of-arrival of received RACH burst.
Thomas Tsou3eaae802013-08-20 19:31:14 -0400185 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000186*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400187int detectRACHBurst(signalVector &rxBurst,
188 float detectThreshold,
189 int sps,
190 complex *amplitude,
191 float* TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000192
193/**
194 Normal burst correlator, detector, channel estimator.
195 @param rxBurst The received GSM burst of interest.
196
197 @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 -0400198 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000199 @param amplitude The estimated amplitude of received TSC burst.
200 @param TOA The estimate time-of-arrival of received TSC burst.
201 @param maxTOA The maximum expected time-of-arrival
202 @param requestChannel Set to true if channel estimation is desired.
203 @param channelResponse The estimated channel.
204 @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 -0400205 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000206*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400207int analyzeTrafficBurst(signalVector &rxBurst,
208 unsigned TSC,
209 float detectThreshold,
210 int sps,
211 complex *amplitude,
212 float *TOA,
213 unsigned maxTOA,
214 bool requestChannel = false,
215 signalVector** channelResponse = NULL,
216 float *channelResponseOffset = NULL);
dburgessb3a0ca42011-10-12 07:44:40 +0000217
218/**
219 Decimate a vector.
220 @param wVector The vector of interest.
Thomas Tsou94edaae2013-11-09 22:19:19 -0500221 @param factor Decimation factor.
dburgessb3a0ca42011-10-12 07:44:40 +0000222 @return The decimated signal vector.
223*/
Thomas Tsou94edaae2013-11-09 22:19:19 -0500224signalVector *decimateVector(signalVector &wVector, size_t factor);
dburgessb3a0ca42011-10-12 07:44:40 +0000225
226/**
227 Demodulates a received burst using a soft-slicer.
228 @param rxBurst The burst to be demodulated.
229 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400230 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000231 @param channel The amplitude estimate of the received burst.
232 @param TOA The time-of-arrival of the received burst.
233 @return The demodulated bit sequence.
234*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400235SoftVector *demodulateBurst(signalVector &rxBurst, int sps,
236 complex channel, float TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000237
238/**
dburgessb3a0ca42011-10-12 07:44:40 +0000239 Design the necessary filters for a decision-feedback equalizer.
240 @param channelResponse The multipath channel that we're mitigating.
241 @param SNRestimate The signal-to-noise estimate of the channel, a linear value
242 @param Nf The number of taps in the feedforward filter.
243 @param feedForwardFilter The designed feed forward filter.
244 @param feedbackFilter The designed feedback filter.
245 @return True if DFE can be designed.
246*/
247bool designDFE(signalVector &channelResponse,
248 float SNRestimate,
249 int Nf,
250 signalVector **feedForwardFilter,
251 signalVector **feedbackFilter);
252
253/**
254 Equalize/demodulate a received burst via a decision-feedback equalizer.
255 @param rxBurst The received burst to be demodulated.
256 @param TOA The time-of-arrival of the received burst.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400257 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000258 @param w The feed forward filter of the DFE.
259 @param b The feedback filter of the DFE.
260 @return The demodulated bit sequence.
261*/
262SoftVector *equalizeBurst(signalVector &rxBurst,
263 float TOA,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400264 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000265 signalVector &w,
266 signalVector &b);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000267
268#endif /* SIGPROCLIB_H */