Skip to content

Commit 696380b

Browse files
iqgen: bug fixes
Fixed bugs in IQgen components. Reworked code for unit testing.
1 parent 0f44dde commit 696380b

25 files changed

+439
-261
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ tests/test_data_old*
5656
.project
5757
.cproject
5858
.settings/
59+
60+
# Coverage
61+
.coverage
62+
htmlcov/
63+

peregrine/iqgen/bits/amplitude_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def convertUnits2SNR(value, units, noiseParams):
206206
snrDb = 10 * numpy.log10(snr)
207207
elif units == AmplitudeBase.UNITS_SNR_DB:
208208
snrDb = value
209-
else:
209+
else: # pragma: no cover
210210
assert False
211211
return snrDb
212212

@@ -240,6 +240,6 @@ def convertUnits2Amp(value, units, noiseParams):
240240
snrDb = value
241241
snr = 10. ** (0.1 * snrDb)
242242
amp = numpy.sqrt(4. * snr / freqTimesTau) * noiseSigma
243-
else:
243+
else: # pragma: no cover
244244
assert False
245245
return amp

peregrine/iqgen/bits/doppler_base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,8 @@ def computeBatch(self,
181181
-------
182182
signal : numpy.ndarray(n_samples, dtype=float)
183183
Generated samples
184-
userTimeX_s : float
185-
End of interval time in seconds
186-
chipAll_idx : numpy.ndarray(n_samples, dtype=float)
187-
Code chip phases for the samples
188-
chips : numpy.ndarray(n_samples, dtype=int)
189-
Code combined with data
184+
dopplerAll_hz : numpy.ndarray(n_samples, dtype=float)
185+
Doppler values in Hz if debug is enabled
190186
'''
191187

192188
userTimeAll_s = self.applySignalDelays(userTimeAll_s, carrierSignal)

peregrine/iqgen/bits/doppler_sine.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,6 @@ def __str__(self):
6565
format(self.distance0_m, self.tec_epm2, self.speed0_mps,
6666
self.amplutude_mps, self.period_s, self.codeDopplerIgnored)
6767

68-
def __repr__(self):
69-
'''
70-
Constructs python expression presentation of object.
71-
72-
Returns
73-
-------
74-
string
75-
Python expression presentation of object
76-
'''
77-
return "Doppler({}, {}, {}, {}, {})".format(self.distance0_m,
78-
self.tec_epm2,
79-
self.speed0_mps,
80-
self.amplutude_mps,
81-
self.period_s)
82-
8368
def computeDistanceM(self, svTime_s):
8469
'''
8570
Computes doppler shift in meters.

peregrine/iqgen/bits/encoder_base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, bufferSize=1000, attDb=0.):
4646

4747
def addSamples(self, sample_array):
4848
'''
49-
Extracts samples of the supported band and coverts them into bit stream.
49+
Extracts samples of the supported band and converts them into bit stream.
5050
5151
Parameters
5252
----------
@@ -58,7 +58,7 @@ def addSamples(self, sample_array):
5858
numpy.ndarray(dtype=numpy.uint8)
5959
Array of type uint8 containing the encoded data.
6060
'''
61-
return Encoder.EMPTY_RESULT
61+
raise NotImplementedError()
6262

6363
def flush(self):
6464
'''
@@ -70,10 +70,15 @@ def flush(self):
7070
Array of type uint8 containing the encoded data.
7171
'''
7272
if self.n_bits > 0 and self.n_bits % 8 != 0:
73-
self.bits += (8 - self.n_bits % 8)
74-
res = numpy.packbits(self.bits[0:self.n_bits])
75-
self.n_bits = 0
76-
return res
73+
self.n_bits += (8 - self.n_bits % 8)
74+
if self.n_bits:
75+
res = numpy.packbits(self.bits[0:self.n_bits])
76+
self.bits[0:self.n_bits].fill(0)
77+
self.n_bits = 0
78+
return res
79+
else:
80+
# Pack bits returns incorrect result in case of empty source bit set.
81+
return Encoder.EMPTY_RESULT
7782

