Skip to content

Commit

Permalink
Merge pull request swift-nav#8 from valeri-atamaniouk/i75-IQgen-2bit-…
Browse files Browse the repository at this point in the history
…encoding

iqgen: fixed bug with 2 bit encoding
  • Loading branch information
adel-mamin committed Mar 4, 2016
2 parents 4775c24 + 943705d commit 8cf269e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions peregrine/iqgen/bits/encoder_2bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,15 @@ def convertBand(band_samples):
totalPower = numpy.sum(power)
totalPowerLimit = totalPower * 0.67

# Build histrogram to find 67% power
# Build histogram to find 67% power
totalBins = 30
hist, edges = numpy.histogram(power,
bins=10,
density=True)
lastPower = 0.
powerLimit = 0.
for i in range(10):
# Approximate power of samples in the bin
entryPower = hist[i] * (edges[i] + edges[i + 1]) / 2.
newPower = lastPower + entryPower
if newPower > totalPowerLimit:
powerLimit = edges[i]
break
else:
lastPower = newPower
bins=totalBins,
density=False)
avg = (edges[:-1] + edges[1:]) * 0.5
powers = numpy.cumsum(hist * avg)
idx = numpy.searchsorted(powers, totalPowerLimit, side="right")
powerLimit = avg[idx]

# Signal sign
signs = band_samples > 0
Expand Down

0 comments on commit 8cf269e

Please sign in to comment.