Naposledy aktivní 1 month ago

Revize 7a6bb7d82743d2a80a90f8a826e5cdd25afe720f

rotate.go Raw
1
2package main
3var constellationLut []map[byte]byte
4var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
5
6func 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
52func 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}