Skip to content

Commit

Permalink
Remove Sqrt in MagLUT, sensitivity is unaffected. Use appropriate sca…
Browse files Browse the repository at this point in the history
…ling in LUT calculation.
  • Loading branch information
bemasher committed Apr 14, 2016
1 parent faba109 commit 1378c68
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewDecoder(cfg PacketConfig, decimation int) (d Decoder) {
d.csum = make([]float64, (d.DecCfg.PacketLength - d.DecCfg.SymbolLength2 + 1))

// Calculate magnitude lookup table specified by -fastmag flag.
d.demod = NewSqrtMagLUT()
d.demod = NewMagLUT()

// Pre-calculate a byte-slice version of the preamble for searching.
d.preamble = make([]byte, len(d.Cfg.Preamble))
Expand Down Expand Up @@ -207,10 +207,10 @@ type Demodulator interface {
type MagLUT []float64

// Pre-computes normalized squares with most common DC offset for rtl-sdr dongles.
func NewSqrtMagLUT() (lut MagLUT) {
func NewMagLUT() (lut MagLUT) {
lut = make([]float64, 0x100)
for idx := range lut {
lut[idx] = 127.4 - float64(idx)
lut[idx] = (127.5 - float64(idx)) / 127.5
lut[idx] *= lut[idx]
}
return
Expand All @@ -222,7 +222,8 @@ func (lut MagLUT) Execute(input []byte, output []float64) {
dec := (len(input) / len(output))

for idx := 0; decIdx < len(output); idx += dec {
output[decIdx] = math.Sqrt(lut[input[idx]] + lut[input[idx+1]])
// output[decIdx] = math.Sqrt(lut[input[idx]] + lut[input[idx+1]])
output[decIdx] = lut[input[idx]] + lut[input[idx+1]]
decIdx++
}
}
Expand Down

0 comments on commit 1378c68

Please sign in to comment.