Zuletzt aktiv 1 month ago

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 24 insertions, 4 deletions

rotate.go

@@ -22,16 +22,16 @@ func rotateByte(v byte, n int, conj bool) byte {
22 22 b0 := int(byteData[i*2])
23 23 b1 := int(byteData[i*2+1])
24 24
25 - // 0 degrees
26 25 c := complex(float32(b0), float32(b1))
27 26 for z := 0; z < n; z++ {
28 27 c *= rotation90
29 28 }
30 - outByteData[i*2] = int(f2b(real(c)))
29 +
30 + outByteData[i*2] = int(f2bSoft(real(c)))
31 31 if conj {
32 - outByteData[i*2+1] = int(-f2b(imag(c)))
32 + outByteData[i*2+1] = int(f2bSoft(-imag(c)))
33 33 } else {
34 - outByteData[i*2+1] = int(f2b(imag(c)))
34 + outByteData[i*2+1] = int(f2bSoft(imag(c)))
35 35 }
36 36 }
37 37 // endregion
@@ -50,6 +50,26 @@ func rotateByte(v byte, n int, conj bool) byte {
50 50 return v
51 51 }
52 52
53 + func rotateSoftBuffer(buffer []byte, n int, conj bool) {
54 + for i := 0; i < len(buffer) / 2; i++ {
55 + // Sync Word
56 + b0 := int(buffer[i*2]) - 127
57 + b1 := int(buffer[i*2+1]) - 127
58 +
59 + c := complex(float32(b0), float32(b1))
60 + for z := 0; z < n % 4; z++ {
61 + c *= rotation90
62 + }
63 +
64 + buffer[i*2] = f2bSoft(real(c))
65 + if conj {
66 + buffer[i*2+1] = f2bSoft(-imag(c))
67 + } else {
68 + buffer[i*2+1] = f2bSoft(imag(c))
69 + }
70 + }
71 + }
72 +
53 73 func init() {
54 74 constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion)
55 75

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 6 insertions, 1 deletion

rotate.go

@@ -1,7 +1,8 @@
1 1
2 2 package main
3 3 var constellationLut []map[byte]byte
4 - var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
4 +
5 + var constellationLut []map[byte]byte
5 6
6 7 func rotateByte(v byte, n int, conj bool) byte {
7 8 byteData := make([]int, 8)
@@ -52,6 +53,10 @@ func rotateByte(v byte, n int, conj bool) byte {
52 53 func init() {
53 54 constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion)
54 55
56 + for i := 0; i < 8; i++ {
57 + constellationLut[i] = map[byte]byte{}
58 + }
59 +
55 60 for i := 0; i < 256; i++ {
56 61 for n := 0; n < 4; n++ {
57 62 constellationLut[n][byte(i)] = rotateByte(byte(i), n, false)

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 7 insertions, 7 deletions

rotate.go

@@ -1,11 +1,11 @@
1 - var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
2 - package main
3 1
2 + package main
4 3 var constellationLut []map[byte]byte
4 + var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
5 5
6 6 func rotateByte(v byte, n int, conj bool) byte {
7 - byteData := make([]byte, 8)
8 - outByteData := make([]byte, 8)
7 + byteData := make([]int, 8)
8 + outByteData := make([]int, 8)
9 9
10 10 // region convert to bits in bytes
11 11 for i := 0; i < 8; i++ {
@@ -26,11 +26,11 @@ func rotateByte(v byte, n int, conj bool) byte {
26 26 for z := 0; z < n; z++ {
27 27 c *= rotation90
28 28 }
29 - outByteData[i*2] = f2b(real(c))
29 + outByteData[i*2] = int(f2b(real(c)))
30 30 if conj {
31 - outByteData[i*2+1] = -f2b(imag(c))
31 + outByteData[i*2+1] = int(-f2b(imag(c)))
32 32 } else {
33 - outByteData[i*2+1] = f2b(imag(c))
33 + outByteData[i*2+1] = int(f2b(imag(c)))
34 34 }
35 35 }
36 36 // endregion

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 15 insertions

rotate.go

@@ -1,4 +1,8 @@
1 1 var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
2 + package main
3 +
4 + var constellationLut []map[byte]byte
5 +
2 6 func rotateByte(v byte, n int, conj bool) byte {
3 7 byteData := make([]byte, 8)
4 8 outByteData := make([]byte, 8)
@@ -44,3 +48,14 @@ func rotateByte(v byte, n int, conj bool) byte {
44 48
45 49 return v
46 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 + }

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 7 insertions, 3 deletions

rotate.go

@@ -1,5 +1,5 @@
1 1 var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
2 - func rotateByte(v byte, n int) byte {
2 + func rotateByte(v byte, n int, conj bool) byte {
3 3 byteData := make([]byte, 8)
4 4 outByteData := make([]byte, 8)
5 5
@@ -23,7 +23,11 @@ func rotateByte(v byte, n int) byte {
23 23 c *= rotation90
24 24 }
25 25 outByteData[i*2] = f2b(real(c))
26 - outByteData[i*2+1] = f2b(imag(c))
26 + if conj {
27 + outByteData[i*2+1] = -f2b(imag(c))
28 + } else {
29 + outByteData[i*2+1] = f2b(imag(c))
30 + }
27 31 }
28 32 // endregion
29 33 // region Unmap to Byte
@@ -39,4 +43,4 @@ func rotateByte(v byte, n int) byte {
39 43 // endregion
40 44
41 45 return v
42 - }
46 + }

racerxdl's Avatar Lucas Teske hat die Gist bearbeitet 7 years ago. Zu Änderung gehen

1 file changed, 42 insertions

rotate.go(Datei erstellt)

@@ -0,0 +1,42 @@
1 + var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
2 + func rotateByte(v byte, n int) byte {
3 + byteData := make([]byte, 8)
4 + outByteData := make([]byte, 8)
5 +
6 + // region convert to bits in bytes
7 + for i := 0; i < 8; i++ {
8 + byteData[i] = -127
9 + if v & (1 << uint(i)) > 0 {
10 + byteData[i] = 127
11 + }
12 + }
13 + // endregion
14 + // region Rotate
15 + for i := 0; i < 4; i++ {
16 + // Sync Word
17 + b0 := int(byteData[i*2])
18 + b1 := int(byteData[i*2+1])
19 +
20 + // 0 degrees
21 + c := complex(float32(b0), float32(b1))
22 + for z := 0; z < n; z++ {
23 + c *= rotation90
24 + }
25 + outByteData[i*2] = f2b(real(c))
26 + outByteData[i*2+1] = f2b(imag(c))
27 + }
28 + // endregion
29 + // region Unmap to Byte
30 + v = 0
31 + for i := 0; i < 8; i++ {
32 + t := 0
33 + if outByteData[i] > 0 {
34 + t = 1
35 + }
36 +
37 + v |= byte(t << uint(i))
38 + }
39 + // endregion
40 +
41 + return v
42 + }
Neuer Älter