diff --git a/decode/decode.go b/decode/decode.go index 1c397e20f..544a5f3e4 100644 --- a/decode/decode.go +++ b/decode/decode.go @@ -113,7 +113,7 @@ type Decoder struct { } // Create a new decoder with the given packet configuration. -func NewDecoder(cfg PacketConfig, decimation int, fastMag bool) (d Decoder) { +func NewDecoder(cfg PacketConfig, decimation int) (d Decoder) { d.Cfg = cfg d.Cfg.SymbolLength2 = d.Cfg.SymbolLength << 1 @@ -139,11 +139,7 @@ func NewDecoder(cfg PacketConfig, decimation int, fastMag bool) (d Decoder) { d.csum = make([]float64, (d.DecCfg.PacketLength - d.DecCfg.SymbolLength2 + 1)) // Calculate magnitude lookup table specified by -fastmag flag. - if fastMag { - d.demod = NewAlphaMaxBetaMinLUT() - } else { - d.demod = NewSqrtMagLUT() - } + d.demod = NewSqrtMagLUT() // Pre-calculate a byte-slice version of the preamble for searching. d.preamble = make([]byte, len(d.Cfg.Preamble)) @@ -234,40 +230,6 @@ func (lut MagLUT) Execute(input []byte, output []float64) { } } -// Alpha*Max + Beta*Min Magnitude Approximation Lookup Table. -type AlphaMaxBetaMinLUT []float64 - -// Pre-computes absolute values with most common DC offset for rtl-sdr dongles. -func NewAlphaMaxBetaMinLUT() (lut AlphaMaxBetaMinLUT) { - lut = make([]float64, 0x100) - for idx := range lut { - lut[idx] = math.Abs(127.4 - float64(idx)) - } - return -} - -// Calculates complex magnitude on given IQ stream writing result to output. -func (lut AlphaMaxBetaMinLUT) Execute(input []byte, output []float64) { - const ( - α = 0.948059448969 - ß = 0.392699081699 - ) - - decIdx := 0 - dec := (len(input) / len(output)) - - for idx := 0; decIdx < len(output); idx += dec { - i := lut[input[idx]] - q := lut[input[idx+1]] - if i > q { - output[decIdx] = α*i + ß*q - } else { - output[decIdx] = α*q + ß*i - } - decIdx++ - } -} - // Matched filter for Manchester coded signals. Output signal's sign at each // sample determines the bit-value since Manchester symbols have odd symmetry. func (d Decoder) Filter(input, output []float64) { diff --git a/flags.go b/flags.go index c55652dcb..08242740b 100644 --- a/flags.go +++ b/flags.go @@ -37,7 +37,6 @@ var sampleFilename = flag.String("samplefile", os.DevNull, "raw signal dump file var sampleFile *os.File var msgType = flag.String("msgtype", "scm", "message type to receive: scm, idm or r900") -var fastMag = flag.Bool("fastmag", false, "use faster alpha max + beta min magnitude approximation") var symbolLength = flag.Int("symbollength", 72, "symbol length in samples, see -help for valid lengths") diff --git a/idm/idm.go b/idm/idm.go index 8f824e8fc..c5eb29caf 100644 --- a/idm/idm.go +++ b/idm/idm.go @@ -51,8 +51,8 @@ func (p Parser) Cfg() decode.PacketConfig { return p.Decoder.Cfg } -func NewParser(symbolLength, decimation int, fastMag bool) (p Parser) { - p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation, fastMag) +func NewParser(symbolLength, decimation int) (p Parser) { + p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation) p.CRC = crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F) return } diff --git a/r900/r900.go b/r900/r900.go index e72c2f20b..5432f358e 100644 --- a/r900/r900.go +++ b/r900/r900.go @@ -52,8 +52,8 @@ type Parser struct { quantized []byte } -func NewParser(symbolLength, decimation int, fastMag bool) (p Parser) { - p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation, fastMag) +func NewParser(symbolLength, decimation int) (p Parser) { + p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation) // GF of order 32, polynomial 37, generator 2. p.field = gf.NewField(32, 37, 2) diff --git a/recv.go b/recv.go index fcf7cdbc8..8f9045edb 100644 --- a/recv.go +++ b/recv.go @@ -46,11 +46,11 @@ type Receiver struct { func (rcvr *Receiver) NewReceiver() { switch strings.ToLower(*msgType) { case "scm": - rcvr.p = scm.NewParser(*symbolLength, *decimation, *fastMag) + rcvr.p = scm.NewParser(*symbolLength, *decimation) case "idm": - rcvr.p = idm.NewParser(*symbolLength, *decimation, *fastMag) + rcvr.p = idm.NewParser(*symbolLength, *decimation) case "r900": - rcvr.p = r900.NewParser(*symbolLength, *decimation, *fastMag) + rcvr.p = r900.NewParser(*symbolLength, *decimation) default: log.Fatalf("Invalid message type: %q\n", *msgType) } diff --git a/scm/scm.go b/scm/scm.go index 8f9042c72..d4c491da5 100644 --- a/scm/scm.go +++ b/scm/scm.go @@ -42,8 +42,8 @@ type Parser struct { crc.CRC } -func NewParser(symbolLength, decimation int, fastMag bool) (p Parser) { - p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation, fastMag) +func NewParser(symbolLength, decimation int) (p Parser) { + p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation) p.CRC = crc.NewCRC("BCH", 0, 0x6F63, 0) return }