Skip to content

Commit

Permalink
Minor fix and optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Aug 9, 2016
1 parent 49906ad commit 2ae5485
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (d Decoder) Decode(input []byte) []int {
d.Filter(d.Signal, d.Filtered)

// Perform bit-decision on new block.
Quantize(d.Filtered, d.Quantized[d.DecCfg.PacketLength-d.DecCfg.SymbolLength2:])
Quantize(d.Filtered, d.Quantized[d.DecCfg.PacketLength:])

// Pack the quantized signal into slices for searching.
d.Transpose(d.Quantized)
Expand Down Expand Up @@ -232,18 +232,25 @@ func (d Decoder) Filter(input, output []float64) {
// Filter result is difference of summation of lower and upper symbols.
lower := d.csum[d.DecCfg.SymbolLength:]
upper := d.csum[d.DecCfg.SymbolLength2:]
n := len(input) - d.DecCfg.SymbolLength2
for idx := 0; idx < n; idx++ {
output[idx] = (lower[idx] - d.csum[idx]) - (upper[idx] - lower[idx])
for idx, l := range lower[:len(output)] {
output[idx] = (l - d.csum[idx]) - (upper[idx] - l)
}

return
}

// Bit-value is determined by the sign of each sample after filtering.
func Quantize(input []float64, output []byte) {
// Should optimize out to memclr operation.
for idx := range output {
output[idx] = 0
}

// Only set necessary bits. Previous method set all bits regardless of value.
for idx, val := range input {
output[idx] = byte(math.Float64bits(val)>>63) ^ 0x01
if val > 0 {
output[idx] = 1
}
}

return
Expand Down

0 comments on commit 2ae5485

Please sign in to comment.