Utoljára aktív 1 month ago

Revízió 2be85d62628917cccd0a6edc939849b435f89d2c

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