blob: 8e8c48fb4527c27517ee9af8c304dd574de2c15a [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 */
103void sigProcLibSetup(int samplesPerSymbol);
104
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.
124 @param samplesPerSymbol The number of samples per GSM symbol.
125 @param symbolLength The size of the pulse.
126 @return The GSM pulse.
127*/
128signalVector* generateGSMPulse(int samplesPerSymbol,
129 int symbolLength);
130
131/**
132 Frequency shift a vector.
133 @param y The frequency shifted vector.
134 @param x The vector to-be-shifted.
135 @param freq The digital frequency shift
136 @param startPhase The starting phase of the oscillator
137 @param finalPhase The final phase of the oscillator
138 @return The frequency shifted vector.
139*/
140signalVector* frequencyShift(signalVector *y,
141 signalVector *x,
142 float freq = 0.0,
143 float startPhase = 0.0,
144 float *finalPhase=NULL);
145
146/**
147 Correlate two vectors.
148 @param a,b The vectors to be correlated.
149 @param c, A preallocated vector to hold the correlation result.
150 @param spanType The type/span of the correlation.
151 @return The correlation result.
152*/
153signalVector* correlate(signalVector *a,
154 signalVector *b,
155 signalVector *c,
156 ConvType spanType,
157 bool bReversedConjugated = false,
158 unsigned startIx = 0,
159 unsigned len = 0);
160
161/** Operate soft slicer on real-valued portion of vector */
162bool vectorSlicer(signalVector *x);
163
164/** GMSK modulate a GSM burst of bits */
165signalVector *modulateBurst(const BitVector &wBurst,
166 const signalVector &gsmPulse,
167 int guardPeriodLength,
168 int samplesPerSymbol);
169
170/** Sinc function */
171float sinc(float x);
172
173/** Delay a vector */
174void delayVector(signalVector &wBurst,
175 float delay);
176
177/** Add two vectors in-place */
178bool addVector(signalVector &x,
179 signalVector &y);
180
181/** Multiply two vectors in-place*/
182bool multVector(signalVector &x,
183 signalVector &y);
184
185/** Generate a vector of gaussian noise */
186signalVector *gaussianNoise(int length,
187 float variance = 1.0,
188 complex mean = complex(0.0));
189
190/**
191 Given a non-integer index, interpolate a sample.
192 @param inSig The signal from which to interpolate.
193 @param ix The index.
194 @return The interpolated signal value.
195*/
196complex interpolatePoint(const signalVector &inSig,
197 float ix);
198
199/**
200 Given a correlator output, locate the correlation peak.
201 @param rxBurst The correlator result.
202 @param peakIndex Pointer to value to receive interpolated peak index.
203 @param avgPower Power to value to receive mean power.
204 @return Peak value.
205*/
206complex peakDetect(const signalVector &rxBurst,
207 float *peakIndex,
208 float *avgPwr);
209
210/**
211 Apply a scalar to a vector.
212 @param x The vector of interest.
213 @param scale The scalar.
214*/
215void scaleVector(signalVector &x,
216 complex scale);
217
218/**
219 Add a constant offset to a vecotr.
220 @param x The vector of interest.
221 @param offset The offset.
222*/
223void offsetVector(signalVector &x,
224 complex offset);
225
226/**
227 Generate a modulated GSM midamble, stored within the library.
228 @param gsmPulse The GSM pulse used for modulation.
229 @param samplesPerSymbol The number of samples per GSM symbol.
230 @param TSC The training sequence [0..7]
231 @return Success.
232*/
233bool generateMidamble(signalVector &gsmPulse,
234 int samplesPerSymbol,
235 int TSC);
236/**
237 Generate a modulated RACH sequence, stored within the library.
238 @param gsmPulse The GSM pulse used for modulation.
239 @param samplesPerSymbol The number of samples per GSM symbol.
240 @return Success.
241*/
242bool generateRACHSequence(signalVector &gsmPulse,
243 int samplesPerSymbol);
244
245/**
246 Energy detector, checks to see if received burst energy is above a threshold.
247 @param rxBurst The received GSM burst of interest.
248 @param windowLength The number of burst samples used to compute burst energy
249 @param detectThreshold The detection threshold, a linear value.
250 @param avgPwr The average power of the received burst.
251 @return True if burst energy is above threshold.
252*/
253bool energyDetect(signalVector &rxBurst,
254 unsigned windowLength,
255 float detectThreshold,
256 float *avgPwr = NULL);
257
258/**
259 RACH correlator/detector.
260 @param rxBurst The received GSM burst of interest.
261 @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
262 @param samplesPerSymbol The number of samples per GSM symbol.
263 @param amplitude The estimated amplitude of received RACH burst.
264 @param TOA The estimate time-of-arrival of received RACH burst.
265 @return True if burst SNR is larger that the detectThreshold value.
266*/
267bool detectRACHBurst(signalVector &rxBurst,
268 float detectThreshold,
269 int samplesPerSymbol,
270 complex *amplitude,
271 float* TOA);
272
273/**
274 Normal burst correlator, detector, channel estimator.
275 @param rxBurst The received GSM burst of interest.
276
277 @param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
278 @param samplesPerSymbol The number of samples per GSM symbol.
279 @param amplitude The estimated amplitude of received TSC burst.
280 @param TOA The estimate time-of-arrival of received TSC burst.
281 @param maxTOA The maximum expected time-of-arrival
282 @param requestChannel Set to true if channel estimation is desired.
283 @param channelResponse The estimated channel.
284 @param channelResponseOffset The time offset b/w the first sample of the channel response and the reported TOA.
285 @return True if burst SNR is larger that the detectThreshold value.
286*/
287bool analyzeTrafficBurst(signalVector &rxBurst,
288 unsigned TSC,
289 float detectThreshold,
290 int samplesPerSymbol,
291 complex *amplitude,
292 float *TOA,
293 unsigned maxTOA,
294 bool requestChannel = false,
295 signalVector** channelResponse = NULL,
296 float *channelResponseOffset = NULL);
297
298/**
299 Decimate a vector.
300 @param wVector The vector of interest.
301 @param decimationFactor The amount of decimation, i.e. the decimation factor.
302 @return The decimated signal vector.
303*/
304signalVector *decimateVector(signalVector &wVector,
305 int decimationFactor);
306
307/**
308 Demodulates a received burst using a soft-slicer.
309 @param rxBurst The burst to be demodulated.
310 @param gsmPulse The GSM pulse.
311 @param samplesPerSymbol The number of samples per GSM symbol.
312 @param channel The amplitude estimate of the received burst.
313 @param TOA The time-of-arrival of the received burst.
314 @return The demodulated bit sequence.
315*/
316SoftVector *demodulateBurst(signalVector &rxBurst,
317 const signalVector &gsmPulse,
318 int samplesPerSymbol,
319 complex channel,
320 float TOA);
321
322/**
323 Creates a simple Kaiser-windowed low-pass FIR filter.
324 @param cutoffFreq The digital 3dB bandwidth of the filter.
325 @param filterLen The number of taps in the filter.
326 @param gainDC The DC gain of the filter.
327 @return The desired LPF
328*/
329signalVector *createLPF(float cutoffFreq,
330 int filterLen,
331 float gainDC = 1.0);
332
333/**
334 Change sampling rate of a vector via polyphase resampling.
335 @param wVector The vector to be resampled.
336 @param P The numerator, i.e. the amount of upsampling.
337 @param Q The denominator, i.e. the amount of downsampling.
338 @param LPF An optional low-pass filter used in the resampling process.
339 @return A vector resampled at P/Q of the original sampling rate.
340*/
341signalVector *polyphaseResampleVector(signalVector &wVector,
342 int P, int Q,
343 signalVector *LPF);
344
345/**
346 Change the sampling rate of a vector via linear interpolation.
347 @param wVector The vector to be resampled.
348 @param expFactor Ratio of new sampling rate/original sampling rate.
349 @param endPoint ???
350 @return A vector resampled a expFactor*original sampling rate.
351*/
352signalVector *resampleVector(signalVector &wVector,
353 float expFactor,
354 complex endPoint);
355
356/**
357 Design the necessary filters for a decision-feedback equalizer.
358 @param channelResponse The multipath channel that we're mitigating.
359 @param SNRestimate The signal-to-noise estimate of the channel, a linear value
360 @param Nf The number of taps in the feedforward filter.
361 @param feedForwardFilter The designed feed forward filter.
362 @param feedbackFilter The designed feedback filter.
363 @return True if DFE can be designed.
364*/
365bool designDFE(signalVector &channelResponse,
366 float SNRestimate,
367 int Nf,
368 signalVector **feedForwardFilter,
369 signalVector **feedbackFilter);
370
371/**
372 Equalize/demodulate a received burst via a decision-feedback equalizer.
373 @param rxBurst The received burst to be demodulated.
374 @param TOA The time-of-arrival of the received burst.
375 @param samplesPerSymbol The number of samples per GSM symbol.
376 @param w The feed forward filter of the DFE.
377 @param b The feedback filter of the DFE.
378 @return The demodulated bit sequence.
379*/
380SoftVector *equalizeBurst(signalVector &rxBurst,
381 float TOA,
382 int samplesPerSymbol,
383 signalVector &w,
384 signalVector &b);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000385
386#endif /* SIGPROCLIB_H */