rotate.go
· 2.0 KiB · Go
Originalformat
package main
var constellationLut []map[byte]byte
var constellationLut []map[byte]byte
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])
c := complex(float32(b0), float32(b1))
for z := 0; z < n; z++ {
c *= rotation90
}
outByteData[i*2] = int(f2bSoft(real(c)))
if conj {
outByteData[i*2+1] = int(f2bSoft(-imag(c)))
} else {
outByteData[i*2+1] = int(f2bSoft(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 rotateSoftBuffer(buffer []byte, n int, conj bool) {
for i := 0; i < len(buffer) / 2; i++ {
// Sync Word
b0 := int(buffer[i*2]) - 127
b1 := int(buffer[i*2+1]) - 127
c := complex(float32(b0), float32(b1))
for z := 0; z < n % 4; z++ {
c *= rotation90
}
buffer[i*2] = f2bSoft(real(c))
if conj {
buffer[i*2+1] = f2bSoft(-imag(c))
} else {
buffer[i*2+1] = f2bSoft(imag(c))
}
}
}
func init() {
constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion)
for i := 0; i < 8; i++ {
constellationLut[i] = map[byte]byte{}
}
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 | |
| 5 | var constellationLut []map[byte]byte |
| 6 | |
| 7 | func 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 | c := complex(float32(b0), float32(b1)) |
| 26 | for z := 0; z < n; z++ { |
| 27 | c *= rotation90 |
| 28 | } |
| 29 | |
| 30 | outByteData[i*2] = int(f2bSoft(real(c))) |
| 31 | if conj { |
| 32 | outByteData[i*2+1] = int(f2bSoft(-imag(c))) |
| 33 | } else { |
| 34 | outByteData[i*2+1] = int(f2bSoft(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 | |
| 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 | |
| 73 | func init() { |
| 74 | constellationLut = make([]map[byte]byte, 8) // 8 Ambiguities (4 for QPSK and 4 for conjugated QPSK (IQ inversion) |
| 75 | |
| 76 | for i := 0; i < 8; i++ { |
| 77 | constellationLut[i] = map[byte]byte{} |
| 78 | } |
| 79 | |
| 80 | for i := 0; i < 256; i++ { |
| 81 | for n := 0; n < 4; n++ { |
| 82 | constellationLut[n][byte(i)] = rotateByte(byte(i), n, false) |
| 83 | constellationLut[n+4][byte(i)] = rotateByte(byte(i), n, true) |
| 84 | } |
| 85 | } |
| 86 | } |