rotate.go
· 1.5 KiB · Go
Ham
package main
var constellationLut []map[byte]byte
var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
func rotateByte(v byte, n int, conj bool) byte {
byteData := make([]int, 8)
outByteData := make([]int, 8)
// region convert to bits in bytes
for i := 0; i < 8; i++ {
byteData[i] = -127
if v & (1 << uint(i)) > 0 {
byteData[i] = 127
}
}
// endregion
// region Rotate
for i := 0; i < 4; i++ {
// Sync Word
b0 := int(byteData[i*2])
b1 := int(byteData[i*2+1])
// 0 degrees
c := complex(float32(b0), float32(b1))
for z := 0; z < n; z++ {
c *= rotation90
}
outByteData[i*2] = int(f2b(real(c)))
if conj {
outByteData[i*2+1] = int(-f2b(imag(c)))
} else {
outByteData[i*2+1] = int(f2b(imag(c)))
}
}
// endregion
// region Unmap to Byte
v = 0
for i := 0; i < 8; i++ {
t := 0
if outByteData[i] > 0 {
t = 1
}
v |= byte(t << uint(i))
}
// endregion
return v
}
func init() {
constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion)
for i := 0; i < 256; i++ {
for n := 0; n < 4; n++ {
constellationLut[n][byte(i)] = rotateByte(byte(i), n, false)
constellationLut[n+4][byte(i)] = rotateByte(byte(i), n, true)
}
}
}
| 1 | |
| 2 | package main |
| 3 | var constellationLut []map[byte]byte |
| 4 | var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2))) |
| 5 | |
| 6 | func rotateByte(v byte, n int, conj bool) byte { |
| 7 | byteData := make([]int, 8) |
| 8 | outByteData := make([]int, 8) |
| 9 | |
| 10 | // region convert to bits in bytes |
| 11 | for i := 0; i < 8; i++ { |
| 12 | byteData[i] = -127 |
| 13 | if v & (1 << uint(i)) > 0 { |
| 14 | byteData[i] = 127 |
| 15 | } |
| 16 | } |
| 17 | // endregion |
| 18 | // region Rotate |
| 19 | for i := 0; i < 4; i++ { |
| 20 | // Sync Word |
| 21 | b0 := int(byteData[i*2]) |
| 22 | b1 := int(byteData[i*2+1]) |
| 23 | |
| 24 | // 0 degrees |
| 25 | c := complex(float32(b0), float32(b1)) |
| 26 | for z := 0; z < n; z++ { |
| 27 | c *= rotation90 |
| 28 | } |
| 29 | outByteData[i*2] = int(f2b(real(c))) |
| 30 | if conj { |
| 31 | outByteData[i*2+1] = int(-f2b(imag(c))) |
| 32 | } else { |
| 33 | outByteData[i*2+1] = int(f2b(imag(c))) |
| 34 | } |
| 35 | } |
| 36 | // endregion |
| 37 | // region Unmap to Byte |
| 38 | v = 0 |
| 39 | for i := 0; i < 8; i++ { |
| 40 | t := 0 |
| 41 | if outByteData[i] > 0 { |
| 42 | t = 1 |
| 43 | } |
| 44 | |
| 45 | v |= byte(t << uint(i)) |
| 46 | } |
| 47 | // endregion |
| 48 | |
| 49 | return v |
| 50 | } |
| 51 | |
| 52 | func init() { |
| 53 | constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion) |
| 54 | |
| 55 | for i := 0; i < 256; i++ { |
| 56 | for n := 0; n < 4; n++ { |
| 57 | constellationLut[n][byte(i)] = rotateByte(byte(i), n, false) |
| 58 | constellationLut[n+4][byte(i)] = rotateByte(byte(i), n, true) |
| 59 | } |
| 60 | } |
| 61 | } |