-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUSIGdecoder.py
158 lines (122 loc) · 4.37 KB
/
USIGdecoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from GlobeParameter import *
from DFT import *
from Interleaving import *
from Constellation import *
from ChannelCoding import *
import math
import cmath
from scipy.fft import fft, ifft, fftshift, fftfreq
import numpy as np
# ----------------------------------------------------------------------
# Legacy SIG field demodulation
# ----------------------------------------------------------------------
#INPUT#
# samples: complex number array
#samplingRate: number (Hz)
# LSTF_endIndex: sample index for LSTF end
# LLTF_channel: channel estimation on 64 subcarrier 20MHz bandwidth
# ----------------------------------------------------------------------
#OUTPUT#
# LSIG_symbol: legacy SIG field constellation symbols array
# ----------------------------------------------------------------------
def USIG_demodulator(samples, samplingRate, USIG_startIndex, LLTF_channel, LSIG_symbol):
ret = 0
try:
startIndex = USIG_startIndex + 1
ratio = int(samplingRate/L_preambleBandth)
windowSize = int((LSIG_length - L_cp) * samplingRate)
# we will need index shift for bandwith beyond 20MHz
# temp = []
# DFT(samples[startIndex:startIndex + windowSize: ratio], temp)
temp = fftshift(fft(samples[startIndex:startIndex + windowSize: ratio]))
# Phase track
phaseShift = 0
for i in pilot64.index:
phaseShift = phaseShift + \
(temp[i]/LLTF_channel[i]) / \
pilot64.symbol[pilot64.index.index(i)]
phaseShift = phaseShift/pilot64.num
if abs(phaseShift) < 1e-6:
phaseShift = 1
#phaseShift = 1
# Phase track
amplitudeShift = 0
for i in pilot64.index:
amplitudeShift = amplitudeShift + \
np.abs(temp[i]/LLTF_channel[i]) / \
np.abs(pilot64.symbol[pilot64.index.index(i)])
amplitudeShift = amplitudeShift/pilot64.num
symbol = []
for i in range(len(LLTF_channel)):
if i not in pilot64.index:
if np.real(LLTF_channel[i]) == 0:
# symbol.append(0);
pass
else:
symbol.append(temp[i]/LLTF_channel[i]/phaseShift)
# -----------------------------------------------------------------------------------------------------------
LSIG_symbol.clear()
for x in symbol:
LSIG_symbol.append(x)
except Exception as err:
ret = -1
print(str(err))
return ret
# ----------------------------------------------------------------------
# Legacy SIG field decoder
# ----------------------------------------------------------------------
#INPUT#
# LSIG_symbol: legacy SIG field constellation symbols array
# ----------------------------------------------------------------------
#OUTPUT#
# LSIG_bits: legacy SIG field bits array
# LSIG_info: legacy SIG field information dictionary
# ----------------------------------------------------------------------
def USIG_decoder(LSIG1_symbol, LSIG2_symbol, LSIG_bits):
ret = 0
LLR1 = []
#BPSKDemapperCenter(LSIG1_symbol, LLR1, center = (-1,1),variance=10)
BPSKDemapper(LSIG1_symbol, LLR1, variance=1)
LLR2 = []
BPSKDemapper(LSIG2_symbol, LLR2, variance=1)
BCCDeinterleaver.N_COL = 13
BCCDeinterleaver.N_ROW = 4
dLLR1 = BCCDeinterleaver.deinterleave(np.array(LLR1))
dLLR2 = BCCDeinterleaver.deinterleave(np.array(LLR2))
#dLLR1 = np.array(dLLR1)
#dLLR1[np.abs(dLLR1) < 1.5] = 0
# dLLR2 = np.array(dLLR2)
# dLLR2 = dLLR2*200
dLLR = np.concatenate((np.array(dLLR1), np.array(dLLR2)))
print(dLLR)
# dLLR_bits = []
# for x in dLLR:
# if x > 0:
# dLLR_bits.append(0)
# else:
# dLLR_bits.append(1)
# print(dLLR_bits)
decoded_LLR = BCCDecoder(dLLR, "1/2")
print(decoded_LLR)
LSIG_bits.clear()
for x in decoded_LLR:
if x >= 0:
LSIG_bits.append(0)
else:
LSIG_bits.append(1)
return ret
def CRC_calc(input):
c = [1,1,1,1,1,1,1,1]
for i in range(len(input)):
temp = input[i]^c[7]
c[7] = c[6]
c[6] = c[5]
c[5] = c[4]
c[4] = c[3]
c[3] = c[2]
c[2] = c[1]^temp
c[1] = c[0]^temp
c[0] = temp
for i in range(len(c)):
c[i] = 1 - c[i]
return [c[7], c[6], c[5], c[4]]