7883
def encodeValues(self):
7984
'''
@@ -91,6 +96,7 @@ def encodeValues(self):
9196
n_left = self.n_bits - n_offset
9297
res = numpy.packbits(self.bits[0: n_offset])
9398
self.bits[0:n_left] = self.bits[n_offset:n_offset + n_left]
99+
self.bits[n_left:].fill(0)
94100
self.n_bits = n_left
95101
return res
96102

peregrine/iqgen/bits/encoder_gps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
1515
"""
1616

17-
from peregrine.iqgen.bits.encoder_base import Encoder
1817
from peregrine.iqgen.bits.encoder_1bit import BandBitEncoder
1918
from peregrine.iqgen.bits.encoder_1bit import TwoBandsBitEncoder
2019
from peregrine.iqgen.bits.encoder_2bits import BandTwoBitsEncoder

peregrine/iqgen/bits/filter_bandpass.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def __init__(self, outputConfig, frequency_hz, bw_hz=1e6):
4141

4242
self.bw_hz = bw_hz
4343
self.frequency_hz = frequency_hz
44-
passBand_hz = bw_hz * 0.5 / outputConfig.SAMPLE_RATE_HZ
45-
stopBand_hz = bw_hz * 0.6 / outputConfig.SAMPLE_RATE_HZ
44+
passBand_hz = bw_hz
45+
stopBand_hz = bw_hz * 1.2
4646
mult = 2. / outputConfig.SAMPLE_RATE_HZ
4747
order, wn = cheb2ord(wp=[(frequency_hz - passBand_hz) * mult,
4848
(frequency_hz + passBand_hz) * mult],
@@ -52,7 +52,7 @@ def __init__(self, outputConfig, frequency_hz, bw_hz=1e6):
5252
gstop=self.stopBandAtt_dbhz,
5353
analog=False)
5454

55-
b, a = cheby2(order, # Order of the filter
55+
b, a = cheby2(order + 1, # Order of the filter
5656
# Minimum attenuation required in the stop band in dB
5757
self.stopBandAtt_dbhz,
5858
wn,

peregrine/iqgen/bits/filter_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def __init__(self, passBandAtt_dbhz, stopBandAtt_dbhz):
2424
Parameters
2525
----------
2626
passBandAtt_dbhz : float
27-
Pass band attenutation in dB*Hz
27+
Pass band attenuation in dB*Hz
2828
stopBandAtt_dbhz: float
29-
Stop band attenutation in dB*Hz
29+
Stop band attenuation in dB*Hz
3030
'''
3131
self.passBandAtt_dbhz = passBandAtt_dbhz
3232
self.stopBandAtt_dbhz = stopBandAtt_dbhz

peregrine/iqgen/bits/filter_lowpass.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,23 @@ def __init__(self, outputConfig, frequency_hz=0.):
5151
'''
5252
super(LowPassFilter, self).__init__(3., 40.)
5353

54-
self.bw_hz = 1e3
55-
passBand_hz = self.bw_hz / outputConfig.SAMPLE_RATE_HZ
56-
stopBand_hz = self.bw_hz * 1.1 / outputConfig.SAMPLE_RATE_HZ
57-
mult = 2. / outputConfig.SAMPLE_RATE_HZ
58-
order, wn = cheb2ord(wp=passBand_hz * mult,
59-
ws=stopBand_hz * mult,
54+
self.bw_hz = 1e6
55+
passBand_hz = frequency_hz + self.bw_hz
56+
stopBand_hz = frequency_hz + self.bw_hz * 1.2
57+
58+
nyqFreq_s = 2. / outputConfig.SAMPLE_RATE_HZ # 1.0 /Nyquist frequency
59+
wp = passBand_hz * nyqFreq_s
60+
ws = stopBand_hz * nyqFreq_s
61+
62+
order, wn = cheb2ord(wp=wp,
63+
ws=ws,
6064
gpass=self.passBandAtt_dbhz,
6165
gstop=self.stopBandAtt_dbhz,
6266
analog=False)
6367
self.order = order
6468
self.wn = wn
6569

66-
b, a = cheby2(order, # Order of the filter
70+
b, a = cheby2(order + 1, # Order of the filter
6771
# Minimum attenuation required in the stop band in dB
6872
self.stopBandAtt_dbhz,
6973
wn,

peregrine/iqgen/bits/message_block.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ def __init__(self, messageData):
3131
Array with message bits. Bit 0 is encoded with 1, bit 1 is encoded with -1
3232
'''
3333
super(Message, self).__init__()
34-
self.messageData = messageData[:]
35-
self.messageLen = len(self.messageData)
36-
tmp = numpy.asarray(self.messageData, dtype=numpy.uint8)
37-
tmp *= -2
38-
tmp -= 1
39-
self.bits = tmp.astype(numpy.uint8)
34+
bits = numpy.asarray(messageData) < 0
35+
self.messageLen = bits.shape[0]
36+
self.bits = bits.astype(numpy.uint8)
4037

4138
def __str__(self, *args, **kwargs):
4239
'''
@@ -66,20 +63,3 @@ def getDataBits(self, dataAll_idx):
6663
# numpy.take degrades performance a lot over time.
6764
# return numpy.take(self.bits, dataAll_idx , mode='wrap')
6865
return self.bits[dataAll_idx % self.messageLen]
69-
70-
def getBit(self, bitIndex):
71-
'''
72-
Provides bit at a given index
73-
74-
Parameters
75-
----------
76-
bitIndex : long
77-
Bit index
78-
79-
Returns
80-
-------
81-
int
82-
Bit value: 1 for bit 0 and -1 for bit 1
83-
'''
84-
85-
return self.messageData[bitIndex % self.messageLen]

0 commit comments

Comments
 (0)