blob: 147c14ca39b05cfcedb9e2bf47b8363958114e75 [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 Tsou3f32ab52013-11-15 16:32:54 -050056signalVector *convolve(const signalVector *a, const signalVector *b,
57 signalVector *c, ConvType spanType,
58 size_t start = 0, size_t len = 0,
59 size_t step = 1, int offset = 0);
dburgessb3a0ca42011-10-12 07:44:40 +000060
61/**
dburgessb3a0ca42011-10-12 07:44:40 +000062 Frequency shift a vector.
63 @param y The frequency shifted vector.
64 @param x The vector to-be-shifted.
65 @param freq The digital frequency shift
66 @param startPhase The starting phase of the oscillator
67 @param finalPhase The final phase of the oscillator
68 @return The frequency shifted vector.
69*/
70signalVector* frequencyShift(signalVector *y,
71 signalVector *x,
72 float freq = 0.0,
73 float startPhase = 0.0,
74 float *finalPhase=NULL);
75
76/**
77 Correlate two vectors.
78 @param a,b The vectors to be correlated.
79 @param c, A preallocated vector to hold the correlation result.
80 @param spanType The type/span of the correlation.
81 @return The correlation result.
82*/
83signalVector* correlate(signalVector *a,
84 signalVector *b,
85 signalVector *c,
86 ConvType spanType,
87 bool bReversedConjugated = false,
88 unsigned startIx = 0,
89 unsigned len = 0);
90
91/** Operate soft slicer on real-valued portion of vector */
92bool vectorSlicer(signalVector *x);
93
94/** GMSK modulate a GSM burst of bits */
95signalVector *modulateBurst(const BitVector &wBurst,
dburgessb3a0ca42011-10-12 07:44:40 +000096 int guardPeriodLength,
Thomas Tsou83e06892013-08-20 16:10:01 -040097 int sps, bool emptyPulse = false);
dburgessb3a0ca42011-10-12 07:44:40 +000098
99/** Sinc function */
100float sinc(float x);
101
102/** Delay a vector */
Thomas Tsou94edaae2013-11-09 22:19:19 -0500103signalVector *delayVector(signalVector *in, signalVector *out, float delay);
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105/** Add two vectors in-place */
106bool addVector(signalVector &x,
107 signalVector &y);
108
109/** Multiply two vectors in-place*/
110bool multVector(signalVector &x,
111 signalVector &y);
112
113/** Generate a vector of gaussian noise */
114signalVector *gaussianNoise(int length,
115 float variance = 1.0,
116 complex mean = complex(0.0));
117
118/**
119 Given a non-integer index, interpolate a sample.
120 @param inSig The signal from which to interpolate.
121 @param ix The index.
122 @return The interpolated signal value.
123*/
124complex interpolatePoint(const signalVector &inSig,
125 float ix);
126
127/**
128 Given a correlator output, locate the correlation peak.
129 @param rxBurst The correlator result.
130 @param peakIndex Pointer to value to receive interpolated peak index.
131 @param avgPower Power to value to receive mean power.
132 @return Peak value.
133*/
134complex peakDetect(const signalVector &rxBurst,
135 float *peakIndex,
136 float *avgPwr);
137
138/**
139 Apply a scalar to a vector.
140 @param x The vector of interest.
141 @param scale The scalar.
142*/
143void scaleVector(signalVector &x,
144 complex scale);
145
dburgessb3a0ca42011-10-12 07:44:40 +0000146/**
147 Generate a modulated GSM midamble, stored within the library.
148 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400149 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000150 @param TSC The training sequence [0..7]
151 @return Success.
152*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400153bool generateMidamble(int sps, int tsc);
dburgessb3a0ca42011-10-12 07:44:40 +0000154/**
155 Generate a modulated RACH sequence, stored within the library.
156 @param gsmPulse The GSM pulse used for modulation.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400157 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000158 @return Success.
159*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400160bool generateRACHSequence(int sps);
dburgessb3a0ca42011-10-12 07:44:40 +0000161
162/**
163 Energy detector, checks to see if received burst energy is above a threshold.
164 @param rxBurst The received GSM burst of interest.
165 @param windowLength The number of burst samples used to compute burst energy
166 @param detectThreshold The detection threshold, a linear value.
167 @param avgPwr The average power of the received burst.
168 @return True if burst energy is above threshold.
169*/
170bool energyDetect(signalVector &rxBurst,
171 unsigned windowLength,
172 float detectThreshold,
173 float *avgPwr = NULL);
174
175/**
176 RACH correlator/detector.
177 @param rxBurst The received GSM burst of interest.
178 @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 -0400179 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000180 @param amplitude The estimated amplitude of received RACH burst.
181 @param TOA The estimate time-of-arrival of received RACH burst.
Thomas Tsou3eaae802013-08-20 19:31:14 -0400182 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000183*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400184int detectRACHBurst(signalVector &rxBurst,
185 float detectThreshold,
186 int sps,
187 complex *amplitude,
188 float* TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000189
190/**
191 Normal burst correlator, detector, channel estimator.
192 @param rxBurst The received GSM burst of interest.
193
194 @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 -0400195 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000196 @param amplitude The estimated amplitude of received TSC burst.
197 @param TOA The estimate time-of-arrival of received TSC burst.
198 @param maxTOA The maximum expected time-of-arrival
199 @param requestChannel Set to true if channel estimation is desired.
200 @param channelResponse The estimated channel.
201 @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 -0400202 @return positive if threshold value is reached, negative on error, zero otherwise
dburgessb3a0ca42011-10-12 07:44:40 +0000203*/
Thomas Tsou3eaae802013-08-20 19:31:14 -0400204int analyzeTrafficBurst(signalVector &rxBurst,
205 unsigned TSC,
206 float detectThreshold,
207 int sps,
208 complex *amplitude,
209 float *TOA,
210 unsigned maxTOA,
211 bool requestChannel = false,
212 signalVector** channelResponse = NULL,
213 float *channelResponseOffset = NULL);
dburgessb3a0ca42011-10-12 07:44:40 +0000214
215/**
216 Decimate a vector.
217 @param wVector The vector of interest.
Thomas Tsou94edaae2013-11-09 22:19:19 -0500218 @param factor Decimation factor.
dburgessb3a0ca42011-10-12 07:44:40 +0000219 @return The decimated signal vector.
220*/
Thomas Tsou94edaae2013-11-09 22:19:19 -0500221signalVector *decimateVector(signalVector &wVector, size_t factor);
dburgessb3a0ca42011-10-12 07:44:40 +0000222
223/**
224 Demodulates a received burst using a soft-slicer.
225 @param rxBurst The burst to be demodulated.
226 @param gsmPulse The GSM pulse.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400227 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000228 @param channel The amplitude estimate of the received burst.
229 @param TOA The time-of-arrival of the received burst.
230 @return The demodulated bit sequence.
231*/
Thomas Tsou83e06892013-08-20 16:10:01 -0400232SoftVector *demodulateBurst(signalVector &rxBurst, int sps,
233 complex channel, float TOA);
dburgessb3a0ca42011-10-12 07:44:40 +0000234
235/**
dburgessb3a0ca42011-10-12 07:44:40 +0000236 Design the necessary filters for a decision-feedback equalizer.
237 @param channelResponse The multipath channel that we're mitigating.
238 @param SNRestimate The signal-to-noise estimate of the channel, a linear value
239 @param Nf The number of taps in the feedforward filter.
240 @param feedForwardFilter The designed feed forward filter.
241 @param feedbackFilter The designed feedback filter.
242 @return True if DFE can be designed.
243*/
244bool designDFE(signalVector &channelResponse,
245 float SNRestimate,
246 int Nf,
247 signalVector **feedForwardFilter,
248 signalVector **feedbackFilter);
249
250/**
251 Equalize/demodulate a received burst via a decision-feedback equalizer.
252 @param rxBurst The received burst to be demodulated.
253 @param TOA The time-of-arrival of the received burst.
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400254 @param sps The number of samples per GSM symbol.
dburgessb3a0ca42011-10-12 07:44:40 +0000255 @param w The feed forward filter of the DFE.
256 @param b The feedback filter of the DFE.
257 @return The demodulated bit sequence.
258*/
259SoftVector *equalizeBurst(signalVector &rxBurst,
260 float TOA,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400261 int sps,
dburgessb3a0ca42011-10-12 07:44:40 +0000262 signalVector &w,
263 signalVector &b);
kurtis.heimerl8aea56e2011-11-26 03:18:30 +0000264
265#endif /* SIGPROCLIB_H */