blob: e91644c75a2fe1a4d2d6f2ed274019b02c7e696c [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"
dburgessb3a0ca42011-10-12 07:44:40 +000021
22/** Indicated signalVector symmetry */
kurtis.heimerl3b8ad242011-11-26 03:18:19 +000023enum Symmetry {
dburgessb3a0ca42011-10-12 07:44:40 +000024 NONE = 0,
25 ABSSYM = 1
26};
27
28/** Convolution type indicator */
kurtis.heimerl3b8ad242011-11-26 03:18:19 +000029enum ConvType {
dburgessb3a0ca42011-10-12 07:44:40 +000030 FULL_SPAN = 0,
31 OVERLAP_ONLY = 1,
32 START_ONLY = 2,
33 WITH_TAIL = 3,
34 NO_DELAY = 4,
35 CUSTOM = 5,
36 UNDEFINED = 255
37};
38
39/** the core data structure of the Transceiver */
40class signalVector: public Vector<complex>
41{
42
43 private:
44
45 Symmetry symmetry; ///< the symmetry of the vector
46 bool realOnly; ///< true if vector is real-valued, not complex-valued
47
48 public:
49
50 /** Constructors */
51 signalVector(int dSize=0, Symmetry wSymmetry = NONE):
52 Vector<complex>(dSize),
53 realOnly(false)
54 {
55 symmetry = wSymmetry;
56 };
57
58 signalVector(complex* wData, size_t start,
59 size_t span, Symmetry wSymmetry = NONE):
60 Vector<complex>(NULL,wData+start,wData+start+span),
61 realOnly(false)
62 {
63 symmetry = wSymmetry;
64 };
65
66 signalVector(const signalVector &vec1, const signalVector &vec2):
67 Vector<complex>(vec1,vec2),
68 realOnly(false)
69 {
70 symmetry = vec1.symmetry;
71 };
72
73 signalVector(const signalVector &wVector):
74 Vector<complex>(wVector.size()),
75 realOnly(false)
76 {
77 wVector.copyTo(*this);
78 symmetry = wVector.getSymmetry();
79 };
80
81 /** symmetry operators */
82 Symmetry getSymmetry() const { return symmetry;};
83 void setSymmetry(Symmetry wSymmetry) { symmetry = wSymmetry;};
84
85 /** real-valued operators */
86 bool isRealOnly() const { return realOnly;};
87 void isRealOnly(bool wOnly) { realOnly = wOnly;};
88};
89
90/** Convert a linear number to a dB value */
91float dB(float x);
92
93/** Convert a dB value into a linear value */
94float dBinv(float x);
95
96/** Compute the energy of a vector */
97float vectorNorm2(const signalVector &x);
98
99/** Compute the average power of a vector */
100float vectorPower(const signalVector &x);
101
102/** Setup the signal processing library */
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400103void sigProcLibSetup(int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105/** Destroy the signal processing library */
106void sigProcLibDestroy(void);
107
108/**
109 Convolve two vectors.
110 @param a,b The vectors to be convolved.
111 @param c, A preallocated vector to hold the convolution result.
112 @param spanType The type/span of the convolution.
113 @return The convolution result.
114*/
115signalVector* convolve(const signalVector *a,
116 const signalVector *b,
117 signalVector *c,
118 ConvType spanType,
119 unsigned startIx = 0,
120 unsigned len = 0);
121
122/**
123 Generate the GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400124 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000125 @param symbolLength The size of the pulse.
126 @return The GSM pulse.
127*/
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400128signalVector* generateGSMPulse(int sps, int symbolLength);
dburgessb3a0ca42011-10-12 07:44:40 +0000129
130/**
131 Frequency shift a vector.
132 @param y The frequency shifted vector.
133 @param x The vector to-be-shifted.
134 @param freq The digital frequency shift
135 @param startPhase The starting phase of the oscillator
136 @param finalPhase The final phase of the oscillator
137 @return The frequency shifted vector.
138*/
139signalVector* frequencyShift(signalVector *y,
140 signalVector *x,
141 float freq = 0.0,
142 float startPhase = 0.0,
143 float *finalPhase=NULL);
144
145/**
146 Correlate two vectors.
147 @param a,b The vectors to be correlated.
148 @param c, A preallocated vector to hold the correlation result.
149 @param spanType The type/span of the correlation.
150 @return The correlation result.
151*/
152signalVector* correlate(signalVector *a,
153 signalVector *b,
154 signalVector *c,
155 ConvType spanType,
156 bool bReversedConjugated = false,
157 unsigned startIx = 0,
158 unsigned len = 0);
159
160/** Operate soft slicer on real-valued portion of vector */
161bool vectorSlicer(signalVector *x);
162
163/** GMSK modulate a GSM burst of bits */
164signalVector *modulateBurst(const BitVector &wBurst,
165 const signalVector &gsmPulse,
166 int guardPeriodLength,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400167 int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000168
169/** Sinc function */
170float sinc(float x);
171
172/** Delay a vector */
173void delayVector(signalVector &wBurst,
174 float delay);
175
176/** Add two vectors in-place */
177bool addVector(signalVector &x,
178 signalVector &y);
179
180/** Multiply two vectors in-place*/
181bool multVector(signalVector &x,
182 signalVector &y);
183
184/** Generate a vector of gaussian noise */
185signalVector *gaussianNoise(int length,
186 float variance = 1.0,
187 complex mean = complex(0.0));
188
189/**
190 Given a non-integer index, interpolate a sample.
191 @param inSig The signal from which to interpolate.
192 @param ix The index.
193 @return The interpolated signal value.
194*/
195complex interpolatePoint(const signalVector &inSig,
196 float ix);
197
198/**
199 Given a correlator output, locate the correlation peak.
200 @param rxBurst The correlator result.
201 @param peakIndex Pointer to value to receive interpolated peak index.
202 @param avgPower Power to value to receive mean power.
203 @return Peak value.
204*/
205complex peakDetect(const signalVector &rxBurst,
206 float *peakIndex,
207 float *avgPwr);
208
209/**
210 Apply a scalar to a vector.
211 @param x The vector of interest.
212 @param scale The scalar.
213*/
214void scaleVector(signalVector &x,
215 complex scale);
216
217/**
218 Add a constant offset to a vecotr.
219 @param x The vector of interest.
220 @param offset The offset.
221*/
222void offsetVector(signalVector &x,
223 complex offset);
224
225/**
226 Generate a modulated GSM midamble, stored within the library.
227 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400228 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000229 @param TSC The training sequence [0..7]
230 @return Success.
231*/
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400232bool generateMidamble(signalVector &gsmPulse, int sps, int tsc);
dburgessb3a0ca42011-10-12 07:44:40 +0000233/**
234 Generate a modulated RACH sequence, stored within the library.
235 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400236 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000237 @return Success.
238*/
239bool generateRACHSequence(signalVector &gsmPulse,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400240 int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000241
242/**
243 Energy detector, checks to see if received burst energy is above a threshold.
244 @param rxBurst The received GSM burst of interest.
245 @param windowLength The number of burst samples used to compute burst energy
246 @param detectThreshold The detection threshold, a linear value.
247 @param avgPwr The average power of the received burst.
248 @return True if burst energy is above threshold.
249*/
250bool energyDetect(signalVector &rxBurst,
251 unsigned windowLength,
252 float detectThreshold,
253 float *avgPwr = NULL);
254
255/**
256 RACH correlator/detector.
257 @param rxBurst The received GSM burst of interest.
258 @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 -0400259 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000260 @param amplitude The estimated amplitude of received RACH burst.
261 @param TOA The estimate time-of-arrival of received RACH burst.
262 @return True if burst SNR is larger that the detectThreshold value.
263*/
264bool detectRACHBurst(signalVector &rxBurst,
265 float detectThreshold,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400266 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000267 complex *amplitude,
268 float* TOA);
269
270/**
271 Normal burst correlator, detector, channel estimator.
272 @param rxBurst The received GSM burst of interest.
273
274 @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 -0400275 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000276 @param amplitude The estimated amplitude of received TSC burst.
277 @param TOA The estimate time-of-arrival of received TSC burst.
278 @param maxTOA The maximum expected time-of-arrival
279 @param requestChannel Set to true if channel estimation is desired.
280 @param channelResponse The estimated channel.
281 @param channelResponseOffset The time offset b/w the first sample of the channel response and the reported TOA.
282 @return True if burst SNR is larger that the detectThreshold value.
283*/
284bool analyzeTrafficBurst(signalVector &rxBurst,
285 unsigned TSC,
286 float detectThreshold,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400287 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000288 complex *amplitude,
289 float *TOA,
290 unsigned maxTOA,
291 bool requestChannel = false,
292 signalVector** channelResponse = NULL,
293 float *channelResponseOffset = NULL);
294
295/**
296 Decimate a vector.
297 @param wVector The vector of interest.
298 @param decimationFactor The amount of decimation, i.e. the decimation factor.
299 @return The decimated signal vector.
300*/
301signalVector *decimateVector(signalVector &wVector,
302 int decimationFactor);
303
304/**
305 Demodulates a received burst using a soft-slicer.
306 @param rxBurst The burst to be demodulated.
307 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400308 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000309 @param channel The amplitude estimate of the received burst.
310 @param TOA The time-of-arrival of the received burst.
311 @return The demodulated bit sequence.
312*/
313SoftVector *demodulateBurst(signalVector &rxBurst,
314 const signalVector &gsmPulse,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400315 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000316 complex channel,
317 float TOA);
318
319/**
320 Creates a simple Kaiser-windowed low-pass FIR filter.
321 @param cutoffFreq The digital 3dB bandwidth of the filter.
322 @param filterLen The number of taps in the filter.
323 @param gainDC The DC gain of the filter.
324 @return The desired LPF
325*/
326signalVector *createLPF(float cutoffFreq,
327 int filterLen,
328 float gainDC = 1.0);
329
330/**
331 Change sampling rate of a vector via polyphase resampling.
332 @param wVector The vector to be resampled.
333 @param P The numerator, i.e. the amount of upsampling.
334 @param Q The denominator, i.e. the amount of downsampling.
335 @param LPF An optional low-pass filter used in the resampling process.
336 @return A vector resampled at P/Q of the original sampling rate.
337*/
338signalVector *polyphaseResampleVector(signalVector &wVector,
339 int P, int Q,
340 signalVector *LPF);
341
342/**
343 Change the sampling rate of a vector via linear interpolation.
344 @param wVector The vector to be resampled.
345 @param expFactor Ratio of new sampling rate/original sampling rate.
346 @param endPoint ???
347 @return A vector resampled a expFactor*original sampling rate.
348*/
349signalVector *resampleVector(signalVector &wVector,
350 float expFactor,
351 complex endPoint);
352
353/**
354 Design the necessary filters for a decision-feedback equalizer.
355 @param channelResponse The multipath channel that we're mitigating.
356 @param SNRestimate The signal-to-noise estimate of the channel, a linear value
357 @param Nf The number of taps in the feedforward filter.
358 @param feedForwardFilter The designed feed forward filter.
359 @param feedbackFilter The designed feedback filter.
360 @return True if DFE can be designed.
361*/
362bool designDFE(signalVector &channelResponse,
363 float SNRestimate,
364 int Nf,
365 signalVector **feedForwardFilter,
366 signalVector **feedbackFilter);
367
368/**
369 Equalize/demodulate a received burst via a decision-feedback equalizer.
370 @param rxBurst The received burst to be demodulated.
371 @param TOA The time-of-arrival of the received burst.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400372 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000373 @param w The feed forward filter of the DFE.
374 @param b The feedback filter of the DFE.
375 @return The demodulated bit sequence.
376*/
377SoftVector *equalizeBurst(signalVector &rxBurst,
378 float TOA,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400379 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000380 signalVector &w,
381 signalVector &b);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000382
383#endif /* SIGPROCLIB_H */