Skip to content

Commit

Permalink
Remove FastMag
Browse files Browse the repository at this point in the history
Simulation shows that FastMag is of roughly equivalent sensitivity to
MagLUT while not providing much better performance.
  • Loading branch information
bemasher committed Jul 11, 2015
1 parent 30ee13e commit 42ceb2c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 50 deletions.
42 changes: 2 additions & 40 deletions decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions idm/idm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions r900/r900.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions scm/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 42ceb2c

Please sign in to comment.